vectory 0.7.3 → 0.7.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vectory/emf.rb +1 -1
- data/lib/vectory/svg.rb +10 -72
- data/lib/vectory/svg_document.rb +76 -0
- data/lib/vectory/svg_mapping.rb +11 -4
- data/lib/vectory/version.rb +1 -1
- data/lib/vectory.rb +2 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aef4319c091897a2bc5971c65ef3d87332655aa1d76516ffbcd66fc9541465da
|
4
|
+
data.tar.gz: ca405f2071d56b523ec6203b6dcf98c390fa420c2c9a58102fdb766a179d9577
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 101b0bbf1881240b6a84516450e8e73670c726339d16d1bb7b15e3efd806422f237a95dcc5b1e7145c951df4326cbda679d7f89c0523909822e0d3a28ecf2c73
|
7
|
+
data.tar.gz: 4a5b4495f7a8335e8514c2dd76fc332ce6f46afe070132f9aee427317aaeedcbfd4922c23fb7efff8c429f89a2cff74077cfdb5d3e4134279867556b9e38a614
|
data/lib/vectory/emf.rb
CHANGED
data/lib/vectory/svg.rb
CHANGED
@@ -25,8 +25,10 @@ module Vectory
|
|
25
25
|
from_path(uri)
|
26
26
|
end
|
27
27
|
|
28
|
-
def content
|
29
|
-
|
28
|
+
def initialize(content = nil, initial_path = nil)
|
29
|
+
super
|
30
|
+
|
31
|
+
self.content = content
|
30
32
|
end
|
31
33
|
|
32
34
|
def to_emf
|
@@ -41,81 +43,17 @@ module Vectory
|
|
41
43
|
convert_with_inkscape("--export-type=ps", Ps)
|
42
44
|
end
|
43
45
|
|
44
|
-
def namespace(suffix, links, xpath_to_remove)
|
45
|
-
remap_links(links)
|
46
|
-
suffix_ids(suffix)
|
47
|
-
remove_xpath(xpath_to_remove)
|
48
|
-
end
|
49
|
-
|
50
|
-
def remap_links(map)
|
51
|
-
document.xpath(".//m:a", "m" => SVG_NS).each do |a|
|
52
|
-
href_attrs = ["xlink:href", "href"]
|
53
|
-
href_attrs.each do |p|
|
54
|
-
a[p] and x = map[File.expand_path(a[p])] and a[p] = x
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
self
|
59
|
-
end
|
60
|
-
|
61
|
-
def suffix_ids(suffix)
|
62
|
-
ids = collect_ids
|
63
|
-
return if ids.empty?
|
64
|
-
|
65
|
-
update_ids_attrs(ids, suffix)
|
66
|
-
update_ids_css(ids, suffix)
|
67
|
-
|
68
|
-
self
|
69
|
-
end
|
70
|
-
|
71
|
-
def remove_xpath(xpath)
|
72
|
-
document.xpath(xpath).remove
|
73
|
-
|
74
|
-
self
|
75
|
-
end
|
76
|
-
|
77
46
|
private
|
78
47
|
|
79
48
|
def content=(content)
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
def document
|
88
|
-
@document ||= begin
|
89
|
-
doc = Nokogiri::XML(@content)
|
90
|
-
@content = nil
|
91
|
-
doc
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
def collect_ids
|
96
|
-
document.xpath("./@id | .//@id").map(&:value)
|
97
|
-
end
|
98
|
-
|
99
|
-
def update_ids_attrs(ids, suffix)
|
100
|
-
document.xpath(". | .//*[@*]").each do |a|
|
101
|
-
a.attribute_nodes.each do |x|
|
102
|
-
ids.include?(x.value) and x.value += sprintf("_%09d", suffix)
|
103
|
-
end
|
49
|
+
# non-root node inserts the xml tag which breaks markup when placed in
|
50
|
+
# another xml document
|
51
|
+
document = Nokogiri::XML(content).root
|
52
|
+
unless document
|
53
|
+
raise ParsingError, "Could not parse '#{content&.slice(0, 30)}'"
|
104
54
|
end
|
105
|
-
end
|
106
|
-
|
107
|
-
def update_ids_css(ids, suffix)
|
108
|
-
document.xpath("//m:style", "m" => SVG_NS).each do |s|
|
109
|
-
c = s.children.to_xml
|
110
|
-
ids.each do |i|
|
111
|
-
c = c.gsub(%r[##{i}\b],
|
112
|
-
sprintf("#%<id>s_%<suffix>09d", id: i, suffix: suffix))
|
113
|
-
.gsub(%r(\[id\s*=\s*['"]?#{i}['"]?\]),
|
114
|
-
sprintf("[id='%<id>s_%<suffix>09d']", id: i, suffix: suffix))
|
115
|
-
end
|
116
55
|
|
117
|
-
|
118
|
-
end
|
56
|
+
@content = document.to_xml
|
119
57
|
end
|
120
58
|
end
|
121
59
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require "nokogiri"
|
2
|
+
|
3
|
+
module Vectory
|
4
|
+
class SvgDocument
|
5
|
+
SVG_NS = "http://www.w3.org/2000/svg".freeze
|
6
|
+
|
7
|
+
def initialize(content)
|
8
|
+
@document = Nokogiri::XML(content)
|
9
|
+
end
|
10
|
+
|
11
|
+
def content
|
12
|
+
@document.root.to_xml
|
13
|
+
end
|
14
|
+
|
15
|
+
def namespace(suffix, links, xpath_to_remove)
|
16
|
+
remap_links(links)
|
17
|
+
suffix_ids(suffix)
|
18
|
+
remove_xpath(xpath_to_remove)
|
19
|
+
end
|
20
|
+
|
21
|
+
def remap_links(map)
|
22
|
+
@document.xpath(".//m:a", "m" => SVG_NS).each do |a|
|
23
|
+
href_attrs = ["xlink:href", "href"]
|
24
|
+
href_attrs.each do |p|
|
25
|
+
a[p] and x = map[File.expand_path(a[p])] and a[p] = x
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def suffix_ids(suffix)
|
33
|
+
ids = collect_ids
|
34
|
+
return if ids.empty?
|
35
|
+
|
36
|
+
update_ids_attrs(ids, suffix)
|
37
|
+
update_ids_css(ids, suffix)
|
38
|
+
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
def remove_xpath(xpath)
|
43
|
+
@document.xpath(xpath).remove
|
44
|
+
|
45
|
+
self
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def collect_ids
|
51
|
+
@document.xpath("./@id | .//@id").map(&:value)
|
52
|
+
end
|
53
|
+
|
54
|
+
def update_ids_attrs(ids, suffix)
|
55
|
+
@document.xpath(". | .//*[@*]").each do |a|
|
56
|
+
a.attribute_nodes.each do |x|
|
57
|
+
ids.include?(x.value) and x.value += sprintf("_%09d", suffix)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def update_ids_css(ids, suffix)
|
63
|
+
@document.xpath("//m:style", "m" => SVG_NS).each do |s|
|
64
|
+
c = s.children.to_xml
|
65
|
+
ids.each do |i|
|
66
|
+
c = c.gsub(%r[##{i}\b],
|
67
|
+
sprintf("#%<id>s_%<suffix>09d", id: i, suffix: suffix))
|
68
|
+
.gsub(%r(\[id\s*=\s*['"]?#{i}['"]?\]),
|
69
|
+
sprintf("[id='%<id>s_%<suffix>09d']", id: i, suffix: suffix))
|
70
|
+
end
|
71
|
+
|
72
|
+
s.children = c
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/vectory/svg_mapping.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative "svg"
|
2
|
+
require_relative "svg_document"
|
2
3
|
|
3
4
|
module Vectory
|
4
5
|
class SvgMapping
|
@@ -70,13 +71,19 @@ module Vectory
|
|
70
71
|
end
|
71
72
|
|
72
73
|
def generate_content(image, svgmap, suffix)
|
73
|
-
|
74
|
-
return unless
|
74
|
+
document = build_svg_document(image)
|
75
|
+
return unless document
|
75
76
|
|
76
77
|
links_map = from_targets_to_links_map(svgmap)
|
77
|
-
|
78
|
+
document.namespace(suffix, links_map, PROCESSING_XPATH)
|
79
|
+
|
80
|
+
document.content
|
81
|
+
end
|
82
|
+
|
83
|
+
def build_svg_document(image)
|
84
|
+
vector = build_vector(image)
|
78
85
|
|
79
|
-
vector.content
|
86
|
+
SvgDocument.new(vector.content)
|
80
87
|
end
|
81
88
|
|
82
89
|
def build_vector(image)
|
data/lib/vectory/version.rb
CHANGED
data/lib/vectory.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vectory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: emf2svg
|
@@ -112,6 +112,7 @@ files:
|
|
112
112
|
- lib/vectory/inkscape_converter.rb
|
113
113
|
- lib/vectory/ps.rb
|
114
114
|
- lib/vectory/svg.rb
|
115
|
+
- lib/vectory/svg_document.rb
|
115
116
|
- lib/vectory/svg_mapping.rb
|
116
117
|
- lib/vectory/system_call.rb
|
117
118
|
- lib/vectory/utils.rb
|