Class: Vectory::Svg
Constant Summary
collapse
- SVG_NS =
"http://www.w3.org/2000/svg"
Instance Attribute Summary
Attributes inherited from Vector
#initial_path
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Vector
#convert_with_inkscape, #file_size, from_datauri, from_path, #height, #initialize, #mime, #path, #size, #to_uri, #width, #write
Methods inherited from Image
from_content, from_path, #initialize
Class Method Details
.default_extension ⇒ Object
9
10
11
|
# File 'lib/vectory/svg.rb', line 9
def self.default_extension
"svg"
end
|
.from_node(node) ⇒ Object
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/vectory/svg.rb', line 17
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
|
.mimetype ⇒ Object
13
14
15
|
# File 'lib/vectory/svg.rb', line 13
def self.mimetype
"image/svg+xml"
end
|
Instance Method Details
#content ⇒ Object
28
29
30
|
# File 'lib/vectory/svg.rb', line 28
def content
@document&.to_xml || @content
end
|
#namespace(suffix, links, xpath_to_remove) ⇒ Object
44
45
46
47
48
|
# File 'lib/vectory/svg.rb', line 44
def namespace(suffix, links, xpath_to_remove)
remap_links(links)
suffix_ids(suffix)
remove_xpath(xpath_to_remove)
end
|
#remap_links(map) ⇒ Object
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/vectory/svg.rb', line 50
def remap_links(map)
document.xpath(".//m:a", "m" => SVG_NS).each do |a|
href_attrs = ["xlink:href", "href"]
href_attrs.each do |p|
a[p] and x = map[File.expand_path(a[p])] and a[p] = x
end
end
self
end
|
#remove_xpath(xpath) ⇒ Object
71
72
73
74
75
|
# File 'lib/vectory/svg.rb', line 71
def remove_xpath(xpath)
document.xpath(xpath).remove
self
end
|
#suffix_ids(suffix) ⇒ Object
61
62
63
64
65
66
67
68
69
|
# File 'lib/vectory/svg.rb', line 61
def suffix_ids(suffix)
ids = collect_ids
return if ids.empty?
update_ids_attrs(ids, suffix)
update_ids_css(ids, suffix)
self
end
|
#to_emf ⇒ Object
32
33
34
|
# File 'lib/vectory/svg.rb', line 32
def to_emf
convert_with_inkscape("--export-type=emf", Emf)
end
|
#to_eps ⇒ Object
36
37
38
|
# File 'lib/vectory/svg.rb', line 36
def to_eps
convert_with_inkscape("--export-type=eps", Eps)
end
|
#to_ps ⇒ Object
40
41
42
|
# File 'lib/vectory/svg.rb', line 40
def to_ps
convert_with_inkscape("--export-type=ps", Ps)
end
|