Class: Prawn::SVG::Document
- Inherits:
-
Object
- Object
- Prawn::SVG::Document
- Defined in:
- lib/prawn/svg/document.rb
Constant Summary collapse
- Error =
Class.new(StandardError)
- InvalidSVGData =
Class.new(Error)
- DEFAULT_FALLBACK_FONT_NAME =
'Times-Roman'.freeze
Class Attribute Summary collapse
-
.enable_web_requests_warned ⇒ Object
Returns the value of attribute enable_web_requests_warned.
Instance Attribute Summary collapse
-
#color_mode ⇒ Object
readonly
Returns the value of attribute color_mode.
-
#element_styles ⇒ Object
readonly
Returns the value of attribute element_styles.
-
#elements_by_id ⇒ Object
readonly
Returns the value of attribute elements_by_id.
-
#external_svg_cache ⇒ Object
readonly
Returns the value of attribute external_svg_cache.
-
#fallback_font_name ⇒ Object
readonly
Returns the value of attribute fallback_font_name.
-
#font_registry ⇒ Object
readonly
Returns the value of attribute font_registry.
-
#gradients ⇒ Object
readonly
Returns the value of attribute gradients.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#sizing ⇒ Object
readonly
Returns the value of attribute sizing.
-
#url_loader ⇒ Object
readonly
Returns the value of attribute url_loader.
-
#warnings ⇒ Object
readonly
An
Arrayof warnings that occurred while parsing the SVG data.
Instance Method Summary collapse
- #calculate_sizing(requested_width: nil, requested_height: nil) ⇒ Object
-
#initialize(data, bounds, options, font_registry: nil, css_parser: CssParser::Parser.new, attribute_overrides: {}) {|_self| ... } ⇒ Document
constructor
A new instance of Document.
- #with_sizing(temporary_sizing) ⇒ Object
Constructor Details
#initialize(data, bounds, options, font_registry: nil, css_parser: CssParser::Parser.new, attribute_overrides: {}) {|_self| ... } ⇒ Document
Returns a new instance of Document.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/prawn/svg/document.rb', line 26 def initialize(data, bounds, , font_registry: nil, css_parser: CssParser::Parser.new, attribute_overrides: {}) begin @root = REXML::Document.new(data).root or raise_parse_error(data) rescue REXML::ParseException => e raise_parse_error(data, e.) end @warnings = [] @options = @elements_by_id = {} @gradients = Prawn::SVG::Gradients.new(self) @external_svg_cache = {} @fallback_font_name = .fetch(:fallback_font_name, DEFAULT_FALLBACK_FONT_NAME) @font_registry = font_registry @color_mode = load_color_mode @font_face_tempfiles = [] if !.key?(:enable_web_requests) && !self.class.enable_web_requests_warned self.class.enable_web_requests_warned = true warn '[prawn-svg] WARNING: :enable_web_requests is not set and currently defaults to true. ' \ 'In prawn-svg 1.0, this will default to false. ' \ 'Please explicitly pass enable_web_requests: true or enable_web_requests: false to suppress this warning.' end @url_loader = Prawn::SVG::UrlLoader.new( enable_cache: [:cache_images], enable_web: .fetch(:enable_web_requests, true), enable_file_with_root: [:enable_file_requests_with_root] ) attributes = @root.attributes.dup attribute_overrides.each { |key, value| attributes.add(REXML::Attribute.new(key, value)) } @sizing = Prawn::SVG::Calculators::DocumentSizing.new(bounds, attributes) calculate_sizing(requested_width: [:width], requested_height: [:height]) stylesheets = Prawn::SVG::CSS::Stylesheets.new(css_parser, root, url_loader: url_loader, warnings: warnings) @element_styles = stylesheets.load process_font_face_rules(stylesheets.font_face_rules) yield self if block_given? end |
Class Attribute Details
.enable_web_requests_warned ⇒ Object
Returns the value of attribute enable_web_requests_warned.
10 11 12 |
# File 'lib/prawn/svg/document.rb', line 10 def enable_web_requests_warned @enable_web_requests_warned end |
Instance Attribute Details
#color_mode ⇒ Object (readonly)
Returns the value of attribute color_mode.
16 17 18 |
# File 'lib/prawn/svg/document.rb', line 16 def color_mode @color_mode end |
#element_styles ⇒ Object (readonly)
Returns the value of attribute element_styles.
16 17 18 |
# File 'lib/prawn/svg/document.rb', line 16 def element_styles @element_styles end |
#elements_by_id ⇒ Object (readonly)
Returns the value of attribute elements_by_id.
16 17 18 |
# File 'lib/prawn/svg/document.rb', line 16 def elements_by_id @elements_by_id end |
#external_svg_cache ⇒ Object (readonly)
Returns the value of attribute external_svg_cache.
16 17 18 |
# File 'lib/prawn/svg/document.rb', line 16 def external_svg_cache @external_svg_cache end |
#fallback_font_name ⇒ Object (readonly)
Returns the value of attribute fallback_font_name.
16 17 18 |
# File 'lib/prawn/svg/document.rb', line 16 def fallback_font_name @fallback_font_name end |
#font_registry ⇒ Object (readonly)
Returns the value of attribute font_registry.
16 17 18 |
# File 'lib/prawn/svg/document.rb', line 16 def font_registry @font_registry end |
#gradients ⇒ Object (readonly)
Returns the value of attribute gradients.
16 17 18 |
# File 'lib/prawn/svg/document.rb', line 16 def gradients @gradients end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
16 17 18 |
# File 'lib/prawn/svg/document.rb', line 16 def root @root end |
#sizing ⇒ Object (readonly)
Returns the value of attribute sizing.
16 17 18 |
# File 'lib/prawn/svg/document.rb', line 16 def sizing @sizing end |
#url_loader ⇒ Object (readonly)
Returns the value of attribute url_loader.
16 17 18 |
# File 'lib/prawn/svg/document.rb', line 16 def url_loader @url_loader end |
#warnings ⇒ Object (readonly)
An Array of warnings that occurred while parsing the SVG data.
14 15 16 |
# File 'lib/prawn/svg/document.rb', line 14 def warnings @warnings end |
Instance Method Details
#calculate_sizing(requested_width: nil, requested_height: nil) ⇒ Object
69 70 71 72 73 |
# File 'lib/prawn/svg/document.rb', line 69 def calculate_sizing(requested_width: nil, requested_height: nil) sizing.requested_width = requested_width sizing.requested_height = requested_height sizing.calculate end |
#with_sizing(temporary_sizing) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/prawn/svg/document.rb', line 75 def with_sizing(temporary_sizing) original = @sizing @sizing = temporary_sizing yield ensure @sizing = original end |