isodoc 1.8.1 → 1.8.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,181 +1,192 @@
1
- module IsoDoc::XrefGen
2
- module Blocks
3
- def hiersep
4
- "."
5
- end
6
-
7
- def hierfigsep
8
- "-"
9
- end
1
+ require_relative "../function/utils"
10
2
 
11
- def subfigure_increment(idx, counter, elem)
12
- if elem.parent.name == "figure" then idx += 1
13
- else
14
- idx = 0
15
- counter.increment(elem)
3
+ module IsoDoc
4
+ module XrefGen
5
+ module Blocks
6
+ def hiersep
7
+ "."
16
8
  end
17
- idx
18
- end
19
-
20
- def sequential_figure_names(clause)
21
- c = Counter.new
22
- j = 0
23
- clause.xpath(ns(".//figure | .//sourcecode[not(ancestor::example)]"))
24
- .each do |t|
25
- j = subfigure_increment(j, c, t)
26
- label = c.print + (j.zero? ? "" : "-#{j}")
27
- next if t["id"].nil? || t["id"].empty?
28
9
 
29
- @anchors[t["id"]] = anchor_struct(
30
- label, nil, @labels["figure"], "figure", t["unnumbered"]
31
- )
10
+ def hierfigsep
11
+ "-"
32
12
  end
33
- end
34
-
35
- def sequential_table_names(clause)
36
- c = Counter.new
37
- clause.xpath(ns(".//table")).reject { |n| blank?(n["id"]) }.each do |t|
38
13
 
39
- @anchors[t["id"]] = anchor_struct(
40
- c.increment(t).print, nil,
41
- @labels["table"], "table", t["unnumbered"]
42
- )
14
+ def subfigure_increment(idx, counter, elem)
15
+ if elem.parent.name == "figure" then idx += 1
16
+ else
17
+ idx = 0
18
+ counter.increment(elem)
19
+ end
20
+ idx
43
21
  end
44
- end
45
22
 
46
- def sequential_formula_names(clause)
47
- c = Counter.new
48
- clause.xpath(ns(".//formula")).reject { |n| blank?(n["id"]) }.each do |t|
49
-
50
- @anchors[t["id"]] = anchor_struct(
51
- c.increment(t).print, t,
52
- t["inequality"] ? @labels["inequality"] : @labels["formula"],
53
- "formula", t["unnumbered"]
54
- )
23
+ def sequential_figure_names(clause)
24
+ c = Counter.new
25
+ j = 0
26
+ clause.xpath(ns(".//figure | .//sourcecode[not(ancestor::example)]"))
27
+ .each do |t|
28
+ next if labelled_ancestor(t) && t.ancestors("figure").empty?
29
+
30
+ j = subfigure_increment(j, c, t)
31
+ label = c.print + (j.zero? ? "" : "-#{j}")
32
+ next if t["id"].nil? || t["id"].empty?
33
+
34
+ @anchors[t["id"]] = anchor_struct(
35
+ label, nil, @labels["figure"], "figure", t["unnumbered"]
36
+ )
37
+ end
55
38
  end
56
- end
57
39
 
58
- FIRST_LVL_REQ = "[not(ancestor::permission or ancestor::requirement or "\
59
- "ancestor::recommendation)]".freeze
40
+ def sequential_table_names(clause)
41
+ c = Counter.new
42
+ clause.xpath(ns(".//table")).reject { |n| blank?(n["id"]) }.each do |t|
43
+ next if labelled_ancestor(t)
60
44
 
61
- def sequential_permission_names(clause, klass, label)
62
- c = Counter.new
63
- clause.xpath(ns(".//#{klass}#{FIRST_LVL_REQ}"))
64
- .reject { |n| blank?(n["id"]) }.each do |t|
65
-
66
- id = c.increment(t).print
67
- @anchors[t["id"]] = anchor_struct(id, t, label, klass, t["unnumbered"])
68
- sequential_permission_names2(t, id)
45
+ @anchors[t["id"]] = anchor_struct(
46
+ c.increment(t).print, nil,
47
+ @labels["table"], "table", t["unnumbered"]
48
+ )
49
+ end
69
50
  end
