Class: Prawn::Svg::Document

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

Constant Summary collapse

DEFAULT_FALLBACK_FONT_NAME =
"Times-Roman"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, bounds, options) {|_self| ... } ⇒ Document

Returns a new instance of Document

Yields:

  • (_self)

Yield Parameters:


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/prawn/svg/document.rb', line 20

def initialize(data, bounds, options)
  @css_parser = CssParser::Parser.new if CSS_PARSER_LOADED

  @root = REXML::Document.new(data).root
  @warnings = []
  @options = options
  @elements_by_id = {}
  @cache_images = options[:cache_images]
  @fallback_font_name = options.fetch(:fallback_font_name, DEFAULT_FALLBACK_FONT_NAME)

  @sizing = Prawn::Svg::Calculators::DocumentSizing.new(bounds, @root.attributes)
  sizing.requested_width = options[:width]
  sizing.requested_height = options[:height]
  sizing.calculate

  yield self if block_given?
end

Instance Attribute Details

#cache_imagesObject (readonly)

Returns the value of attribute cache_images


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

def cache_images
  @cache_images
end

#css_parserObject (readonly)

Returns the value of attribute css_parser


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

def css_parser
  @css_parser
end

#elements_by_idObject (readonly)

Returns the value of attribute elements_by_id


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

def elements_by_id
  @elements_by_id
end

#fallback_font_nameObject (readonly)

Returns the value of attribute fallback_font_name


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

def fallback_font_name
  @fallback_font_name
end

#rootObject (readonly)

Returns the value of attribute root


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

def root
  @root
end

#sizingObject (readonly)

Returns the value of attribute sizing


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

def sizing
  @sizing
end

#url_cache=(value) ⇒ Object (writeonly)

Sets the attribute url_cache

Parameters:

  • value

    the value to set the attribute url_cache to.


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

def url_cache=(value)
  @url_cache = value
end

#warningsObject (readonly)

An Array of warnings that occurred while parsing the SVG data.


12
13
14
# File 'lib/prawn/svg/document.rb', line 12

def warnings
  @warnings
end

Instance Method Details

#distance(value, axis = nil) ⇒ Object


46
47
48
# File 'lib/prawn/svg/document.rb', line 46

def distance(value, axis = nil)
  value && points(value, axis)
end

#points(value, axis = nil) ⇒ Object


50
51
52
# File 'lib/prawn/svg/document.rb', line 50

def points(value, axis = nil)
  Prawn::Svg::Calculators::Pixels.to_pixels(value, axis == :y ? sizing.viewport_height : sizing.viewport_width)
end

#url_loaderObject


54
55
56
# File 'lib/prawn/svg/document.rb', line 54

def url_loader
  @url_loader ||= Prawn::Svg::UrlLoader.new(:enable_cache => cache_images)
end

#x(value) ⇒ Object


38
39
40
# File 'lib/prawn/svg/document.rb', line 38

def x(value)
  points(value, :x)
end

#y(value) ⇒ Object


42
43
44
# File 'lib/prawn/svg/document.rb', line 42

def y(value)
  sizing.output_height - points(value, :y)
end