vectory 0.7.3 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +12 -4
- data/lib/vectory/version.rb +1 -1
- data/lib/vectory.rb +2 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a6c18ba7c79e9fe87d1a9ccdd8456e250b85d91e4955c9d84487a1b0d13d30e
|
4
|
+
data.tar.gz: 710be6d71399fc7cfc0dcd18b016edb6f4fa4ab5587b5af9dec0c011e7cdc31b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b78ec2bbaaeff9a1de40cb3b259b6dec8530b867c25bda9a9c2f593649f6ce1e8d825a9b3d9e534ba68b5a6188d4b99dfa7a8997b81e5815c547b950a60531d
|
7
|
+
data.tar.gz: 7d3d896903020a026a6d2da467e8a23f996a69b0fc5033ca7a6c6741a41ebb19330702b1d68c896deca84f44db69f37fc38ce7cd4e8d6aa27297e412aa3b3fdb
|
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,20 @@ 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)
|
85
|
+
return unless vector
|
78
86
|
|
79
|
-
vector.content
|
87
|
+
SvgDocument.new(vector.content)
|
80
88
|
end
|
81
89
|
|
82
90
|
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.5
|
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-23 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
|
@@ -138,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
139
|
- !ruby/object:Gem::Version
|
139
140
|
version: '0'
|
140
141
|
requirements: []
|
141
|
-
rubygems_version: 3.3.
|
142
|
+
rubygems_version: 3.3.27
|
142
143
|
signing_key:
|
143
144
|
specification_version: 4
|
144
145
|
summary: Pairwise vector image conversions.
|