Class: Prawn::SVG::Interface
- Inherits:
-
Object
- Object
- Prawn::SVG::Interface
- Defined in:
- lib/prawn/svg/interface.rb
Constant Summary collapse
- VALID_OPTIONS =
[:at, :position, :vposition, :width, :height, :cache_images, :enable_web_requests, :enable_file_requests_with_root, :fallback_font_name, :color_mode]
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#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.
Class Method Summary collapse
-
.font_path ⇒ Object
backwards support for when the font_path used to be stored on this class.
Instance Method Summary collapse
-
#draw ⇒ Object
Draws the SVG to the Prawn::Document object.
-
#initialize(data, prawn, options, &block) ⇒ Interface
constructor
Creates a Prawn::SVG object.
- #position ⇒ Object
- #resize(width: nil, height: nil) ⇒ Object
- #sizing ⇒ Object
Constructor Details
#initialize(data, prawn, options, &block) ⇒ Interface
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.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/prawn/svg/interface.rb', line 19 def initialize(data, prawn, , &block) Prawn. VALID_OPTIONS, @data = data @prawn = prawn @options = font_registry = Prawn::SVG::FontRegistry.new(prawn.font_families) @document = Document.new(data, [prawn.bounds.width, prawn.bounds.height], , font_registry: font_registry, &block) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
10 11 12 |
# File 'lib/prawn/svg/interface.rb', line 10 def data @data end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
10 11 12 |
# File 'lib/prawn/svg/interface.rb', line 10 def document @document end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/prawn/svg/interface.rb', line 10 def @options end |
#prawn ⇒ Object (readonly)
Returns the value of attribute prawn.
10 11 12 |
# File 'lib/prawn/svg/interface.rb', line 10 def prawn @prawn end |
Class Method Details
.font_path ⇒ Object
backwards support for when the font_path used to be stored on this class
69 70 71 |
# File 'lib/prawn/svg/interface.rb', line 69 def self.font_path # backwards support for when the font_path used to be stored on this class Prawn::SVG::FontRegistry.font_path end |
Instance Method Details
#draw ⇒ Object
Draws the SVG to the Prawn::Document object.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/prawn/svg/interface.rb', line 34 def draw if @document.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 => @document.sizing.output_width, :height => @document.sizing.output_height) do prawn.save_graphics_state do clip_rectangle 0, 0, @document.sizing.output_width, @document.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
65 66 67 |
# File 'lib/prawn/svg/interface.rb', line 65 def position @options[:at] || [x_based_on_requested_alignment, y_based_on_requested_alignment] end |
#resize(width: nil, height: nil) ⇒ Object
61 62 63 |
# File 'lib/prawn/svg/interface.rb', line 61 def resize(width: nil, height: nil) document.calculate_sizing(requested_width: width, requested_height: height) end |
#sizing ⇒ Object
57 58 59 |
# File 'lib/prawn/svg/interface.rb', line 57 def sizing document.sizing end |