Class: Prawn::SVG::Elements::Marker

Inherits:
Base
  • Object
show all
Defined in:
lib/prawn/svg/elements/marker.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

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

#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

This class inherits a constructor from Prawn::SVG::Elements::Base

Instance Method Details

#apply_marker(element, point: nil, angle: 0) ⇒ Object



11
12
13
14
15
16
17
18
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/prawn/svg/elements/marker.rb', line 11

def apply_marker(element, point: nil, angle: 0)
  sizing = Prawn::SVG::Calculators::DocumentSizing.new([0, 0], attributes)
  sizing.document_width = attributes['markerWidth'] || 3
  sizing.document_height = attributes['markerHeight'] || 3
  sizing.calculate

  if sizing.invalid?
    document.warnings << '<marker> cannot be rendered due to invalid sizing information'
    return
  end

  element.new_call_context_from_base do
    element.add_call 'save'

    # LATER : these will probably change when we separate out properties from attributes
    element.parse_transform_attribute_and_call
    element.parse_opacity_attributes_and_call
    element.parse_clip_path_attribute_and_call

    element.add_call 'transformation_matrix', 1, 0, 0, 1, point[0], -point[1]

    if attributes['orient'] != 'auto'
      angle = attributes['orient'].to_f # defaults to 0 if not specified
    end

    element.push_call_position
    element.add_call_and_enter 'rotate', -angle, origin: [0, y('0')] if angle != 0

    if attributes['markerUnits'] != 'userSpaceOnUse'
      scale = element.state.stroke_width
      element.add_call 'transformation_matrix', scale, 0, 0, scale, 0, 0
    end

    ref_x = x_pixels(attributes['refX']) || 0
    ref_y = y_pixels(attributes['refY']) || 0

    element.add_call 'transformation_matrix', 1, 0, 0, 1, -ref_x * sizing.x_scale, ref_y * sizing.y_scale

    if overflow_hidden?
      point = [sizing.x_offset * sizing.x_scale, y(sizing.y_offset * sizing.y_scale)]
      element.add_call 'rectangle', point, sizing.output_width, sizing.output_height
      element.add_call 'clip'
    end

    element.add_call 'transformation_matrix', sizing.x_scale, 0, 0, sizing.y_scale, 0, 0

    new_state = state.dup
    new_state.computed_properties = computed_properties.dup
    new_state.last_fill_opacity = element.state.last_fill_opacity
    new_state.last_stroke_opacity = element.state.last_stroke_opacity

    container = Prawn::SVG::Elements::Container.new(document, nil, [], new_state)
    container.properties.compute_properties(new_state.computed_properties)
    container.parse_and_apply
    container.add_calls_from_element(self)

    element.add_calls_from_element(container)

    element.pop_call_position
    element.add_call 'restore'
  end
end

#container?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/prawn/svg/elements/marker.rb', line 7

def container?
  true
end

#parseObject



2
3
4
5
# File 'lib/prawn/svg/elements/marker.rb', line 2

def parse
  properties.display = 'none'
  computed_properties.display = 'none'
end