70
- end
71
-
72
- def sequential_permission_names2(elem, ident)
73
- sequential_permission_names1(elem, ident, "permission",
74
- @labels["permission"])
75
- sequential_permission_names1(elem, ident, "requirement",
76
- @labels["requirement"])
77
- sequential_permission_names1(elem, ident, "recommendation",
78
- @labels["recommendation"])
79
- end
80
-
81
- def sequential_permission_names1(block, lbl, klass, label)
82
- c = Counter.new
83
- block.xpath(ns("./#{klass}")).reject { |n| blank?(n["id"]) }.each do |t|
84
51
 
85
- id = "#{lbl}#{hierfigsep}#{c.increment(t).print}"
86
- @anchors[t["id"]] = anchor_struct(id, t, label, klass, t["unnumbered"])
87
- sequential_permission_names2(t, id)
52
+ def sequential_formula_names(clause)
53
+ c = Counter.new
54
+ clause.xpath(ns(".//formula")).reject do |n|
55
+ blank?(n["id"])
56
+ end.each do |t|
57
+ @anchors[t["id"]] = anchor_struct(
58
+ c.increment(t).print, t,
59
+ t["inequality"] ? @labels["inequality"] : @labels["formula"],
60
+ "formula", t["unnumbered"]
61
+ )
62
+ end
88
63
  end
89
- end
90
-
91
- def sequential_asset_names(clause)
92
- sequential_table_names(clause)
93
- sequential_figure_names(clause)
94
- sequential_formula_names(clause)
95
- sequential_permission_names(clause, "permission", @labels["permission"])
96
- sequential_permission_names(clause, "requirement", @labels["requirement"])
97
- sequential_permission_names(clause, "recommendation",
98
- @labels["recommendation"])
99
- end
100
-
101
- def hierarchical_figure_names(clause, num)
102
- c = Counter.new
103
- j = 0
104
- clause.xpath(ns(".//figure | .//sourcecode[not(ancestor::example)]"))
105
- .each do |t|
106
- j = subfigure_increment(j, c, t)
107
- label = "#{num}#{hiersep}#{c.print}" +
108
- (j.zero? ? "" : "#{hierfigsep}#{j}")
109
- next if t["id"].nil? || t["id"].empty?
110
64
 
111
- @anchors[t["id"]] = anchor_struct(label, nil, @labels["figure"],
112
- "figure", t["unnumbered"])
65
+ FIRST_LVL_REQ = "[not(ancestor::permission or ancestor::requirement or "\
66
+ "ancestor::recommendation)]".freeze
67
+
68
+ def sequential_permission_names(clause, klass, label)
69
+ c = Counter.new
70
+ clause.xpath(ns(".//#{klass}#{FIRST_LVL_REQ}"))
71
+ .reject { |n| blank?(n["id"]) }.each do |t|
72
+ id = c.increment(t).print
73
+ @anchors[t["id"]] =
74
+ anchor_struct(id, t, label, klass, t["unnumbered"])
75
+ sequential_permission_names2(t, id)
76
+ end
113
77
  end
114
- end
115
78
 
116
- def hierarchical_table_names(clause, num)
117
- c = Counter.new
118
- clause.xpath(ns(".//table")).reject { |n| blank?(n["id"]) }.each do |t|
79
+ def sequential_permission_names2(elem, ident)
80
+ sequential_permission_names1(elem, ident, "permission",
81
+ @labels["permission"])
82
+ sequential_permission_names1(elem, ident, "requirement",
83
+ @labels["requirement"])
84
+ sequential_permission_names1(elem, ident, "recommendation",
85
+ @labels["recommendation"])
86
+ end
119
87
 
