Class: Prawn::SVG::Renderer
- Inherits:
-
Object
- Object
- Prawn::SVG::Renderer
- Defined in:
- lib/prawn/svg/renderer.rb
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#prawn ⇒ Object
readonly
Returns the value of attribute prawn.
Instance Method Summary collapse
-
#draw ⇒ Object
Draws the SVG to the Prawn::Document object.
-
#initialize(prawn, document, options) ⇒ Renderer
constructor
Creates a Prawn::SVG object.
- #position ⇒ Object
- #render_calls(prawn, calls) ⇒ Object
- #sizing ⇒ Object
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, ) @prawn = prawn @document = document = end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
4 5 6 |
# File 'lib/prawn/svg/renderer.rb', line 4 def document @document end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/prawn/svg/renderer.rb', line 4 def end |
#prawn ⇒ Object (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
#draw ⇒ Object
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 |
#position ⇒ Object
49 50 51 |
# File 'lib/prawn/svg/renderer.rb', line 49 def position [: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 |
#sizing ⇒ Object
45 46 47 |
# File 'lib/prawn/svg/renderer.rb', line 45 def sizing document.sizing end |