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

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Attributes::ClipPath, Attributes::Mask, Attributes::Opacity, Attributes::Space, Attributes::Stroke, Attributes::Transform, Calculators::Pixels, BboxScaling, 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::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

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

Returns a new instance of Base.



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

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.



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

def attributes
  @attributes
end

#base_callsObject (readonly)

Returns the value of attribute base_calls.



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

def base_calls
  @base_calls
end

#callsObject

Returns the value of attribute calls.



27
28
29
# File 'lib/prawn/svg/elements/base.rb', line 27

def calls
  @calls
end

#documentObject (readonly)

Returns the value of attribute document.



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

def document
  @document
end

#parent_callsObject (readonly)

Returns the value of attribute parent_calls.



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

def parent_calls
  @parent_calls
end

#propertiesObject (readonly)

Returns the value of attribute properties.



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

def properties
  @properties
end

#sourceObject (readonly)

Returns the value of attribute source.



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

def source
  @source
end

#stateObject (readonly)

Returns the value of attribute state.



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

def state
  @state
end

Instance Method Details

#nameObject



73
74
75
# File 'lib/prawn/svg/elements/base.rb', line 73

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

#parse_and_applyObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/prawn/svg/elements/base.rb', line 54

def parse_and_apply
  parse_standard_attributes
  parse

  apply_calls_from_standard_attributes
  apply

  if state.anchor_href && bounding_box
    add_call('svg:add_link', state.anchor_href, bounding_box)
  end

  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



49
50
51
52
# File 'lib/prawn/svg/elements/base.rb', line 49

def process
  extract_attributes_and_properties
  parse_and_apply
end