isodoc 2.2.0 → 2.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/isodoc.gemspec +5 -5
- data/lib/isodoc/class_utils.rb +1 -4
- data/lib/isodoc/convert.rb +56 -42
- data/lib/isodoc/function/references.rb +1 -1
- data/lib/isodoc/function/reqt.rb +17 -88
- data/lib/isodoc/function/table.rb +1 -1
- data/lib/isodoc/function/to_word_html.rb +6 -5
- data/lib/isodoc/function/utils.rb +4 -0
- data/lib/isodoc/i18n.rb +3 -18
- data/lib/isodoc/init.rb +20 -0
- data/lib/isodoc/pdf_convert.rb +0 -1
- data/lib/isodoc/presentation_function/block.rb +23 -6
- data/lib/isodoc/presentation_function/image.rb +68 -19
- data/lib/isodoc/presentation_function/refs.rb +102 -0
- data/lib/isodoc/presentation_function/section.rb +1 -80
- data/lib/isodoc/presentation_function/terms.rb +9 -13
- data/lib/isodoc/presentation_xml_convert.rb +1 -0
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/xref/xref_counter.rb +12 -0
- data/lib/isodoc/xref/xref_gen.rb +17 -5
- data/lib/isodoc/xref/xref_gen_seq.rb +106 -81
- data/lib/isodoc/xref.rb +6 -0
- data/lib/isodoc/xslfo_convert.rb +0 -2
- data/lib/isodoc-yaml/i18n-ar.yaml +0 -2
- data/lib/isodoc-yaml/i18n-de.yaml +0 -2
- data/lib/isodoc-yaml/i18n-en.yaml +9 -2
- data/lib/isodoc-yaml/i18n-es.yaml +0 -2
- data/lib/isodoc-yaml/i18n-fr.yaml +0 -2
- data/lib/isodoc-yaml/i18n-ru.yaml +0 -2
- data/lib/isodoc-yaml/i18n-zh-Hans.yaml +0 -2
- data/lib/relaton/render/general.rb +5 -19
- metadata +42 -34
- data/lib/isodoc/base_style/all.css +0 -227
- data/lib/isodoc/base_style/blocks.css +0 -0
- data/lib/isodoc/base_style/coverpage.css +0 -0
- data/lib/isodoc/base_style/defaults.css +0 -0
- data/lib/isodoc/base_style/metanorma_word.css +0 -47
- data/lib/isodoc/base_style/nav.css +0 -0
- data/lib/isodoc/base_style/reset.css +0 -125
- data/lib/isodoc/base_style/typography.css +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efcdfcde0ed6b8878845a1b030b1bf7f375dc21f7daae1589ba6b8324e06a333
|
4
|
+
data.tar.gz: 6498b1dc8efa9f850c2fed954ec9f7067d847fb932d86b4e353125754e780dad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b6a7404d5021f2ef2db93b83803a122a842febd05e30fb0fbda876407c8b8673382ef818038f73899376d6ba1b465410d12c4076c782829a8292adefd65e758
|
7
|
+
data.tar.gz: 251e5f94894578f8d5e365333a1512a1c8bac91d0c6020afa95d409eb1c9299f4bbb73762c94e2103775e85f5bb43e5b6710161c9f79ebee2fa0d29d5d94f0f1
|
data/isodoc.gemspec
CHANGED
@@ -34,15 +34,16 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.add_dependency "asciimath"
|
35
35
|
spec.add_dependency "html2doc", "~> 1.4.1"
|
36
36
|
spec.add_dependency "htmlentities", "~> 4.3.4"
|
37
|
-
spec.add_dependency "isodoc-i18n", "~> 1.0.
|
37
|
+
spec.add_dependency "isodoc-i18n", "~> 1.0.7"
|
38
38
|
spec.add_dependency "liquid", "~> 4"
|
39
39
|
# spec.add_dependency "metanorma", ">= 1.2.0"
|
40
40
|
spec.add_dependency "emf2svg"
|
41
41
|
spec.add_dependency "mathml2asciimath"
|
42
|
-
spec.add_dependency "metanorma-utils"
|
43
|
-
|
42
|
+
spec.add_dependency "metanorma-utils", "~> 1.4.0"
|
43
|
+
spec.add_dependency "mn2pdf"
|
44
|
+
spec.add_dependency "mn-requirements", "~> 0.1.3"
|
44
45
|
spec.add_dependency "relaton-cli"
|
45
|
-
spec.add_dependency "relaton-render", "
|
46
|
+
spec.add_dependency "relaton-render", "~> 0.4.0"
|
46
47
|
spec.add_dependency "roman-numerals"
|
47
48
|
spec.add_dependency "thread_safe"
|
48
49
|
spec.add_dependency "twitter_cldr", ">= 6.6.0"
|
@@ -52,7 +53,6 @@ Gem::Specification.new do |spec|
|
|
52
53
|
spec.add_development_dependency "equivalent-xml", "~> 0.6"
|
53
54
|
spec.add_development_dependency "guard", "~> 2.14"
|
54
55
|
spec.add_development_dependency "guard-rspec", "~> 4.7"
|
55
|
-
spec.add_development_dependency "metanorma-iso"
|
56
56
|
spec.add_development_dependency "rake", "~> 13.0"
|
57
57
|
spec.add_development_dependency "rexml"
|
58
58
|
spec.add_development_dependency "rspec", "~> 3.6"
|
data/lib/isodoc/class_utils.rb
CHANGED
@@ -13,10 +13,7 @@ module IsoDoc
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def ns(xpath)
|
16
|
-
xpath
|
17
|
-
.gsub(%r{::([a-zA-z])}, "::xmlns:\\1")
|
18
|
-
.gsub(%r{\[([a-zA-z][a-z0-9A-Z@/-]* ?=)}, "[xmlns:\\1")
|
19
|
-
.gsub(%r{\[([a-zA-z][a-z0-9A-Z@/-]*[/\[\]])}, "[xmlns:\\1")
|
16
|
+
Metanorma::Utils::ns(xpath)
|
20
17
|
end
|
21
18
|
|
22
19
|
def liquid(doc)
|
data/lib/isodoc/convert.rb
CHANGED
@@ -5,11 +5,13 @@ require "fileutils"
|
|
5
5
|
require "tempfile"
|
6
6
|
require_relative "i18n"
|
7
7
|
require_relative "css"
|
8
|
+
require_relative "init"
|
8
9
|
require "securerandom"
|
10
|
+
require "mn-requirements"
|
9
11
|
|
10
12
|
module IsoDoc
|
11
13
|
class Convert < ::IsoDoc::Common
|
12
|
-
attr_accessor :options, :i18n, :meta, :xrefs
|
14
|
+
attr_accessor :options, :i18n, :meta, :xrefs, :reqt_models, :requirements_processor
|
13
15
|
|
14
16
|
# htmlstylesheet: Generic stylesheet for HTML
|
15
17
|
# htmlstylesheet_override: Override stylesheet for HTML
|
@@ -45,22 +47,28 @@ module IsoDoc
|
|
45
47
|
# tocrecommendations: add ToC for rcommendations
|
46
48
|
# fonts: fontist fonts to install
|
47
49
|
# fontlicenseagreement: fontist font license agreement
|
48
|
-
def initialize(options)
|
49
|
-
@
|
50
|
+
def initialize(options) # rubocop:disable Lint/MissingSuper
|
51
|
+
@options = options_preprocess(options)
|
52
|
+
init_stylesheets(@options)
|
53
|
+
init_covers(@options)
|
54
|
+
init_toc(@options)
|
55
|
+
init_fonts(@options)
|
56
|
+
init_processing
|
57
|
+
init_locations(@options)
|
58
|
+
init_i18n(@options)
|
59
|
+
init_rendering(@options)
|
60
|
+
end
|
61
|
+
|
62
|
+
def options_preprocess(options)
|
50
63
|
options.merge!(default_fonts(options)) do |_, old, new|
|
51
64
|
old || new
|
52
65
|
end.merge!(default_file_locations(options)) do |_, old, new|
|
53
66
|
old || new
|
54
67
|
end
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
init_stylesheets(options)
|
60
|
-
init_covers(options)
|
61
|
-
init_toc(options)
|
62
|
-
init_fonts(options)
|
63
|
-
@i18nyaml = options[:i18nyaml]
|
68
|
+
options
|
69
|
+
end
|
70
|
+
|
71
|
+
def init_rendering(options)
|
64
72
|
@ulstyle = options[:ulstyle]
|
65
73
|
@olstyle = options[:olstyle]
|
66
74
|
@datauriimage = options[:datauriimage]
|
@@ -69,6 +77,26 @@ module IsoDoc
|
|
69
77
|
@sectionsplit = options[:sectionsplit] == "true"
|
70
78
|
@suppressasciimathdup = options[:suppressasciimathdup] == "true"
|
71
79
|
@bare = options[:bare]
|
80
|
+
@aligncrosselements = options[:aligncrosselements]
|
81
|
+
end
|
82
|
+
|
83
|
+
def init_i18n(options)
|
84
|
+
@i18nyaml = options[:i18nyaml]
|
85
|
+
@lang = options[:language] || "en"
|
86
|
+
@script = options[:script] || "Latn"
|
87
|
+
end
|
88
|
+
|
89
|
+
def init_locations(options)
|
90
|
+
@libdir ||= File.dirname(__FILE__)
|
91
|
+
@baseassetpath = options[:baseassetpath]
|
92
|
+
@tmpimagedir_suffix = tmpimagedir_suffix
|
93
|
+
@tmpfilesdir_suffix = tmpfilesdir_suffix
|
94
|
+
@sourcefilename = options[:sourcefilename]
|
95
|
+
@files_to_delete = []
|
96
|
+
@tempfile_cache = []
|
97
|
+
end
|
98
|
+
|
99
|
+
def init_processing
|
72
100
|
@termdomain = ""
|
73
101
|
@termexample = false
|
74
102
|
@note = false
|
@@ -83,16 +111,10 @@ module IsoDoc
|
|
83
111
|
@c = HTMLEntities.new
|
84
112
|
@openmathdelim = "`"
|
85
113
|
@closemathdelim = "`"
|
86
|
-
@lang = options[:language] || "en"
|
87
|
-
@script = options[:script] || "Latn"
|
88
114
|
@maxwidth = 1200
|
89
115
|
@maxheight = 800
|
90
116
|
@bookmarks_allocated = { "X" => true }
|
91
117
|
@fn_bookmarks = {}
|
92
|
-
@baseassetpath = options[:baseassetpath]
|
93
|
-
@aligncrosselements = options[:aligncrosselements]
|
94
|
-
@tmpimagedir_suffix = tmpimagedir_suffix
|
95
|
-
@tmpfilesdir_suffix = tmpfilesdir_suffix
|
96
118
|
end
|
97
119
|
|
98
120
|
def init_fonts(options)
|
@@ -150,6 +172,10 @@ module IsoDoc
|
|
150
172
|
nil
|
151
173
|
end
|
152
174
|
|
175
|
+
def requirements_processor
|
176
|
+
Metanorma::Requirements
|
177
|
+
end
|
178
|
+
|
153
179
|
def convert1(docxml, filename, dir)
|
154
180
|
@xrefs.parse docxml
|
155
181
|
bibitem_lookup(docxml)
|
@@ -171,35 +197,25 @@ module IsoDoc
|
|
171
197
|
end
|
172
198
|
end
|
173
199
|
|
174
|
-
def metadata_init(lang, script, i18n)
|
175
|
-
@meta = Metadata.new(lang, script, i18n)
|
176
|
-
end
|
177
|
-
|
178
|
-
def xref_init(lang, script, _klass, i18n, options)
|
179
|
-
html = HtmlConvert.new(language: @lang, script: @script)
|
180
|
-
@xrefs = Xref.new(lang, script, html, i18n, options)
|
181
|
-
end
|
182
|
-
|
183
|
-
def i18n_init(lang, script, i18nyaml = nil)
|
184
|
-
@i18n = I18n.new(lang, script, i18nyaml: i18nyaml || @i18nyaml)
|
185
|
-
end
|
186
|
-
|
187
|
-
def l10n(expr, lang = @lang, script = @script)
|
188
|
-
@i18n.l10n(expr, lang, script)
|
189
|
-
end
|
190
|
-
|
191
200
|
def convert_init(file, input_filename, debug)
|
192
201
|
docxml = Nokogiri::XML(file) { |config| config.huge }
|
193
202
|
filename, dir = init_file(input_filename, debug)
|
194
203
|
docxml.root.default_namespace = ""
|
195
|
-
|
196
|
-
script = docxml&.at(ns("//bibdata/script"))&.text and @script = script
|
197
|
-
i18n_init(@lang, @script)
|
204
|
+
convert_i18n_init(docxml)
|
198
205
|
metadata_init(@lang, @script, @i18n)
|
199
206
|
xref_init(@lang, @script, self, @i18n, {})
|
200
207
|
[docxml, filename, dir]
|
201
208
|
end
|
202
209
|
|
210
|
+
def convert_i18n_init(docxml)
|
211
|
+
lang = docxml&.at(ns("//bibdata/language"))&.text and @lang = lang
|
212
|
+
script = docxml&.at(ns("//bibdata/script"))&.text and @script = script
|
213
|
+
i18n_init(@lang, @script)
|
214
|
+
@reqt_models = requirements_processor
|
215
|
+
.new({ default: "default", lang: lang, script: script,
|
216
|
+
labels: @i18n.get })
|
217
|
+
end
|
218
|
+
|
203
219
|
def convert(input_filename, file = nil, debug = false,
|
204
220
|
output_filename = nil)
|
205
221
|
file = File.read(input_filename, encoding: "utf-8") if file.nil?
|
@@ -219,10 +235,8 @@ module IsoDoc
|
|
219
235
|
end
|
220
236
|
|
221
237
|
def target_pdf(node)
|
222
|
-
if /#/.match?(node["target"])
|
223
|
-
|
224
|
-
else
|
225
|
-
"##{node['target']}"
|
238
|
+
if /#/.match?(node["target"]) then node["target"].sub(/#/, ".pdf#")
|
239
|
+
else "##{node['target']}"
|
226
240
|
end
|
227
241
|
end
|
228
242
|
end
|
@@ -120,7 +120,7 @@ module IsoDoc
|
|
120
120
|
def omit_docid_prefix(prefix)
|
121
121
|
return true if prefix.nil? || prefix.empty?
|
122
122
|
|
123
|
-
%w(ISO IEC IEV ITU W3C csd metanorma repository metanorma-ordinal)
|
123
|
+
%w(ISO IEC IEV ITU W3C BIPM csd metanorma repository metanorma-ordinal)
|
124
124
|
.include? prefix
|
125
125
|
end
|
126
126
|
|
data/lib/isodoc/function/reqt.rb
CHANGED
@@ -1,121 +1,50 @@
|
|
1
1
|
module IsoDoc
|
2
2
|
module Function
|
3
3
|
module Blocks
|
4
|
-
def
|
5
|
-
|
6
|
-
end
|
7
|
-
|
8
|
-
def recommendation_name(node, out, _type)
|
9
|
-
label, title, lbl = recommendation_labels(node)
|
10
|
-
out.p **{ class: "RecommendationTitle" } do |b|
|
11
|
-
lbl&.children&.each { |n| parse(n, b) }
|
12
|
-
b << l10n(":")
|
13
|
-
if label || title
|
14
|
-
b.br
|
15
|
-
label&.children&.each { |n| parse(n, b) }
|
16
|
-
b << "#{clausedelim} " if label && title
|
17
|
-
title&.children&.each { |n| parse(n, b) }
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def recommendation_attributes1(node)
|
23
|
-
out = []
|
24
|
-
oblig = node["obligation"] and
|
25
|
-
out << l10n("#{@i18n.obligation}: #{oblig}")
|
26
|
-
node.xpath(ns("./subject")).each do |subj|
|
27
|
-
out << l10n("#{@i18n.subject}: #{subj.text}")
|
28
|
-
end
|
29
|
-
node.xpath(ns("./inherit")).each do |i|
|
30
|
-
out << recommendation_attr_parse(i, @i18n.inherits)
|
31
|
-
end
|
32
|
-
node.xpath(ns("./classification")).each do |c|
|
33
|
-
line = recommendation_attr_keyvalue(c, "tag", "value") and out << line
|
34
|
-
end
|
35
|
-
out
|
36
|
-
end
|
37
|
-
|
38
|
-
def recommendation_attr_parse(node, label)
|
39
|
-
noko do |xml|
|
40
|
-
xml << "#{label}: "
|
41
|
-
node.children.each { |n| parse(n, xml) }
|
42
|
-
end.join
|
43
|
-
end
|
4
|
+
def recommendation_name(name, out)
|
5
|
+
return if name.nil?
|
44
6
|
|
45
|
-
|
46
|
-
|
47
|
-
value = node.at(ns("./#{value}")) or return nil
|
48
|
-
"#{tag.text.capitalize}: #{value.text}"
|
49
|
-
end
|
50
|
-
|
51
|
-
def recommendation_attributes(node, out)
|
52
|
-
ret = recommendation_attributes1(node)
|
53
|
-
return if ret.empty?
|
54
|
-
|
55
|
-
out.p do |p|
|
56
|
-
p.i do |i|
|
57
|
-
i << ret.join("<br/>")
|
58
|
-
end
|
7
|
+
out.p **{ class: "RecommendationTitle" } do |p|
|
8
|
+
name.children.each { |n| parse(n, p) }
|
59
9
|
end
|
60
10
|
end
|
61
11
|
|
62
|
-
def reqt_metadata_node(node)
|
63
|
-
%w(label title subject classification tag value
|
64
|
-
inherit name).include? node.name
|
65
|
-
end
|
66
|
-
|
67
12
|
def reqt_attrs(node, klass)
|
68
13
|
attr_code(class: klass, id: node["id"], style: keep_style(node))
|
69
14
|
end
|
70
15
|
|
71
16
|
def recommendation_parse(node, out)
|
72
17
|
out.div **reqt_attrs(node, "recommend") do |t|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
18
|
+
recommendation_parse1(node, t)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def recommendation_parse1(node, out)
|
23
|
+
recommendation_name(node.at(ns("./name")), out)
|
24
|
+
node.children.each do |n|
|
25
|
+
parse(n, out) unless n.name == "name"
|
78
26
|
end
|
79
27
|
end
|
80
28
|
|
81
29
|
def requirement_parse(node, out)
|
82
30
|
out.div **reqt_attrs(node, "require") do |t|
|
83
|
-
|
84
|
-
recommendation_attributes(node, out)
|
85
|
-
node.children.each do |n|
|
86
|
-
parse(n, t) unless reqt_metadata_node(n)
|
87
|
-
end
|
31
|
+
recommendation_parse1(node, t)
|
88
32
|
end
|
89
33
|
end
|
90
34
|
|
91
35
|
def permission_parse(node, out)
|
92
36
|
out.div **reqt_attrs(node, "permission") do |t|
|
93
|
-
|
94
|
-
recommendation_attributes(node, out)
|
95
|
-
node.children.each do |n|
|
96
|
-
parse(n, t) unless reqt_metadata_node(n)
|
97
|
-
end
|
37
|
+
recommendation_parse1(node, t)
|
98
38
|
end
|
99
39
|
end
|
100
40
|
|
101
|
-
def
|
102
|
-
|
103
|
-
klass == "component" and klass = node["class"]
|
104
|
-
attr_code(class: "requirement-#{klass}",
|
105
|
-
style: keep_style(node))
|
106
|
-
end
|
107
|
-
|
108
|
-
def requirement_component_parse(node, out)
|
109
|
-
return if node["exclude"] == "true"
|
110
|
-
|
111
|
-
out.div **reqt_component_attrs(node) do |div|
|
41
|
+
def div_parse(node, out)
|
42
|
+
out.div **reqt_attrs(node, node["type"]) do |t|
|
112
43
|
node.children.each do |n|
|
113
|
-
parse(n,
|
44
|
+
parse(n, t)
|
114
45
|
end
|
115
46
|
end
|
116
47
|
end
|
117
|
-
|
118
|
-
def requirement_skip_parse(node, out); end
|
119
48
|
end
|
120
49
|
end
|
121
50
|
end
|
@@ -43,7 +43,7 @@ module IsoDoc
|
|
43
43
|
width = node["width"] ? "width:#{node['width']};" : nil
|
44
44
|
attr_code(
|
45
45
|
id: node["id"],
|
46
|
-
class: "MsoISOTable",
|
46
|
+
class: node["class"] || "MsoISOTable",
|
47
47
|
style: "border-width:1px;border-spacing:0;"\
|
48
48
|
"#{width}#{keep_style(node)}",
|
49
49
|
title: node["alt"],
|
@@ -204,11 +204,12 @@ module IsoDoc
|
|
204
204
|
when "requirement" then requirement_parse(node, out)
|
205
205
|
when "recommendation" then recommendation_parse(node, out)
|
206
206
|
when "permission" then permission_parse(node, out)
|
207
|
-
when "
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
207
|
+
when "div" then div_parse(node, out)
|
208
|
+
#when "subject", "classification"
|
209
|
+
# requirement_skip_parse(node, out)
|
210
|
+
#when "inherit", "description", "specification", "measurement-target",
|
211
|
+
#"verification", "import", "component"
|
212
|
+
# requirement_component_parse(node, out)
|
212
213
|
when "index" then index_parse(node, out)
|
213
214
|
when "index-xref" then index_xref_parse(node, out)
|
214
215
|
when "termref" then termrefelem_parse(node, out)
|
@@ -222,6 +222,10 @@ module IsoDoc
|
|
222
222
|
application/x-msmetafile image/x-xbitmap).include? type
|
223
223
|
end
|
224
224
|
|
225
|
+
def eps?(type)
|
226
|
+
%w(application/postscript image/x-eps).include? type
|
227
|
+
end
|
228
|
+
|
225
229
|
def cleanup_entities(text, is_xml: true)
|
226
230
|
c = HTMLEntities.new
|
227
231
|
if is_xml
|
data/lib/isodoc/i18n.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
require "yaml"
|
2
2
|
require "isodoc-i18n"
|
3
3
|
require_relative "function/utils"
|
4
|
+
require "metanorma-utils"
|
4
5
|
|
5
6
|
module IsoDoc
|
6
7
|
class I18n
|
8
|
+
Hash.include Metanorma::Utils::Hash
|
9
|
+
|
7
10
|
def load_yaml1(lang, script)
|
8
11
|
case lang
|
9
12
|
when "en", "fr", "ru", "de", "es", "ar"
|
@@ -24,21 +27,3 @@ module IsoDoc
|
|
24
27
|
end
|
25
28
|
end
|
26
29
|
|
27
|
-
class ::Hash
|
28
|
-
def deep_merge(second)
|
29
|
-
merger = proc { |_, v1, v2|
|
30
|
-
if Hash === v1 && Hash === v2
|
31
|
-
v1.merge(v2, &merger)
|
32
|
-
elsif Array === v1 && Array === v2
|
33
|
-
v1 | v2
|
34
|
-
elsif [:undefined, nil,
|
35
|
-
:nil].include?(v2)
|
36
|
-
v1
|
37
|
-
else
|
38
|
-
v2
|
39
|
-
end
|
40
|
-
}
|
41
|
-
merge(second.to_h, &merger)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
data/lib/isodoc/init.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module IsoDoc
|
2
|
+
class Convert < ::IsoDoc::Common
|
3
|
+
def metadata_init(lang, script, i18n)
|
4
|
+
@meta = Metadata.new(lang, script, i18n)
|
5
|
+
end
|
6
|
+
|
7
|
+
def xref_init(lang, script, _klass, i18n, options)
|
8
|
+
html = HtmlConvert.new(language: @lang, script: @script)
|
9
|
+
@xrefs = Xref.new(lang, script, html, i18n, options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def i18n_init(lang, script, i18nyaml = nil)
|
13
|
+
@i18n = I18n.new(lang, script, i18nyaml: i18nyaml || @i18nyaml)
|
14
|
+
end
|
15
|
+
|
16
|
+
def l10n(expr, lang = @lang, script = @script)
|
17
|
+
@i18n.l10n(expr, lang, script)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/isodoc/pdf_convert.rb
CHANGED
@@ -45,7 +45,6 @@ module IsoDoc
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
# introduce name element
|
49
48
|
def formula1(elem)
|
50
49
|
lbl = @xrefs.anchor(elem["id"], :label, false)
|
51
50
|
prefix_name(elem, "", lbl, "name")
|
@@ -73,7 +72,6 @@ module IsoDoc
|
|
73
72
|
end
|
74
73
|
end
|
75
74
|
|
76
|
-
# introduce name element
|
77
75
|
def note1(elem)
|
78
76
|
return if elem.parent.name == "bibitem" || elem["notag"] == "true"
|
79
77
|
|
@@ -116,11 +114,10 @@ module IsoDoc
|
|
116
114
|
end
|
117
115
|
end
|
118
116
|
|
119
|
-
# introduce name element
|
120
117
|
def recommendation1(elem, type)
|
121
|
-
|
122
|
-
|
123
|
-
prefix_name(elem, "", lbl, "name")
|
118
|
+
lbl = @reqt_models.model(elem["model"])
|
119
|
+
.recommendation_label(elem, type, xrefs)
|
120
|
+
prefix_name(elem, "", l10n(lbl), "name")
|
124
121
|
end
|
125
122
|
|
126
123
|
def table(docxml)
|
@@ -175,5 +172,25 @@ module IsoDoc
|
|
175
172
|
def ol1(elem)
|
176
173
|
elem["type"] ||= ol_depth(elem).to_s
|
177
174
|
end
|
175
|
+
|
176
|
+
def requirement_render_preprocessing(docxml); end
|
177
|
+
|
178
|
+
REQS = %w(requirement recommendation permission).freeze
|
179
|
+
|
180
|
+
def requirement_render(docxml)
|
181
|
+
requirement_render_preprocessing(docxml)
|
182
|
+
REQS.each do |x|
|
183
|
+
REQS.each do |y|
|
184
|
+
docxml.xpath(ns("//#{x}//#{y}")).each { |r| requirement_render1(r) }
|
185
|
+
end
|
186
|
+
end
|
187
|
+
docxml.xpath(ns("//requirement | //recommendation | //permission"))
|
188
|
+
.each { |r| requirement_render1(r) }
|
189
|
+
end
|
190
|
+
|
191
|
+
def requirement_render1(node)
|
192
|
+
node.replace(@reqt_models.model(node["model"])
|
193
|
+
.requirement_render1(node))
|
194
|
+
end
|
178
195
|
end
|
179
196
|
end
|
@@ -11,7 +11,14 @@ module IsoDoc
|
|
11
11
|
else s.remove
|
12
12
|
end
|
13
13
|
end
|
14
|
-
docxml
|
14
|
+
imageconvert(docxml)
|
15
|
+
end
|
16
|
+
|
17
|
+
def imageconvert(docxml)
|
18
|
+
docxml.xpath(ns("//image")).each do |f|
|
19
|
+
eps2svg(f)
|
20
|
+
svg_emf_double(f)
|
21
|
+
end
|
15
22
|
end
|
16
23
|
|
17
24
|
def svg_extract(elem)
|
@@ -36,6 +43,16 @@ module IsoDoc
|
|
36
43
|
l10n("#{lower2cap @i18n.figure} #{lbl}"), "name")
|
37
44
|
end
|
38
45
|
|
46
|
+
def eps2svg(img)
|
47
|
+
return unless eps?(img["mimetype"])
|
48
|
+
|
49
|
+
img["mimetype"] = "image/svg+xml"
|
50
|
+
if src = eps_to_svg(img)
|
51
|
+
img["src"] = src
|
52
|
+
img.children = ""
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
39
56
|
def svg_emf_double(img)
|
40
57
|
if emf?(img["mimetype"])
|
41
58
|
img = emf_encode(img)
|
@@ -46,40 +63,59 @@ module IsoDoc
|
|
46
63
|
end
|
47
64
|
|
48
65
|
def emf_encode(img)
|
49
|
-
img
|
50
|
-
unless %r{^data:image}.match?(img["src"])
|
51
|
-
img["src"] = Metanorma::Utils::datauri(img["src"])
|
52
|
-
end
|
66
|
+
svg_prep(img)
|
53
67
|
img.children = "<emf src='#{img['src']}'/>"
|
54
68
|
img["src"] = ""
|
55
69
|
img
|
56
70
|
end
|
57
71
|
|
72
|
+
def svg_prep(img)
|
73
|
+
img["mimetype"] = "image/svg+xml"
|
74
|
+
%r{^data:image}.match?(img["src"]) or
|
75
|
+
img["src"] = Metanorma::Utils::datauri(img["src"])
|
76
|
+
end
|
77
|
+
|
58
78
|
def emf_to_svg(img)
|
59
79
|
emf = Metanorma::Utils::save_dataimage(img.at(ns("./emf/@src")).text)
|
60
80
|
Emf2svg.from_file(emf).sub(/<\?[^>]+>/, "")
|
61
81
|
end
|
62
82
|
|
83
|
+
def eps_to_svg(node)
|
84
|
+
uri = eps_to_svg_uri(node)
|
85
|
+
ret = imgfile_suffix(uri, "svg")
|
86
|
+
File.exist?(ret) and return ret
|
87
|
+
inkscape_convert(uri, ret, "--export-plain-svg")
|
88
|
+
end
|
89
|
+
|
63
90
|
def svg_to_emf(node)
|
64
91
|
uri = svg_to_emf_uri(node)
|
65
|
-
ret =
|
92
|
+
ret = imgfile_suffix(uri, "emf")
|
66
93
|
File.exist?(ret) and return ret
|
94
|
+
inkscape_convert(uri, ret, '--export-type="emf"')
|
95
|
+
end
|
96
|
+
|
97
|
+
def inkscape_convert(uri, file, option)
|
67
98
|
exe = inkscape_installed? or raise "Inkscape missing in PATH, unable" \
|
68
|
-
"to convert
|
99
|
+
"to convert image #{uri}. Aborting."
|
69
100
|
uri = Metanorma::Utils::external_path uri
|
70
101
|
exe = Metanorma::Utils::external_path exe
|
71
|
-
system(%(#{exe}
|
72
|
-
return Metanorma::Utils::datauri(
|
102
|
+
system(%(#{exe} #{option} #{uri})) and
|
103
|
+
return Metanorma::Utils::datauri(file)
|
73
104
|
|
74
|
-
raise %(Fail on #{exe}
|
105
|
+
raise %(Fail on #{exe} #{option} #{uri})
|
75
106
|
end
|
76
107
|
|
77
108
|
def svg_to_emf_uri(node)
|
78
|
-
uri =
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
109
|
+
uri = svg_to_emf_uri_convert(node)
|
110
|
+
cache_dataimage(uri)
|
111
|
+
end
|
112
|
+
|
113
|
+
def eps_to_svg_uri(node)
|
114
|
+
uri = eps_to_svg_uri_convert(node)
|
115
|
+
cache_dataimage(uri)
|
116
|
+
end
|
117
|
+
|
118
|
+
def cache_dataimage(uri)
|
83
119
|
if %r{^data:}.match?(uri)
|
84
120
|
uri = save_dataimage(uri)
|
85
121
|
@tempfile_cache << uri
|
@@ -87,12 +123,25 @@ module IsoDoc
|
|
87
123
|
uri
|
88
124
|
end
|
89
125
|
|
90
|
-
def
|
91
|
-
|
126
|
+
def svg_to_emf_uri_convert(node)
|
127
|
+
if node&.elements&.first&.name == "svg"
|
128
|
+
a = Base64.strict_encode64(node.children.to_xml)
|
129
|
+
"data:image/svg+xml;base64,#{a}"
|
130
|
+
else node["src"]
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def eps_to_svg_uri_convert(node)
|
135
|
+
if node.text.strip.empty?
|
136
|
+
node["src"]
|
137
|
+
else
|
138
|
+
a = Base64.strict_encode64(node.children.to_xml)
|
139
|
+
"data:application/postscript;base64,#{a}"
|
140
|
+
end
|
92
141
|
end
|
93
142
|
|
94
|
-
def
|
95
|
-
"#{File.join(File.dirname(uri), File.basename(uri, '.*'))}
|
143
|
+
def imgfile_suffix(uri, suffix)
|
144
|
+
"#{File.join(File.dirname(uri), File.basename(uri, '.*'))}.#{suffix}"
|
96
145
|
end
|
97
146
|
|
98
147
|
def inkscape_installed?
|