120
- @anchors[t["id"]] =
121
- anchor_struct("#{num}#{hiersep}#{c.increment(t).print}",
122
- nil, @labels["table"], "table", t["unnumbered"])
88
+ def sequential_permission_names1(block, lbl, klass, label)
89
+ c = Counter.new
90
+ block.xpath(ns("./#{klass}")).reject { |n| blank?(n["id"]) }.each do |t|
91
+ id = "#{lbl}#{hierfigsep}#{c.increment(t).print}"
92
+ @anchors[t["id"]] =
93
+ anchor_struct(id, t, label, klass, t["unnumbered"])
94
+ sequential_permission_names2(t, id)
95
+ end
123
96
  end
124
- end
125
97
 
126
- def hierarchical_asset_names(clause, num)
127
- hierarchical_table_names(clause, num)
128
- hierarchical_figure_names(clause, num)
129
- hierarchical_formula_names(clause, num)
130
- hierarchical_permission_names(clause, num, "permission",
131
- @labels["permission"])
132
- hierarchical_permission_names(clause, num, "requirement",
98
+ def sequential_asset_names(clause)
99
+ sequential_table_names(clause)
100
+ sequential_figure_names(clause)
101
+ sequential_formula_names(clause)
102
+ sequential_permission_names(clause, "permission", @labels["permission"])
103
+ sequential_permission_names(clause, "requirement",
133
104
  @labels["requirement"])
134
- hierarchical_permission_names(clause, num, "recommendation",
105
+ sequential_permission_names(clause, "recommendation",
135
106
  @labels["recommendation"])
136
- end
107
+ end
108
+
109
+ def hierarchical_figure_names(clause, num)
110
+ c = Counter.new
111
+ j = 0
112
+ clause.xpath(ns(".//figure | .//sourcecode[not(ancestor::example)]"))
113
+ .each do |t|
114
+ next if labelled_ancestor(t) && t.ancestors("figure").empty?
115
+
116
+ j = subfigure_increment(j, c, t)
117
+ label = "#{num}#{hiersep}#{c.print}" +
118
+ (j.zero? ? "" : "#{hierfigsep}#{j}")
119
+ next if t["id"].nil? || t["id"].empty?
120
+
121
+ @anchors[t["id"]] = anchor_struct(label, nil, @labels["figure"],
122
+ "figure", t["unnumbered"])
123
+ end
124
+ end
137
125
 
138
- def hierarchical_formula_names(clause, num)
139
- c = Counter.new
140
- clause.xpath(ns(".//formula")).reject { |n| blank?(n["id"]) }.each do |t|
126
+ def hierarchical_table_names(clause, num)
127
+ c = Counter.new
128
+ clause.xpath(ns(".//table")).reject { |n| blank?(n["id"]) }.each do |t|
129
+ next if labelled_ancestor(t)
141
130
 
142
- @anchors[t["id"]] = anchor_struct(
143
- "#{num}#{hiersep}#{c.increment(t).print}", nil,
144
- t["inequality"] ? @labels["inequality"] : @labels["formula"],
145
- "formula", t["unnumbered"]
146
- )
131
+ @anchors[t["id"]] =
132
+ anchor_struct("#{num}#{hiersep}#{c.increment(t).print}",
133
+ nil, @labels["table"], "table", t["unnumbered"])
134
+ end
147
135
  end
148
- end
149
136
 
150
- def hierarchical_permission_names(clause, num, klass, label)
151
- c = Counter.new
152
- clause.xpath(ns(".//#{klass}#{FIRST_LVL_REQ}"))
153
- .reject { |n| blank?(n["id"]) }.each do |t|
137
+ def hierarchical_asset_names(clause, num)
138
+ hierarchical_table_names(clause, num)
139
+ hierarchical_figure_names(clause, num)
140
+ hierarchical_formula_names(clause, num)
141
+ hierarchical_permission_names(clause, num, "permission",
142
+ @labels["permission"])
143
+ hierarchical_permission_names(clause, num, "requirement",
144
+ @labels["requirement"])
145
+ hierarchical_permission_names(clause, num, "recommendation",
146
+ @labels["recommendation"])
147
+ end
154
148
 
155
- id = "#{num}#{hiersep}#{c.increment(t).print}"
156
- @anchors[t["id"]] =
157
- anchor_struct(id, nil, label, klass, t["unnumbered"])
158
- hierarchical_permission_names2(t, id)
149
+ def hierarchical_formula_names(clause, num)
150
+ c = Counter.new
151
+ clause.xpath(ns(".//formula")).reject do |n|
152
+ blank?(n["id"])
153
+ end.each do |t|
154
+ @anchors[t["id"]] = anchor_struct(
155
+ "#{num}#{hiersep}#{c.increment(t).print}", nil,
156
+ t["inequality"] ? @labels["inequality"] : @labels["formula"],
157
+ "formula", t["unnumbered"]
158
+ )
159
+ end
159
160
  end
160
- end
161
161
 
162
- def hierarchical_permission_names2(elem, ident)
163
- hierarchical_permission_names1(elem, ident, "permission",
164
- @labels["permission"])
165
- hierarchical_permission_names1(elem, ident, "requirement",
166
- @labels["requirement"])
167
- hierarchical_permission_names1(elem, ident, "recommendation",
168
- @labels["recommendation"])
169
- end
162
+ def hierarchical_permission_names(clause, num, klass, label)
163
+ c = Counter.new
164
+ clause.xpath(ns(".//#{klass}#{FIRST_LVL_REQ}"))
165
+ .reject { |n| blank?(n["id"]) }.each do |t|
166
+ id = "#{num}#{hiersep}#{c.increment(t).print}"
167
+ @anchors[t["id"]] =
168
+ anchor_struct(id, nil, label, klass, t["unnumbered"])
169
+ hierarchical_permission_names2(t, id)
170
+ end
171
+ end
170
172
 
171
- def hierarchical_permission_names1(block, lbl, klass, label)
172
- c = Counter.new
173
- block.xpath(ns("./#{klass}")).reject { |n| blank?(n["id"]) }.each do |t|
173
+ def hierarchical_permission_names2(elem, ident)
174
+ hierarchical_permission_names1(elem, ident, "permission",
175
+ @labels["permission"])
176
+ hierarchical_permission_names1(elem, ident, "requirement",
177
+ @labels["requirement"])
178
+ hierarchical_permission_names1(elem, ident, "recommendation",
179
+ @labels["recommendation"])
180
+ end
174
181
 
175
- id = "#{lbl}#{hierfigsep}#{c.increment(t).print}"
176
- @anchors[t["id"]] =
177
- anchor_struct(id, nil, label, klass, t["unnumbered"])
178
- hierarchical_permission_names2(t, id)
182
+ def hierarchical_permission_names1(block, lbl, klass, label)
183
+ c = Counter.new
184
+ block.xpath(ns("./#{klass}")).reject { |n| blank?(n["id"]) }.each do |t|
185
+ id = "#{lbl}#{hierfigsep}#{c.increment(t).print}"
186
+ @anchors[t["id"]] =
187
+ anchor_struct(id, nil, label, klass, t["unnumbered"])
188
+ hierarchical_permission_names2(t, id)
189
+ end
179
190
  end
180
191
  end
181
192
  end
@@ -4,8 +4,7 @@ module IsoDoc
4
4
  def back_anchor_names(docxml)
5
5
  i = Counter.new("@")
6
6
  docxml.xpath(ns("//annex")).each do |c|
7
- i.increment(c)
8
- annex_names(c, i.print)
7
+ annex_names(c, i.increment(c).print)
9
8
  end
10
9
  docxml.xpath(ns(@klass.bibliography_xpath)).each do |b|
11
10
  preface_names(b)
@@ -86,8 +85,7 @@ module IsoDoc
86
85
  level: lvl, type: "clause" }
87
86
  i = Counter.new
88
87
  clause.xpath(ns(SUBCLAUSES)).each do |c|
89
- i.increment(c)
90
- section_names1(c, "#{num.print}.#{i.print}", lvl + 1)
88
+ section_names1(c, "#{num.print}.#{i.increment(c).print}", lvl + 1)
91
89
  end
92
90
  num
93
91
  end
@@ -98,8 +96,7 @@ module IsoDoc
98
96
  type: "clause" }
