isodoc 2.7.4 → 2.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed67e4d2dcf7434348ba3cffd17acb74fe0299e0572e5de475b6239354a1a76d
4
- data.tar.gz: fed255fae89b9d5142a1ba7f7b775de2681d1321163ae11a28e735649cdbaa45
3
+ metadata.gz: 3a4ea94214377595240bcb873426fb3170509fd7e535b2c277fff4dbb6077f95
4
+ data.tar.gz: 46c9e47211dbbd225871f4ea91a86697c119b0d60a5359b974795c303becca18
5
5
  SHA512:
6
- metadata.gz: 0f8c5fb1bee726d778940c54b608603f11ba01f48b564198b2a4c56b03d741ea60b8bf2bd7b178f97dcb169760484731dcb7c3984c46ba0662df7dfa772a0315
7
- data.tar.gz: 5b981bee3d73b52ff4d1d22ae8ba71b93fcd9512c78fc486de1f2902700dc201a75e8cf459c6229b6e27c78a333a4ec2db6a8155c77728f7ed65c993d040d552
6
+ metadata.gz: 9862cb11f6f06fb48052a21c5a1289e53677a2d357da003434d66251a28fd4c62cda42696e2d906448f791edd485545bc7a7257764eabeb6125f35ef287dfd15
7
+ data.tar.gz: db953889f3de823b3bb107d9c694088c81fc68ebf16d8f75cd38d78aef13b5794b0349cff181e8c1f9c3566b16c9b8ffa7da57a8baa02cfb937317658d807c79
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ spec/assets/img.svg
data/Gemfile CHANGED
@@ -6,7 +6,4 @@ git_source(:github) { |repo| "https://github.com/#{repo}" }
6
6
 
7
7
  gemspec
8
8
 
9
- if File.exist? "Gemfile.devel"
10
- eval File.read("Gemfile.devel"), nil, "Gemfile.devel" # rubocop:disable Security/Eval
11
- end
12
-
9
+ eval_gemfile("Gemfile.devel") rescue nil
data/isodoc.gemspec CHANGED
@@ -31,7 +31,6 @@ Gem::Specification.new do |spec|
31
31
  spec.add_dependency "html2doc", "~> 1.7.1"
32
32
  spec.add_dependency "htmlentities", "~> 4.3.4"
33
33
  # spec.add_dependency "isodoc-i18n", "~> 1.1.0" # already in relaton-render and mn-requirements
34
- spec.add_dependency "emf2svg"
35
34
  spec.add_dependency "liquid", "~> 5"
36
35
  #spec.add_dependency "relaton-cli"
37
36
  # spec.add_dependency "metanorma-utils", "~> 1.5.0" # already in isodoc-i18n
@@ -44,6 +43,7 @@ Gem::Specification.new do |spec|
44
43
  spec.add_dependency "thread_safe"
45
44
  spec.add_dependency "twitter_cldr", ">= 6.6.0"
46
45
  spec.add_dependency "uuidtools"
46
+ spec.add_dependency "vectory", "~> 0.6"
47
47
 
48
48
  spec.add_development_dependency "debug"
49
49
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
@@ -85,7 +85,7 @@ module IsoDoc
85
85
  end
86
86
 
87
87
  def datauri(img)
88
- img["src"] = Metanorma::Utils::datauri(img["src"], @localdir)
88
+ img["src"] = Vectory::Utils::datauri(img["src"], @localdir)
89
89
  end
90
90
 
91
91
  def image_suffix(img)
@@ -58,8 +58,8 @@ module IsoDoc
58
58
  def iso?(org)
59
59
  name = org&.at(ns("./name"))&.text
60
60
  abbrev = org&.at(ns("./abbreviation"))&.text
61
- (abbrev == "ISO" ||
62
- name == "International Organization for Standardization")
61
+ abbrev == "ISO" ||
62
+ name == "International Organization for Standardization"
63
63
  end
64
64
 
65
65
  def agency1(xml)
@@ -1,5 +1,4 @@
1
1
  require "base64"
2
- require "emf2svg"
3
2
 
4
3
  module IsoDoc
5
4
  class PresentationXMLConvert < ::IsoDoc::Convert
@@ -92,33 +91,56 @@ module IsoDoc
92
91
 
