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
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.
-
#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
Array
of 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.
Constructor Details
#initialize(data, bounds, options, font_registry: nil, css_parser: CssParser::Parser.new, attribute_overrides: {}) {|_self| ... } ⇒ Document
Returns a new instance of Document.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/prawn/svg/document.rb', line 19 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 = [] = @elements_by_id = {} @gradients = Prawn::SVG::Gradients.new(self) @fallback_font_name = .fetch(:fallback_font_name, DEFAULT_FALLBACK_FONT_NAME) @font_registry = font_registry @color_mode = load_color_mode @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]) @element_styles = Prawn::SVG::CSS::Stylesheets.new(css_parser, root).load yield self if block_given? end |
Instance Attribute Details
#color_mode ⇒ Object (readonly)
Returns the value of attribute color_mode.
10 11 12 |
# File 'lib/prawn/svg/document.rb', line 10 def color_mode @color_mode end |
#element_styles ⇒ Object (readonly)
Returns the value of attribute element_styles.
10 11 12 |
# File 'lib/prawn/svg/document.rb', line 10 def element_styles @element_styles end |
#elements_by_id ⇒ Object (readonly)
Returns the value of attribute elements_by_id.
10 11 12 |
# File 'lib/prawn/svg/document.rb', line 10 def elements_by_id @elements_by_id end |
#fallback_font_name ⇒ Object (readonly)
Returns the value of attribute fallback_font_name.
10 11 12 |
# File 'lib/prawn/svg/document.rb', line 10 def fallback_font_name @fallback_font_name end |
#font_registry ⇒ Object (readonly)
Returns the value of attribute font_registry.
10 11 12 |
# File 'lib/prawn/svg/document.rb', line 10 def font_registry @font_registry end |
#gradients ⇒ Object (readonly)
Returns the value of attribute gradients.
10 11 12 |
# File 'lib/prawn/svg/document.rb', line 10 def gradients @gradients end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
10 11 12 |
# File 'lib/prawn/svg/document.rb', line 10 def root @root end |
#sizing ⇒ Object (readonly)
Returns the value of attribute sizing.
10 11 12 |
# File 'lib/prawn/svg/document.rb', line 10 def sizing @sizing end |
#url_loader ⇒ Object (readonly)
Returns the value of attribute url_loader.
10 11 12 |
# File 'lib/prawn/svg/document.rb', line 10 def url_loader @url_loader end |
#warnings ⇒ Object (readonly)
An Array
of warnings that occurred while parsing the SVG data.
8 9 10 |
# File 'lib/prawn/svg/document.rb', line 8 def warnings @warnings end |
Instance Method Details
#calculate_sizing(requested_width: nil, requested_height: nil) ⇒ Object
51 52 53 54 55 |
# File 'lib/prawn/svg/document.rb', line 51 def calculate_sizing(requested_width: nil, requested_height: nil) sizing.requested_width = requested_width sizing.requested_height = requested_height sizing.calculate end |