metanorma 2.5.12 → 2.5.13

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e5961ffa32ef7920792abf4fa81f46acf83eaa392ff0311b609522e176ff031
4
- data.tar.gz: 46221dbc4e816d908c54646c99ed3932d9f42ad3c61dbd4984bddcb11e5df117
3
+ metadata.gz: 8e2bbe018164520f24a47304e5a543b33162f139617e751a7bd4a71f5bc4b8c8
4
+ data.tar.gz: cd865930cf21c065807ef2d2e357ce3ee41b1c35708ecdb69ea59eb59963f504
5
5
  SHA512:
6
- metadata.gz: b30c4548c26f3516272babb9e5cdde6fdeac27ddffa99c386573e91f4e4a1f473bb2db6a773a00eb1370690e0e7cef49a41ec0951656aca521f2cdd70a6801c4
7
- data.tar.gz: 2d45ad4787e08c109be79012a618486f827107167acf5cbcedf5bfe2dbca02991932e37a68e9e53d7412ce708af5e9ff58c6d2063c1178beec84d55025a5f578
6
+ metadata.gz: 774a88cefafe5985f8868890f62e1ed552c51a9ffb64cd5b3744394dfe424650a2d32742b48238cb438e03a1ab658ff2681783ad8ed343fcf8d95bc6997ef180
7
+ data.tar.gz: fb5f625706d30499551cad94edad5f9aa4f604e3a60c4ab43c0baf3ff83c298d396db5724dc47f58f04545a2d8d0a45afed1fd0d87ad0fa753db09ba9867bc19
data/Gemfile CHANGED
@@ -30,6 +30,10 @@ gem "canon", "~> 0.3.122"
30
30
  gem "lutaml-store", "~> 0.3.11"
31
31
  #gem "metanorma-iho"
32
32
  #gem "metanorma-iso", ">= 3.2.0"
33
+ # Floor fontist at the variable-font indexing fix (fontist#531/#532):
34
+ # anything below 3.0.31 misses freshly installed variable fonts on
35
+ # locations lookups ("Fira Code" MissingFontError, metanorma-iho#563).
36
+ gem "fontist", "~> 3.0.32"
33
37
  gem "mnconvert"
34
38
  gem "pry"
35
39
  gem "rake", "~> 13.0"
@@ -153,15 +153,63 @@ module Metanorma
153
153
  ::Metanorma::Util.log(error, :warning)
154
154
  end
155
155
 
156
+ # Image relocation for collection rendering, in three ordered passes:
157
+ # anchor every image target at the document that emitted it, then
158
+ # inline SVGs, then encode what remains as data URIs.
156
159
  def datauri_encode(docxml, directory)
160
+ anchor_image_targets(docxml, directory)
161
+ inline_svg_images(docxml, directory)
162
+ datauri_images(docxml, directory)
163
+ docxml
164
+ end
165
+
166
+ # Image targets are emitted relative to the document that carries them
167
+ # (metanorma#646). Each target must be anchored at the emitting
168
+ # document's directory BEFORE it is resolved: Vectory's datauri
169
+ # fallback tries the process working directory first, so a relative
170
+ # target was resolved against wherever the build happened to run --
171
+ # picking a same-named file from the wrong tree, or missing both
172
+ # bases and failing the render. Data URIs, remote URLs and absolute
173
+ # paths carry their own base and pass through; a target that anchors
174
+ # to an existing file is pinned to that absolute path, so only the
175
+ # file's bytes reach the output and the output is build-directory
176
+ # independent. A target that anchors to nothing keeps its emitted
177
+ # form, so a missing image stays a build-independent dangling
178
+ # reference.
179
+ def anchor_image_targets(docxml, directory)
180
+ docxml.xpath(ns("//image")).each do |i|
181
+ anchor_image_target(i, directory)
182
+ end
183
+ end
184
+
185
+ def inline_svg_images(docxml, directory)
157
186
  docxml.xpath(ns("//image")).each do |i|
158
187
  read_in_if_svg(i, directory.sub(%r{(?<!=/)$}, "/"))
159
188
  end
160
- docxml.xpath(ns("//image")).each do |i| # rubocop:disable Style/CombinableLoops
189
+ end
190
+
191
+ def datauri_images(docxml, directory)
192
+ docxml.xpath(ns("//image")).each do |i|
161
193
  (i["src"] && !i["src"].empty?) or next
162
194
  i["src"] = Vectory::Utils::datauri(i["src"], directory)
163
195
  end
164
- docxml
196
+ end
197
+
198
+ def anchor_image_target(img, directory)
199
+ src = img["src"]
200
+ anchorable_base?(src) or return
201
+ path = File.expand_path(src, directory)
202
+ File.file?(path) or return
203
+ img["src"] = path
204
+ end
205
+
206
+ # A target whose base is already determined cannot be re-anchored.
207
+ def anchorable_base?(src)
208
+ return false if src.nil? || src.empty?
209
+
210
+ !(Vectory::Utils.datauri?(src) ||
211
+ Vectory::Utils.url?(src) ||
212
+ Vectory::Utils.absolute_path?(src))
165
213
  end
166
214
 
167
215
  def read_in_if_svg(img, localdir)
@@ -1,3 +1,3 @@
1
1
  module Metanorma
2
- VERSION = "2.5.12".freeze
2
+ VERSION = "2.5.13".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.12
4
+ version: 2.5.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.