93
92
  def svg_prep(img)
94
93
  img["mimetype"] = "image/svg+xml"
95
- %r{^data:image}.match?(img["src"]) or
96
- img["src"] = Metanorma::Utils::datauri(img["src"])
94
+ %r{^data:}.match?(img["src"]) or
95
+ img["src"] = Vectory::Emf.from_path(img["src"]).to_uri.content
97
96
  end
98
97
 
99
98
  def emf_to_svg(img)
100
- emf = Metanorma::Utils::save_dataimage(img.at(ns("./emf/@src")).text)
101
- Emf2svg.from_file(emf).sub(/<\?[^>]+>/, "")
99
+ datauri_src = img.at(ns("./emf/@src")).text
100
+ Vectory::Emf.from_datauri(datauri_src)
101
+ .to_svg
102
+ .content
103
+ .sub(/<\?[^>]+>/, "")
102
104
  end
103
105
 
104
106
  def eps_to_svg(node)
105
- uri = eps_to_svg_uri(node)
106
- ret = imgfile_suffix(uri, "svg")
107
- File.exist?(ret) and return ret
108
- inkscape_convert(uri, ret, "--export-plain-svg")
107
+ if !node.text.strip.empty? || %r{^data:}.match?(node["src"])
108
+ return eps_to_svg_from_node(node)
109
+ end
110
+
111
+ target_path = imgfile_suffix(node["src"], "svg")
112
+ return target_path if File.exist?(target_path)
113
+
114
+ eps_to_svg_from_node(node, target_path)
115
+ end
116
+
117
+ def eps_to_svg_from_node(node, target_path = nil)
118
+ svg = Vectory::Eps.from_node(node).to_svg
119
+ return svg.write(target_path).path if target_path
120
+
121
+ svg.write.path
109
122
  end
110
123
 
111
124
  def svg_to_emf(node)
112
125
  @output_formats[:doc] or return
113
- uri = svg_to_emf_uri(node)
126
+
114
127
  svg_impose_height_attr(node)
115
- ret = imgfile_suffix(uri, "emf")
116
- if File.exist?(ret) && File.exist?(node["src"])
117
- warn "Exists: #{ret}, Exists: #{node['src']}"
118
- return ret
128
+
129
+ if node.elements&.first&.name == "svg" || %r{^data:}.match?(node["src"])
130
+ return svg_to_emf_from_node(node)
119
131
  end
120
- warn "Converting..."
121
- inkscape_convert(uri, ret, '--export-type="emf"')
132
+
133
+ target_path = imgfile_suffix(node["src"], "emf")
134
+ return target_path if File.exist?(target_path)
135
+
136
+ svg_to_emf_from_node(node, target_path)
137
+ end
138
+
139
+ def svg_to_emf_from_node(node, target_path = nil)
140
+ emf = Vectory::Svg.from_node(node).to_emf
141
+ return emf.write(target_path).to_uri.content if target_path
142
+
143
+ emf.to_uri.content
122
144
  end
123
145
 
124
146
  def svg_impose_height_attr(node)
@@ -129,68 +151,8 @@ module IsoDoc
129
151
  node["width"] = e["width"]
130
152
  end
131
153
 