99
97
  i = Counter.new
100
98
  clause.xpath(ns(SUBCLAUSES)).each do |c|
101
- i.increment(c)
102
- section_names1(c, "#{num}.#{i.print}", level + 1)
99
+ section_names1(c, "#{num}.#{i.increment(c).print}", level + 1)
103
100
  end
104
101
  end
105
102
 
@@ -129,8 +126,7 @@ module IsoDoc
129
126
  else
130
127
  i = Counter.new
131
128
  clause.xpath(ns(SUBCLAUSES)).each do |c|
132
- i.increment(c)
133
- annex_names1(c, "#{num}.#{i.print}", 2)
129
+ annex_names1(c, "#{num}.#{i.increment(c).print}", 2)
134
130
  end
135
131
  end
136
132
  hierarchical_asset_names(clause, num)
@@ -141,8 +137,7 @@ module IsoDoc
141
137
  label: num, level: level, type: "clause" }
142
138
  i = Counter.new
143
139
  clause.xpath(ns(SUBCLAUSES)).each do |c|
144
- i.increment(c)
145
- annex_names1(c, "#{num}.#{i.print}", level + 1)
140
+ annex_names1(c, "#{num}.#{i.increment(c).print}", level + 1)
146
141
  end
147
142
  end
148
143
 
