isodoc 1.8.2.1 → 1.8.3.2

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.
@@ -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,7 +8,31 @@ 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
13
+ %i(bodyfont headerfont monospacefont).each do |x|
14
+ @options.delete(x)
15
+ end
16
+ end
17
+
18
+ def extract_cmd_options(options)
19
+ ret = {}
20
+ a = options[:pdfencryptionlength] and ret["--encryption-length"] = a
21
+ a = options[:pdfownerpassword] and ret["--owner-password"] = a
22
+ a = options[:pdfuserpassword] and ret["--user-password"] = a
23
+ a = options[:pdfallowprint] and ret["--allow-print"] = a
24
+ a = options[:pdfallowcopycontent] and ret["--allow-copy-content"] = a
25
+ a = options[:pdfalloweditcontent] and ret["--allow-edit-content"] = a
26
+ a = options[:pdfalloweditannotations] and
27
+ ret["--allow-edit-annotations"] = a
28
+ a = options[:pdfallowfillinforms] and ret["--allow-fill-in-forms"] = a
29
+ a = options[:pdfallowaccesscontent] and
30
+ ret["--allow-access-content"] = a
31
+ a = options[:pdfallowassembledocument] and
32
+ ret["--allow-assemble-document"] = a
33
+ a = options[:pdfallowprinthq] and ret["--allow-print-hq"] = a
34
+ a = options[:pdfencryptmetadata] and ret["--encrypt-metadata"] = a
35
+ ret
12
36
  end
13
37
 
14
38
  def tmpimagedir_suffix
@@ -29,7 +53,7 @@ module IsoDoc
29
53
  @aligncrosselements.gsub(/,/, " ")
30
54
  @baseassetpath and
31
55
  ret["--param baseassetpath="] = @baseassetpath
32
- ret
56
+ ret.merge(@pdf_cmd_options)
33
57
  end
34
58
 