132
- def inkscape_convert(uri, file, option)
133
- exe = inkscape_installed? or raise "Inkscape missing in PATH, unable" \
134
- "to convert image #{uri}. Aborting."
135
- uri = Metanorma::Utils::external_path uri
136
- exe = Metanorma::Utils::external_path exe
137
- warn %(#{exe} #{option} #{uri})
138
- err = system %(#{exe} #{option} #{uri})
139
- File.exist?(file) and return Metanorma::Utils::datauri(file)
140
- file2 = uri + File.extname(file)
141
- warn "Checking #{file2}"
142
- File.exist?(file2) and return Metanorma::Utils::datauri(file2)
143
- raise %(Fail on #{exe} #{option} #{uri} outputting #{file}: status #{err})
144
- end
145
-
146
- def svg_to_emf_uri(node)
147
- uri = svg_to_emf_uri_convert(node)
148
- cache_dataimage(uri)
149
- end
150
-
151
- def eps_to_svg_uri(node)
152
- uri = eps_to_svg_uri_convert(node)
153
- cache_dataimage(uri)
154
- end
155
-
156
- def cache_dataimage(uri)
157
- if %r{^data:}.match?(uri)
158
- uri = save_dataimage(uri)
159
- end
160
- uri
161
- end
162
-
163
- def svg_to_emf_uri_convert(node)
164
- if node.elements&.first&.name == "svg"
165
- a = Base64.strict_encode64(node.children.to_xml)
166
- "data:image/svg+xml;base64,#{a}"
167
- else node["src"]
168
- end
169
- end
170
-
171
- def eps_to_svg_uri_convert(node)
172
- if node.text.strip.empty?
173
- node["src"]
174
- else
175
- a = Base64.strict_encode64(node.children.to_xml)
176
- "data:application/postscript;base64,#{a}"
177
- end
178
- end
179
-
180
154
  def imgfile_suffix(uri, suffix)
181
155
  "#{File.join(File.dirname(uri), File.basename(uri, '.*'))}.#{suffix}"
182
156
  end
183
-
184
- def inkscape_installed?
185
- cmd = "inkscape"
186
- exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
187
- ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
188
- exts.each do |ext|
189
- exe = File.join(path, "#{cmd}#{ext}")
190
- return exe if File.executable?(exe) && !File.directory?(exe)
191
- end
192
- end
193
- nil
194
- end
195
157
  end
196
158
  end
@@ -16,7 +16,7 @@ module IsoDoc
16
16
  s = docxml.at(ns("//sections")) ||
17
17
  docxml.at(ns("//preface"))&.after("<sections/>")&.next_element ||
18
18
  docxml.at(ns("//annex | //bibliography"))&.before("<sections/>")
19
- &.previous_element or return
19
+ &.previous_element or return
20
20
  docxml.xpath(ns(@xrefs.klass.norm_ref_xpath)).each do |r|
21
21
  s << r.remove
22
22
  end
@@ -163,7 +163,7 @@ module IsoDoc
163
163
  # else, use both ordinal, as prefix, and ids
164
164
  def biblio_ref_entry_code(ordinal, ids, _id, _standard, datefn, _bib)
165
165
  # standard and id = nil
166
- ret = (ids[:ordinal] || ids[:metanorma] || "[#{ordinal}]")
166
+ ret = ids[:ordinal] || ids[:metanorma] || "[#{ordinal}]"
167
167
  if ids[:sdo]
168
168
  ret = prefix_bracketed_ref(ret)
169
169
  ret += "#{ids[:sdo]}#{datefn}, "
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "2.7.4".freeze
2
+ VERSION = "2.8.1".freeze
3
3
  end
@@ -99,7 +99,7 @@ module IsoDoc
99
99
  def word_tab_clean(docxml)
100
100
  docxml.xpath("//p[@class='Biblio']//span[@style='mso-tab-count:1']")
101
101
  .each do |s|
102
- s.next.text? or next
102
+ s.next&.text? or next
103
103
  s.next.replace(@c.encode(s.next.text.sub(/^\s+/, ""), :hexadecimal))
104
104
  end
105
105
  end
data/lib/isodoc.rb CHANGED
@@ -10,6 +10,7 @@ require "html2doc"
10
10
  require "liquid"
11
11
  require "htmlentities"
12
12
  require "relaton-render"
13
+ require "vectory"
13
14
 
14
15
  require "isodoc/common"
15
16
  require "isodoc/convert"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isodoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.4
4
+ version: 2.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-21 00:00:00.000000000 Z
11
+ date: 2024-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: html2doc
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 4.3.4
41
- - !ruby/object:Gem::Dependency
42
- name: emf2svg
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: liquid
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -178,6 +164,20 @@ dependencies:
178
164
  - - ">="
179
165
  - !ruby/object:Gem::Version
180
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: vectory
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '0.6'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '0.6'
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: debug
183
183
  requirement: !ruby/object:Gem::Requirement
@@ -329,6 +329,7 @@ executables: []
329
329
  extensions: []
330
330
  extra_rdoc_files: []
331
331
  files:
332
+ - ".gitignore"
332
333
  - ".hound.yml"
333
334
  - ".oss-guides.rubocop.yml"
334
335
  - ".rubocop.yml"