Class: Prawn::SVG::Elements::Use
- Defined in:
- lib/prawn/svg/elements/use.rb
Constant Summary
Constants inherited from Base
Base::COMMA_WSP_REGEXP, Base::MissingAttributesError, Base::PAINT_TYPES, Base::SVG_NAMESPACE, Base::SkipElementError, Base::SkipElementQuietly
Constants included from Attributes::Stroke
Attributes::Stroke::CAP_STYLE_TRANSLATIONS, Attributes::Stroke::JOIN_STYLE_TRANSLATIONS
Instance Attribute Summary collapse
-
#referenced_element_class ⇒ Object
readonly
Returns the value of attribute referenced_element_class.
-
#referenced_element_source ⇒ Object
readonly
Returns the value of attribute referenced_element_source.
Attributes inherited from Base
#attributes, #base_calls, #calls, #document, #parent_calls, #properties, #source, #state
Instance Method Summary collapse
Methods inherited from Base
#initialize, #name, #parse_and_apply, #process
Methods included from TransformParser
Methods included from PDFMatrix
#load_matrix, #matrix_for_pdf, #rotation_matrix, #scale_matrix, #translation_matrix
Methods included from Attributes::Space
Methods included from Attributes::Stroke
#parse_stroke_attributes_and_call
Methods included from Attributes::Mask
#parse_mask_attribute_and_call
Methods included from Attributes::ClipPath
#parse_clip_path_attribute_and_call
Methods included from Attributes::Opacity
#parse_opacity_attributes_and_call
Methods included from Attributes::Transform
#parse_transform_attribute_and_call
Constructor Details
This class inherits a constructor from Prawn::SVG::Elements::Base
Instance Attribute Details
#referenced_element_class ⇒ Object (readonly)
Returns the value of attribute referenced_element_class.
2 3 4 |
# File 'lib/prawn/svg/elements/use.rb', line 2 def referenced_element_class @referenced_element_class end |
#referenced_element_source ⇒ Object (readonly)
Returns the value of attribute referenced_element_source.
2 3 4 |
# File 'lib/prawn/svg/elements/use.rb', line 2 def referenced_element_source @referenced_element_source end |
Instance Method Details
#apply ⇒ Object
30 31 32 |
# File 'lib/prawn/svg/elements/use.rb', line 30 def apply add_call_and_enter 'translate', x_pixels(@x || 0), -y_pixels(@y || 0) if @x || @y end |
#container? ⇒ Boolean
26 27 28 |
# File 'lib/prawn/svg/elements/use.rb', line 26 def container? true end |
#parse ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/prawn/svg/elements/use.rb', line 4 def parse href = href_attribute raise SkipElementError, 'use tag must have an href or xlink:href' if href.nil? if href.start_with?('#') resolve_local_reference(href[1..]) else resolve_external_reference(href) end raise SkipElementError, "use tag references '#{href}' which could not be resolved" if referenced_element_class.nil? @referenced_element_class = Prawn::SVG::Elements::Viewport if referenced_element_source.name == 'symbol' state.inside_use = true @x = attributes['x'] @y = attributes['y'] @width = attributes['width'] @height = attributes['height'] end |
#process_child_elements ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/prawn/svg/elements/use.rb', line 34 def process_child_elements add_call 'save' source = clone_element_source(referenced_element_source) if referenced_element_class == Prawn::SVG::Elements::Viewport source.attributes['width'] = @width || '100%' source.attributes['height'] = @height || '100%' end child = referenced_element_class.new(document, source, calls, state.dup) child.process add_call 'restore' end |