data/lib/isodoc/xref.rb CHANGED
@@ -4,12 +4,14 @@ require_relative "xref/xref_gen_seq"
4
4
  require_relative "xref/xref_gen"
5
5
  require_relative "xref/xref_sect_gen"
6
6
  require_relative "class_utils"
7
+ require_relative "function/utils"
7
8
 
8
9
  module IsoDoc
9
10
  class Xref
10
11
  include XrefGen::Anchor
11
12
  include XrefGen::Blocks
12
13
  include XrefGen::Sections
14
+ include Function::Utils
13
15
 
14
16
  attr_reader :klass
15
17
 
@@ -8,9 +8,30 @@ module IsoDoc
8
8
  def initialize(options)
9
9
  @format = :pdf
10
10
  @suffix = "pdf"
11
+ @pdf_cmd_options = extract_cmd_options(options)
11
12
  super
12
13
  end
13
14
 
15
+ def extract_cmd_options(options)
16
+ ret = {}
17
+ a = options[:pdfencryptionlength] and ret["--encryption-length"] = a
18
+ a = options[:pdfownerpassword] and ret["--owner-password"] = a
19
+ a = options[:pdfuserpassword] and ret["--user-password"] = a
20
+ a = options[:pdfallowprint] and ret["--allow-print"] = a
21
+ a = options[:pdfallowcopycontent] and ret["--allow-copy-content"] = a
22
+ a = options[:pdfalloweditcontent] and ret["--allow-edit-content"] = a
23
+ a = options[:pdfalloweditannotations] and
24
+ ret["--allow-edit-annotations"] = a
25
+ a = options[:pdfallowfillinforms] and ret["--allow-fill-in-forms"] = a
26
+ a = options[:pdfallowaccesscontent] and
27
+ ret["--allow-access-content"] = a
28
+ a = options[:pdfallowassembledocument] and
29
+ ret["--allow-assemble-document"] = a
30
+ a = options[:pdfallowprinthq] and ret["--allow-print-hq"] = a
31
+ a = options[:pdfencryptmetadata] and ret["--encrypt-metadata"] = a
32
+ ret
33
+ end
34
+
14
35
  def tmpimagedir_suffix
