Class: Prawn::SVG::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/prawn/svg/renderer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prawn, document, options) ⇒ Renderer

Creates a Prawn::SVG object.

data is the SVG data to convert. prawn is your Prawn::Document object.

See README.md for the options that can be passed to this method.



13
14
15
16
17
# File 'lib/prawn/svg/renderer.rb', line 13

def initialize(prawn, document, options)
  @prawn = prawn
  @document = document
  @options = options
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



4
5
6
# File 'lib/prawn/svg/renderer.rb', line 4

def document
  @document
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/prawn/svg/renderer.rb', line 4

def options
  @options
end

#prawnObject (readonly)

Returns the value of attribute prawn.



4
5
6
# File 'lib/prawn/svg/renderer.rb', line 4

def prawn
  @prawn
end

Instance Method Details

#drawObject

Draws the SVG to the Prawn::Document object.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/prawn/svg/renderer.rb', line 22

def draw
  if sizing.invalid?
    document.warnings << 'Zero or negative sizing data means this SVG cannot be rendered'
    return
  end

  document.warnings.clear

  prawn.save_font do
    prawn.bounding_box(position, width: sizing.output_width, height: sizing.output_height) do
      prawn.save_graphics_state do
        clip_rectangle 0, 0, sizing.output_width, sizing.output_height

        calls = []
        root_element = Prawn::SVG::Elements::Root.new(document, document.root, calls)
        root_element.process

        proc_creator(prawn, calls).call
      end
    end
  end
end

#positionObject



49
50
51
# File 'lib/prawn/svg/renderer.rb', line 49

def position
  options[:at] || [x_based_on_requested_alignment, y_based_on_requested_alignment]
end

#render_calls(prawn, calls) ⇒ Object



53
54
55
# File 'lib/prawn/svg/renderer.rb', line 53

def render_calls(prawn, calls)
  issue_prawn_command(prawn, calls)
end

#sizingObject



45
46
47
# File 'lib/prawn/svg/renderer.rb', line 45

def sizing
  document.sizing
end