Class: Prawn::SVG::Interface

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

Constant Summary collapse

VALID_OPTIONS =
i[
  at position vposition width height cache_images enable_web_requests
  enable_file_requests_with_root fallback_font_name color_mode
].freeze
INHERITABLE_OPTIONS =
i[
  enable_web_requests enable_file_requests_with_root
  cache_images fallback_font_name color_mode
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/prawn/svg/interface.rb', line 27

def initialize(data, prawn, options, &block)
  Prawn.verify_options VALID_OPTIONS, options

  @data = data
  @prawn = prawn
  @options = options

  font_registry = Prawn::SVG::FontRegistry.new(prawn.font_families)

  @document = Document.new(
    data, [prawn.bounds.width, prawn.bounds.height], options,
    font_registry: font_registry, &block
  )

  @renderer = Renderer.new(prawn, document, options)
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



18
19
20
# File 'lib/prawn/svg/interface.rb', line 18

def data
  @data
end

#documentObject (readonly)

Returns the value of attribute document.



18
19
20
# File 'lib/prawn/svg/interface.rb', line 18

def document
  @document
end

#optionsObject (readonly)

Returns the value of attribute options.



18
19
20
# File 'lib/prawn/svg/interface.rb', line 18

def options
  @options
end

#prawnObject (readonly)

Returns the value of attribute prawn.



18
19
20
# File 'lib/prawn/svg/interface.rb', line 18

def prawn
  @prawn
end

Class Method Details

.font_pathObject

backwards support for when the font_path used to be stored on this class



64
65
66
# File 'lib/prawn/svg/interface.rb', line 64

def self.font_path
  Prawn::SVG::FontRegistry.font_path
end

Instance Method Details

#drawObject

Draws the SVG to the Prawn::Document object.



47
48
49
# File 'lib/prawn/svg/interface.rb', line 47

def draw
  @renderer.draw
end

#positionObject



59
60
61
# File 'lib/prawn/svg/interface.rb', line 59

def position
  @renderer.position
end

#resize(width: nil, height: nil) ⇒ Object



55
56
57
# File 'lib/prawn/svg/interface.rb', line 55

def resize(width: nil, height: nil)
  document.calculate_sizing(requested_width: width, requested_height: height)
end

#sizingObject



51
52
53
# File 'lib/prawn/svg/interface.rb', line 51

def sizing
  document.sizing
end