35
59
  def convert(input_filename, file = nil, debug = false,
@@ -37,6 +61,7 @@ module IsoDoc
37
61
  file = File.read(input_filename, encoding: "utf-8") if file.nil?
38
62
  input_filename, docxml, filename = input_xml_path(input_filename,
39
63
  file, debug)
64
+ warn pdf_options(docxml).merge(@options)
40
65
  ::Metanorma::Output::XslfoPdf.new.convert(
41
66
  input_filename,
42
67
  output_filename || "#{filename}.#{@suffix}",
@@ -1053,133 +1053,4 @@ RSpec.describe IsoDoc do
1053
1053
  </html>
1054
1054
  OUTPUT
1055
1055
  end
1056
-
1057
- it "cleans up term sources" do
1058
- c = IsoDoc::HtmlConvert.new({ i18nyaml: "spec/assets/i18n.yaml" })
1059
- c.i18n_init("en", "Latn")
1060
- expect(xmlpp(c.textcleanup(<<~"INPUT").to_s)).to be_equivalent_to xmlpp(<<~"OUTPUT")
1061
- #{HTML_HDR}
1062
- <p class="zzSTDTitle1"/>
1063
- <div id="_terms_and_definitions"><h1>1.&#160; Terms and Definitions</h1><p>For the purposes of this document,
1064
- the following terms and definitions apply.</p>
1065
- <p class="TermNum" id="paddy1">1.1.</p><p class="Terms" style="text-align:left;">paddy</p>
1066
- <p id="_eb29b35e-123e-4d1c-b50b-2714d41e747f">&lt;rice&gt; rice retaining its husk after threshing</p>
1067
- <div id="_bd57bbf1-f948-4bae-b0ce-73c00431f892" class="example"><p class="example-title">EXAMPLE 1</p>
1068
- <p id="_65c9a509-9a89-4b54-a890-274126aeb55c">Foreign seeds, husks, bran, sand, dust.</p>
1069
- <ul>
1070
- <li>A</li>
1071
- </ul>
1072
- </div>
1073
- <div id="_bd57bbf1-f948-4bae-b0ce-73c00431f894" class="example"><p class="example-title">EXAMPLE 2</p>
1074
- <ul>
1075
- <li>A</li>
1076
- </ul>
1077
- </div>
1078
- <p>[TERMREF]
1079
- <a href="#ISO7301">ISO 7301:2011, Clause 3.1</a>
1080
- [MODIFICATION]The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here
1081
- [/TERMREF]</p>
1082
- <p>[TERMREF] Termbase IEV, term ID xyz [/TERMREF]</p>
1083
- <p>[TERMREF] Termbase IEV, term ID xyz [MODIFICATION] [/TERMREF]</p>
1084
- <p>[TERMREF] Termbase IEV, term ID xyz [MODIFICATION]with adjustments [/TERMREF]</p>
1085
- <p class="TermNum" id="paddy">1.2.</p><p class="Terms" style="text-align:left;">paddy</p><p class="AltTerms" style="text-align:left;">paddy rice</p>
1086
- <p class="AltTerms" style="text-align:left;">rough rice</p>
1087
- <p class="DeprecatedTerms" style="text-align:left;">DEPRECATED: cargo rice</p>
1088
- <p id="_eb29b35e-123e-4d1c-b50b-2714d41e747f">rice retaining its husk after threshing</p>
1089
- <div id="_bd57bbf1-f948-4bae-b0ce-73c00431f893" class="example"><p class="example-title">EXAMPLE</p>
1090
- <ul>
1091
- <li>A</li>
1092
- </ul>
1093
- </div>
1094
- <div class="Note"><p>Note 1 to entry: The starch of waxy rice consists almost entirely of amylopectin. The kernels have a tendency to stick together after cooking.</p></div>
1095
- <div class="Note"><p>Note 2 to entry: <ul><li>A</li></ul><p id="_19830f33-e46c-42cc-94ca-a5ef101132d5">The starch of waxy rice consists almost entirely of amylopectin. The kernels have a tendency to stick together after cooking.</p></p></div>
1096
- <p>[TERMREF]
1097
- <a href="#ISO7301">ISO 7301:2011, Clause 3.1</a>
1098
- [/TERMREF]</p></div>
1099
- </div>
1100
- </body>
1101
- </html>
1102
- INPUT
1103
- <html xmlns:epub='http://www.idpf.org/2007/ops' lang='en'>
1104
- <head/>
1105
- <body lang='en'>
1106
- <div class='title-section'>
1107
- <p>&#160;</p>
1108
- </div>
1109
- <br/>
1110
- <div class='prefatory-section'>
1111
- <p>&#160;</p>
1112
- </div>
1113
- <br/>
1114
- <div class='main-section'>
1115
- <p class='zzSTDTitle1'/>
1116
- <div id='_terms_and_definitions'>
1117
- <h1>1.&#160; Terms and Definitions</h1>
1118
- <p>For the purposes of this document, the following terms and definitions apply.</p>
1119
- <p class='TermNum' id='paddy1'>1.1.</p>
1120
- <p class='Terms' style='text-align:left;'>paddy</p>
1121
- <p id='_eb29b35e-123e-4d1c-b50b-2714d41e747f'>&lt;rice&gt; rice retaining its husk after threshing</p>
1122
- <div id='_bd57bbf1-f948-4bae-b0ce-73c00431f892' class='example'>
1123
- <p class='example-title'>EXAMPLE 1</p>
1124
- <p id='_65c9a509-9a89-4b54-a890-274126aeb55c'>Foreign seeds, husks, bran, sand, dust.</p>
1125
- <ul>
1126
- <li>A</li>
1127
- </ul>
1128
- </div>
1129
- <div id='_bd57bbf1-f948-4bae-b0ce-73c00431f894' class='example'>
1130
- <p class='example-title'>EXAMPLE 2</p>
1131
- <ul>
1132
- <li>A</li>
1133
- </ul>
1134
- </div>
1135
- <p>
1136
- [SOURCE:
1137
- <a href='#ISO7301'>ISO 7301:2011, Clause 3.1</a>
1138
- , modified &mdash; The term "cargo rice" is shown as deprecated, and
1139
- Note 1 to entry is not included here; Termbase IEV, term ID xyz;
1140
- Termbase IEV, term ID xyz, modified; Termbase IEV, term ID xyz,
1141
- modified &mdash; with adjustments]
1142
- </p>
1143
- <p class='TermNum' id='paddy'>1.2.</p>
1144
- <p class='Terms' style='text-align:left;'>paddy</p>
1145
- <p class='AltTerms' style='text-align:left;'>paddy rice</p>
1146
- <p class='AltTerms' style='text-align:left;'>rough rice</p>
1147
- <p class='DeprecatedTerms' style='text-align:left;'>DEPRECATED: cargo rice</p>
1148
- <p id='_eb29b35e-123e-4d1c-b50b-2714d41e747f'>rice retaining its husk after threshing</p>
1149
- <div id='_bd57bbf1-f948-4bae-b0ce-73c00431f893' class='example'>
1150
- <p class='example-title'>EXAMPLE</p>
1151
- <ul>
1152
- <li>A</li>
1153
- </ul>
1154
- </div>
1155
- <div class='Note'>
1156
- <p>
1157
- Note 1 to entry: The starch of waxy rice consists almost entirely of
1158
- amylopectin. The kernels have a tendency to stick together after
1159
- cooking.
1160
- </p>
1161
- </div>
1162
- <div class='Note'>
1163
- <p>
1164
- Note 2 to entry:
1165
- <ul>
1166
- <li>A</li>
1167
- </ul>
1168
- <p id='_19830f33-e46c-42cc-94ca-a5ef101132d5'>
1169
- The starch of waxy rice consists almost entirely of amylopectin.
1170
- The kernels have a tendency to stick together after cooking.
1171
- </p>
1172
- </p>
1173
- </div>
1174
- <p>
1175
- [SOURCE:
1176
- <a href='#ISO7301'>ISO 7301:2011, Clause 3.1</a>
1177
- ]
1178
- </p>
1179
- </div>
1180
- </div>
1181
- </body>
1182
- </html>
1183
- OUTPUT
1184
- end
1185
1056
  end
@@ -1082,6 +1082,44 @@ RSpec.describe IsoDoc do
1082
1082
  .to be_equivalent_to xmlpp(output)
1083
1083
  end
1084
1084
 
1085
+ it "processes LTR within RTL" do
1086
+ c = IsoDoc::Convert.new({})
1087
+ c.convert_init(<<~"INPUT", "test", false)
1088
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
1089
+ <bibdata type="standard">
1090
+ <language>fa</language>
1091
+ <script>Arab</script>
1092
+ </bibdata>
1093
+ </iso-standard>
1094
+ INPUT
1095
+ expect(c.i18n.l10n("hello!", "en", "Latn")).to eq "&#x200e;hello!&#x200e;"
1096
+ end
1097
+
1098
+ it "processes Hebrew RTL within LTR" do
1099
+ c = IsoDoc::Convert.new({})
1100
+ c.convert_init(<<~"INPUT", "test", false)
1101
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
1102
+ <bibdata type="standard">
1103
+ <language>en</language>
1104
+ </bibdata>
1105
+ </iso-standard>
1106
+ INPUT
1107
+ expect(c.i18n.l10n("hello!", "he", "Hebr")).to eq "&#x200f;hello!&#x200f;"
1108
+ end
1109
+
1110
+ it "processes Arabic RTL within LTR" do
1111
+ c = IsoDoc::Convert.new({})
1112
+ c.convert_init(<<~"INPUT", "test", false)
1113
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
1114
+ <bibdata type="standard">
1115
+ <language>en</language>
1116
+ </bibdata>
1117
+ </iso-standard>
1118
+ INPUT
1119
+ expect(c.i18n.l10n("hello!", "fa", "Arab")).to eq "&#x61c;hello!&#x61c;"
1120
+ end
1121
+
1122
+
1085
1123
  private
1086
1124
 
1087
1125
  def mock_i18n
@@ -671,7 +671,7 @@ RSpec.describe IsoDoc do
671
671
  <title depth='1'>1.<tab/>Terms and definitions</title>
672
672
  <term id='second'>
673
673
  <name>1.1.</name>
674
- <preferred><strong>Second Term, &lt;Field, Usage Info 1&gt;</strong></preferred>
674
+ <preferred><strong>Second Term</strong>, &#x3c;Field, Usage Info 1&#x3e;</preferred>
675
675
  <definition>Definition 1</definition>
676
676
  </term>
677
677
  <term id='C'>
@@ -446,42 +446,6 @@ RSpec.describe IsoDoc do
446
446
  OUTPUT
447
447
  end
448
448
 
449
- it "populates Word template with terms reference labels" do
450
- FileUtils.rm_f "test.doc"
451
- FileUtils.rm_f "test.html"
452
- IsoDoc::WordConvert.new(
453
- { wordstylesheet: "spec/assets/word.css",
454
- htmlstylesheet: "spec/assets/html.scss" },
455
- ).convert("test", <<~"INPUT", false)
456
- <iso-standard xmlns="http://riboseinc.com/isoxml">
457
- <sections>
458
- <terms id="_terms_and_definitions" obligation="normative"><title>1.<tab/>Terms and Definitions</title>
459
- <term id="paddy1"><name>1.1.</name><preferred>paddy</preferred>
460
- <definition><p id="_eb29b35e-123e-4d1c-b50b-2714d41e747f">rice retaining its husk after threshing</p></definition>
461
- <termsource status="modified">
462
- <origin bibitemid="ISO7301" type="inline" citeas="ISO 7301:2011">ISO 7301:2011, Clause 3.1</origin>
463
- <modification>
464
- <p id="_e73a417d-ad39-417d-a4c8-20e4e2529489">The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here</p>
465
- </modification>
466
- </termsource></term>
467
- </terms>
468
- </sections>
469
- </iso-standard>
470
- INPUT
471
- word = File.read("test.doc")
472
- .sub(/^.*<div class="WordSection3">/m, '<div class="WordSection3">')
473
- .sub(%r{<div style="mso-element:footnote-list"/>.*$}m, "")
474
- expect(xmlpp(word)).to be_equivalent_to xmlpp(<<~"OUTPUT")
475
- <div class="WordSection3">
476
- <p class="zzSTDTitle1"></p>
477
- <div><a name="_terms_and_definitions" id="_terms_and_definitions"></a><h1>1.<span style="mso-tab-count:1">&#xA0; </span>Terms and Definitions</h1>
478
- <p class="TermNum"><a name="paddy1" id="paddy1"></a>1.1.</p><p class="Terms" style="text-align:left;">paddy</p>
479
- <p class="MsoNormal"><a name="_eb29b35e-123e-4d1c-b50b-2714d41e747f" id="_eb29b35e-123e-4d1c-b50b-2714d41e747f"></a>rice retaining its husk after threshing</p>
480
- <p class="MsoNormal">[SOURCE: <a href="#ISO7301">ISO 7301:2011, Clause 3.1</a>, modified &#x2014; The term "cargo rice" is shown as deprecated, and Note 1 to entry is not included here]</p></div>
481
- </div>
482
- OUTPUT
483
- end
484
-
485
449
  it "populates Word header" do
486
450
  FileUtils.rm_f "test.doc"
487
451
  IsoDoc::WordConvert.new(
@@ -1220,43 +1184,6 @@ RSpec.describe IsoDoc do
1220
1184
  expect(html).to match(%r{<h2 class="TermNum" id="paddy">1\.2\.</h2>})
1221
1185
  end
1222
1186
 
1223
- it "processes empty term modifications" do
1224
- FileUtils.rm_f "test.html"
1225
- FileUtils.rm_f "test.doc"
1226
- IsoDoc::HtmlConvert.new(options)
1227
- .convert("test", <<~"INPUT", false)
1228
- <iso-standard xmlns="http://riboseinc.com/isoxml">
1229
- <sections>
1230
- <terms id="_terms_and_definitions" obligation="normative"><title>Terms and Definitions</title>
1231
- <term id="paddy1"><preferred>paddy</preferred>
1232
- <domain>rice</domain>
1233
- <definition><p id="_eb29b35e-123e-4d1c-b50b-2714d41e747f">rice retaining its husk after threshing</p></definition>
1234
- <termexample id="_bd57bbf1-f948-4bae-b0ce-73c00431f892">
1235
- <p id="_65c9a509-9a89-4b54-a890-274126aeb55c">Foreign seeds, husks, bran, sand, dust.</p>
1236
- <ul>
1237
- <li>A</li>
1238
- </ul>
1239
- </termexample>
1240
- <termexample id="_bd57bbf1-f948-4bae-b0ce-73c00431f894">
1241
- <ul>
1242
- <li>A</li>
1243
- </ul>
1244
- </termexample>
1245
- <termsource status="modified">
1246
- <origin bibitemid="ISO7301" type="inline" citeas="ISO 7301:2011">ISO 7301:2011, Clause 3.1</origin>
1247
- <modification>
1248
- <p id="_e73a417d-ad39-417d-a4c8-20e4e2529489"/>
1249
- </modification>
1250
- </termsource></term>
1251
- </terms>
1252
- </sections>
1253
- </iso-standard>
1254
- INPUT
1255
- expect(File.exist?("test.html")).to be true
1256
- html = File.read("test.html")
1257
- expect(html).to include '[SOURCE: <a href="#ISO7301">ISO 7301:2011, Clause 3.1</a>, modified]'
1258
- end
1259
-
1260
1187
  it "creates continuation styles for multiparagraph list items in Word" do
1261
1188
  FileUtils.rm_f "test.doc"
1262
1189
  FileUtils.rm_f "test.html"