Class: Prawn::SVG::Elements::Base

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Attributes::ClipPath, Attributes::Opacity, Attributes::Space, Attributes::Stroke, Attributes::Transform, Calculators::Pixels, CallDuplicator, TransformParser
Defined in:
lib/prawn/svg/elements/base.rb

Constant Summary collapse

PAINT_TYPES =
%w[fill stroke].freeze
COMMA_WSP_REGEXP =
Prawn::SVG::Elements::COMMA_WSP_REGEXP
SVG_NAMESPACE =
'http://www.w3.org/2000/svg'.freeze
SkipElementQuietly =
Class.new(StandardError)
SkipElementError =
Class.new(StandardError)
MissingAttributesError =
Class.new(SkipElementError)

Constants included from Attributes::Stroke

Attributes::Stroke::CAP_STYLE_TRANSLATIONS, Attributes::Stroke::JOIN_STYLE_TRANSLATIONS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TransformParser

#parse_transform_attribute

Methods included from PDFMatrix

#load_matrix, #matrix_for_pdf, #rotation_matrix, #scale_matrix, #translation_matrix

Methods included from Attributes::Space

#parse_xml_space_attribute

Methods included from Attributes::Stroke

#parse_stroke_attributes_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

#initialize(document, source, parent_calls, state) ⇒ Base

Returns a new instance of Base.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/prawn/svg/elements/base.rb', line 30

def initialize(document, source, parent_calls, state)
  @document = document
  @source = source
  @parent_calls = parent_calls
  @state = state
  @base_calls = @calls = []
  @attributes = {}
  @properties = Prawn::SVG::Properties.new

  if source && add_to_elements_by_id? && !state.inside_use
    id = source.attributes['id']
    id = id.strip if id

    document.elements_by_id[id] = self if id && id != ''
  end
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



24
25
26
# File 'lib/prawn/svg/elements/base.rb', line 24

def attributes
  @attributes
end

#base_callsObject (readonly)

Returns the value of attribute base_calls.



24
25
26
# File 'lib/prawn/svg/elements/base.rb', line 24

def base_calls
  @base_calls
end

#callsObject

Returns the value of attribute calls.



25
26
27
# File 'lib/prawn/svg/elements/base.rb', line 25

def calls
  @calls
end

#documentObject (readonly)

Returns the value of attribute document.



24
25
26
# File 'lib/prawn/svg/elements/base.rb', line 24

def document
  @document
end

#parent_callsObject (readonly)

Returns the value of attribute parent_calls.



24
25
26
# File 'lib/prawn/svg/elements/base.rb', line 24

def parent_calls
  @parent_calls
end

#propertiesObject (readonly)

Returns the value of attribute properties.



24
25
26
# File 'lib/prawn/svg/elements/base.rb', line 24

def properties
  @properties
end

#sourceObject (readonly)

Returns the value of attribute source.



24
25
26
# File 'lib/prawn/svg/elements/base.rb', line 24

def source
  @source
end

#stateObject (readonly)

Returns the value of attribute state.



24
25
26
# File 'lib/prawn/svg/elements/base.rb', line 24

def state
  @state
end

Instance Method Details

#nameObject



67
68
69
# File 'lib/prawn/svg/elements/base.rb', line 67

def name
  @name ||= source ? source.name : '???'
end

#parse_and_applyObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/prawn/svg/elements/base.rb', line 52

def parse_and_apply
  parse_standard_attributes
  parse

  apply_calls_from_standard_attributes
  apply

  process_child_elements if container?

  append_calls_to_parent unless computed_properties.display == 'none'
rescue SkipElementQuietly
rescue SkipElementError => e
  @document.warnings << e.message
end

#processObject



47
48
49
50
# File 'lib/prawn/svg/elements/base.rb', line 47

def process
  extract_attributes_and_properties
  parse_and_apply
end