15
36
  "_pdfimages"
16
37
  end
@@ -29,7 +50,7 @@ module IsoDoc
29
50
  @aligncrosselements.gsub(/,/, " ")
30
51
  @baseassetpath and
31
52
  ret["--param baseassetpath="] = @baseassetpath
32
- ret
53
+ ret.merge(@pdf_cmd_options)
33
54
  end
34
55
 
35
56
  def convert(input_filename, file = nil, debug = false,
@@ -37,6 +58,7 @@ module IsoDoc
37
58
  file = File.read(input_filename, encoding: "utf-8") if file.nil?
38
59
  input_filename, docxml, filename = input_xml_path(input_filename,
39
60
  file, debug)
61
+ warn pdf_options(docxml).merge(@options)
40
62
  ::Metanorma::Output::XslfoPdf.new.convert(
41
63
  input_filename,
42
64
  output_filename || "#{filename}.#{@suffix}",
@@ -94,6 +94,9 @@ grammar_abbrevs:
94
94
  feminine: مؤ
95
95
  neuter: محايد
96
96
  common: خنثى
97
+ singular: مفرد
98
+ dual: مزدوج
99
+ plural: جمع
97
100
  isPreposition: حرف جر
98
101
  isParticiple: النعت
99
102
  isAdjective: صفة
@@ -98,6 +98,9 @@ grammar_abbrevs:
98
98
  feminine: fem
99
99
  neuter: neutr
100
100
  common: gemein
101
+ singular: Sg
102
+ dual: Dual
103
+ plural: Pl
101
104
  isPreposition: Präp
102
105
  isParticiple: Part
103
106
  isAdjective: Adj
@@ -100,16 +100,19 @@ locality: {
100
100
  formula: Formula
101
101
  }
102
102
  grammar_abbrevs:
103
- masculine: masc
104
- feminine: fem
105
- neuter: neut
103
+ masculine: m
104
+ feminine: f
105
+ neuter: n
106
106
  common: common
107
+ singular: sg
108
+ dual: dual
109
+ pl: pl
107
110
  isPreposition: prep
108
111
  isParticiple: part
109
112
  isAdjective: adj
110
113
  isAdverb: adv
111
- isNoun: n
112
- isVerb: v
114
+ isNoun: noun
115
+ isVerb: verb
113
116
  relatedterms:
114
117
  deprecates: deprecates
115
118
  supersedes: supersedes
@@ -100,6 +100,9 @@ grammar_abbrevs:
100
100
  feminine: fem
101
101
  neuter: neut
102
102
  common: epicen@
103
+ singular: sg
104
+ dual: dual
105
+ plural: pl
103
106
  isPreposition: prep
104
107
  isParticiple: part
105
108
  isAdjective: adj
@@ -97,6 +97,9 @@ grammar_abbrevs:
97
97
  feminine: fem
98
98
  neuter: neut
99
99
  common: épicène
100
+ singular: sg
101
+ dual: duel
102
+ plural: pl
100
103
  isPreposition: prép
101
104
  isParticiple: part
102
105
  isAdjective: adj
@@ -103,6 +103,9 @@ grammar_abbrevs:
103
103
  feminine: жен
104
104
  neuter: ср
105
105
  common: общего рода
106
+ singular: ед
107
+ dual: дв
108
+ plural: мн
106
109
  isPreposition: предл
107
110
  isParticiple: прич
108
111
  isAdjective: прил
@@ -98,6 +98,9 @@ grammar_abbrevs:
98
98
  feminine: 阴性
99
99
  neuter: 中性的
100
100
  common: 通性
101
+ singular: 单数
102
+ dual: 双
103
+ plural: 复数
101
104
  isPreposition: 介词
102
105
  isParticiple: 分词
103
106
  isAdjective: 形容词