Class: Prawn::Svg::Interface

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

Constant Summary collapse

DEFAULT_FONT_PATHS =
["/Library/Fonts", "/System/Library/Fonts", "#{ENV["HOME"]}/Library/Fonts", "/usr/share/fonts/truetype"]

Class Attribute Summary collapse

Instance Attribute 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.

options must contain the key :at, which takes a tuple of x and y co-ordinates.

options can optionally contain the key :width or :height. If both are specified, only :width will be used.


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

def initialize(data, prawn, options, &block)
  @data = data
  @prawn = prawn
  @options = options

  @options[:at] or raise "options[:at] must be specified"

  Prawn::Svg::Font.load_external_fonts(prawn.font_families)

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

Class Attribute Details

.font_pathObject

Returns the value of attribute font_path


13
14
15
# File 'lib/prawn/svg/interface.rb', line 13

def font_path
  @font_path
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data


15
16
17
# File 'lib/prawn/svg/interface.rb', line 15

def data
  @data
end

#documentObject (readonly)

Returns the value of attribute document


15
16
17
# File 'lib/prawn/svg/interface.rb', line 15

def document
  @document
end

#optionsObject (readonly)

Returns the value of attribute options


15
16
17
# File 'lib/prawn/svg/interface.rb', line 15

def options
  @options
end

#prawnObject (readonly)

Returns the value of attribute prawn


15
16
17
# File 'lib/prawn/svg/interface.rb', line 15

def prawn
  @prawn
end

Instance Method Details

#drawObject

Draws the SVG to the Prawn::Document object.


42
43
44
45
46
47
48
49
# File 'lib/prawn/svg/interface.rb', line 42

def draw
  prawn.bounding_box(@options[:at], :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
      proc_creator(prawn, Parser.new(@document).parse).call
    end
  end
end