Class: Vectory::Svg

Inherits:
Vector show all
Defined in:
lib/vectory/svg.rb

Constant Summary collapse

SVG_NS =
"http://www.w3.org/2000/svg"

Instance Attribute Summary

Attributes inherited from Vector

#initial_path

Attributes inherited from Image

#content

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Vector

#file_size, from_datauri, from_path, #mime, #path, #size, #to_uri, #write

Methods inherited from Image

from_content, from_path

Constructor Details

#initialize(content = nil, initial_path = nil) ⇒ Svg

Returns a new instance of Svg.



29
30
31
32
33
# File 'lib/vectory/svg.rb', line 29

def initialize(content = nil, initial_path = nil)
  super

  self.content = content
end

Class Method Details

.default_extensionObject



10
11
12
# File 'lib/vectory/svg.rb', line 10

def self.default_extension
  "svg"
end

.from_node(node) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/vectory/svg.rb', line 18

def self.from_node(node)
  if node.elements&.first&.name == "svg"
    return from_content(node.children.to_xml)
  end

  uri = node["src"]
  return Vectory::Datauri.new(uri).to_vector if %r{^data:}.match?(uri)

  from_path(uri)
end

.mimetypeObject



14
15
16
# File 'lib/vectory/svg.rb', line 14

def self.mimetype
  "image/svg+xml"
end

Instance Method Details

#heightObject



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

def height
  dim_from_attr("height") || dim_from_viewbox(3) || super
end

#to_emfObject



35
36
37
# File 'lib/vectory/svg.rb', line 35

def to_emf
  Emf.from_content(Emfsvg.from_svg(content))
end

#to_epsObject



39
40
41
# File 'lib/vectory/svg.rb', line 39

def to_eps
  Eps.from_content(Postsvg.to_eps(content))
end

#to_psObject



43
44
45
# File 'lib/vectory/svg.rb', line 43

def to_ps
  Ps.from_content(Postsvg.to_ps(content))
end

#widthObject



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

def width
  dim_from_attr("width") || dim_from_viewbox(2) || super
end