Class: IsoDoc::Iso::WordDISConvert

Inherits:
WordConvert
  • Object
show all
Defined in:
lib/isodoc/iso/word_dis_cleanup.rb,
lib/isodoc/iso/word_dis_convert.rb

Constant Summary collapse

STYLESMAP =
{
  AltTerms: "AdmittedTerm",
  TableFootnote: "Tablefootnote",
  formula: "Formula",
  note: "Note",
  example: "Example",
  admonition: "Admonition",
  admonitiontitle: "AdmonitionTitle",
  sourcetitle: "SourceTitle",
  TableTitle: "Tabletitle",
  titlepagesbhead: "TablePageSubhead",
  NormRef: "RefNorm",
  Biblio: "BiblioEntry",
  MsoNormal: "MsoBodyText",
  FigureTitle: "Figuretitle",
  zzwarning: "zzWarning",
  zzwarninghdr: "zzWarningHdr",
  quoteattribution: "QuoteAttribution",
  Sourcecode: "Code",
  zzSTDTitle1: "zzSTDTitle",
  zzSTDTitle2: "zzSTDTitle",
  zzCopyright1: "zzCopyright",
}.freeze
FIGURE_NESTED_STYLES =
{ Note: "Figurenote", example: "Figureexample" }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from WordConvert

#annex_name, #annex_name1, #authority_hdr_cleanup, #bibliography, #bibliography_attrs, #bibliography_parse, #colophon, #convert, #default_fonts, #definition_parse, #figure_cleanup, #figure_name_parse, #font_choice, #footnote_reference_format, #make_WordToC, #make_body, #para_class, #quote_style, #style_cleanup, #table_attrs, #table_title_parse, #termref_attrs, #termref_parse, #word_annex_cleanup, #word_annex_cleanup_h1

Methods included from Init

#amd, #clausedelim, #i18n_init, #metadata_init, #requirements_processor, #std_docid_semantic, #std_docid_semantic1, #std_docid_semantic_full, #xref_init

Methods included from BaseConvert

#admonition_class, #admonition_name_parse, #admonition_p_parse, #admonition_parse, #admonition_parse1, #annex, #clause_etc, #clause_etc1, #cleanup, #error_parse, #example_p_parse, #example_parse, #example_parse1, #example_span_label, #figure_name_parse, #foreword, #formula_where, #implicit_reference, #indexsect, #introduction, #middle, #middle_title_amd, #middle_title_main, #node_begins_with_para, #ol_attrs, #render_identifier, #table_th_center

Constructor Details

#initialize(options) ⇒ WordDISConvert

Returns a new instance of WordDISConvert.



18
19
20
21
22
# File 'lib/isodoc/iso/word_dis_convert.rb', line 18

def initialize(options)
  @libdir ||= File.dirname(__FILE__) # rubocop:disable Lint/DisjunctiveAssignmentInConstructor
  options.merge!(default_file_locations(options))
  super
end

Instance Attribute Details

#bgstripcolorObject

Returns the value of attribute bgstripcolor.



6
7
8
# File 'lib/isodoc/iso/word_dis_convert.rb', line 6

def bgstripcolor
  @bgstripcolor
end

Instance Method Details

#amd_style(docxml) ⇒ Object



82
83
84
85
86
87
88
89
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 82

def amd_style(docxml)
  return unless @meta.get[:doctype] == "Amendment"

  docxml.xpath("//div[@class = 'WordSection3']//h1").each do |h|
    h.name = "p"
    h["style"] = "font-style:italic;page-break-after:avoid;"
  end
end

#authority_cleanup(docxml) ⇒ Object



198
199
200
201
202
203
204
205
206
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 198

def authority_cleanup(docxml)
  super
  if @meta.get[:stage_int].to_s[0] == "9" ||
      @meta.get[:stage_int].to_s[0] == "6"
    copyright_prf(docxml)
  else
    copyright_dis(docxml)
  end
end

#code_style(doc) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 165

def code_style(doc)
  span_style((doc.xpath("//tt//b") - doc.xpath("//tt//i//b")),
             "ISOCodebold")
  span_style((doc.xpath("//tt//i") - doc.xpath("//tt//b//i")),
             "ISOCodeitalic")
  span_style((doc.xpath("//b//tt") - doc.xpath("//b//i//tt")),
             "ISOCodebold")
  span_style((doc.xpath("//i//tt") - doc.xpath("//i//b//tt")),
             "ISOCodeitalic")
  span_style(doc.xpath("//tt"), "ISOCode")
end

#convert1(docxml, filename, dir) ⇒ Object



27
28
29
30
# File 'lib/isodoc/iso/word_dis_convert.rb', line 27

def convert1(docxml, filename, dir)
  update_coverpage(docxml)
  super
end


221
222
223
224
225
226
227
228
229
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 221

def copyright_dis(docxml)
  docxml.xpath("//p[@id = 'boilerplate-address']")&.each do |p|
    p["class"] = "zzCopyright"
    p.replace(to_xml(p).gsub(%r{<br/>}, "</p>\n<p class='zzCopyright'>"))
  end
  docxml.xpath("//p[@class = 'zzCopyrightHdr']")&.each do |p|
    p.remove
  end
end


208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 208

def copyright_prf(docxml)
  docxml.xpath("//p[@id = 'boilerplate-address']")&.each do |p|
    p["class"] = "zzCopyright"
    p["style"] = "text-indent:20.15pt;"
    p.replace(to_xml(p).gsub(%r{<br/>}, "</p>\n<p class='zzCopyright' " \
                                       "style='text-indent:20.15pt;'>"))
  end
  docxml.xpath("//p[@class = 'zzCopyrightHdr']")&.each do |p|
    # p["class"] = "zzCopyright"
    p.remove
  end
end

#default_file_locations(_options) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/isodoc/iso/word_dis_convert.rb', line 8

def default_file_locations(_options)
  { wordstylesheet: html_doc_path("wordstyle-dis.scss"),
    standardstylesheet: html_doc_path("isodoc-dis.scss"),
    header: html_doc_path("header-dis.html"),
    wordcoverpage: html_doc_path("word_iso_titlepage-dis.html"),
    wordintropage: html_doc_path("word_iso_intro-dis.html"),
    ulstyle: "l3",
    olstyle: "l2" }
end

#dis_style_interactions(docxml) ⇒ Object



73
74
75
76
77
78
79
80
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 73

def dis_style_interactions(docxml)
  docxml.xpath("//p[@class = 'Code' or @class = 'Code-' or " \
               "@class = 'Code--']" \
               "[following::p[@class = 'Examplecontinued']]").each do |p|
    p["style"] ||= ""
    p["style"] = "margin-bottom:12pt;#{p['style']}"
  end
end

#dis_styles1(docxml) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 42

def dis_styles1(docxml)
  amd_style(docxml)
  code_style(docxml)
  figure_style(docxml)
  note_style(docxml)
  example_style(docxml)
  dis_style_interactions(docxml)
  quote_style(docxml)
  stripbgcolor(docxml)
end

#example_continued_style(docxml) ⇒ Object



131
132
133
134
135
136
137
138
139
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 131

def example_continued_style(docxml)
  docxml.xpath("//div[@class = 'Example']").each do |d|
    d.xpath("./p").each_with_index do |p, i|
      next if p["class"] && p["class"] != "Example"

      p["class"] = (i.zero? ? "Example" : "Examplecontinued")
    end
  end
end

#example_style(docxml) ⇒ Object



127
128
129
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 127

def example_style(docxml)
  example_continued_style(docxml)
end

#figure_name_attrs(_node) ⇒ Object



42
43
44
# File 'lib/isodoc/iso/word_dis_convert.rb', line 42

def figure_name_attrs(_node)
  { class: "FigureTitle", style: "text-align:center;" }
end

#figure_style(docxml) ⇒ Object



154
155
156
157
158
159
160
161
162
163
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 154

def figure_style(docxml)
  docxml.xpath("//div[@class = 'figure']").each do |f|
    FIGURE_NESTED_STYLES.each do |k, v|
      f.xpath(".//*[@class = '#{k}']").each { |n| n["class"] = v }
    end
    f.xpath("./img").each do |i|
      i.replace("<p class='FigureGraphic'>#{i.to_xml}</p>")
    end
  end
end

#figure_toc_classObject



252
253
254
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 252

def figure_toc_class
  ["Figure Title", "Annex Figure Title", "AnnexFigureTitle"] + super
end

#init_dis(opt) ⇒ Object



24
25
# File 'lib/isodoc/iso/word_dis_convert.rb', line 24

def init_dis(opt)
end

#make_tr_attr(cell, row, totalrows, header, bordered) ⇒ Object



66
67
68
# File 'lib/isodoc/iso/word_dis_convert.rb', line 66

def make_tr_attr(cell, row, totalrows, header, bordered)
  super.merge(header: header)
end

#middle_title(_isoxml, out) ⇒ Object



86
87
88
# File 'lib/isodoc/iso/word_dis_convert.rb', line 86

def middle_title(_isoxml, out)
  middle_title_dis(out)
end

#middle_title_dis(out) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/isodoc/iso/word_dis_convert.rb', line 90

def middle_title_dis(out)
  out.p(**{ class: "zzSTDTitle" }) do |p|
    p << @meta.get[:doctitleintro]
    @meta.get[:doctitleintro] && @meta.get[:doctitlemain] and p << " &#x2014; "
    p << @meta.get[:doctitlemain]
    @meta.get[:doctitlemain] && @meta.get[:doctitlepart] and p << " &#x2014; "
    if @meta.get[:doctitlepart]
      b = @meta.get[:doctitlepartlabel] and
        p << "<span style='font-weight:normal'>#{b}:</span> "
      p << " #{@meta.get[:doctitlepart]}"
    end
    @meta.get[:doctitleamdlabel] || @meta.get[:doctitleamd] ||
      @meta.get[:doctitlecorrlabel] and middle_title_dis_amd(p)
  end
end

#middle_title_dis_amd(para) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
# File 'lib/isodoc/iso/word_dis_convert.rb', line 106

def middle_title_dis_amd(para)
  para.span(**{ style: "font-weight:normal" }) do |p|
    if a = @meta.get[:doctitleamdlabel]
      p << " #{a}"
      a = @meta.get[:doctitleamd] and p << ": #{a}"
    end
    if a = @meta.get[:doctitlecorrlabel]
      p << " #{a}"
    end
  end
end

#new_styles(docxml) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 28

def new_styles(docxml)
  STYLESMAP.each do |k, v|
    docxml.xpath("//*[@class = '#{k}']").each { |s| s["class"] = v }
  end
  docxml.xpath("//h1[@class = 'ForewordTitle' or @class = 'IntroTitle']")
    .each { |h| h.name = "p" }
  dis_styles1(docxml)
  docxml.xpath("//p[not(@class)]").each { |p| p["class"] = "MsoBodyText" }
end

#note_continued_style(docxml) ⇒ Object



141
142
143
144
145
146
147
148
149
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 141

def note_continued_style(docxml)
  docxml.xpath("//div[@class = 'Note']").each do |d|
    d.xpath("./p").each_with_index do |p, i|
      next if p["class"] && p["class"] != "Note"

      p["class"] = (i.zero? ? "Note" : "Notecontinued")
    end
  end
end

#note_style(docxml) ⇒ Object



122
123
124
125
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 122

def note_style(docxml)
  remove_note_label(docxml)
  note_continued_style(docxml)
end

#para_style_change(div, class1, class2) ⇒ Object



91
92
93
94
95
96
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 91

def para_style_change(div, class1, class2)
  s = class1 ? "@class = '#{class1}'" : "not(@class)"
  div.xpath(".//p[#{s}]").each do |p|
    p["class"] = class2
  end
end

#quote_style1(div) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 98

def quote_style1(div)
  para_style_change(div, nil, "BodyTextindent1")
  para_style_change(div, "Code-", "Code--")
  para_style_change(div, "Code", "Code-")
  if div["class"] != "Example"
    para_style_change(div, "Example", "Exampleindent")
    para_style_change(div, "Examplecontinued", "Exampleindentcontinued")
  end
  if div["class"] != "Note"
    para_style_change(div, "Note", "Noteindent")
    para_style_change(div, "Notecontinued", "Noteindentcontinued")
  end
  div.xpath(".//table[@class = 'dl']").each do |t|
    t["style"] = "margin-left: 1cm;"
  end
end

#remove_note_label(doc) ⇒ Object



115
116
117
118
119
120
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 115

def remove_note_label(doc)
  doc.xpath("//span[@class = 'note_label' or @class = 'example_label']")
    .each do |s|
    s.replace(s.children)
  end
end

#sourcecode_styleObject



38
39
40
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 38

def sourcecode_style
  "Code"
end

#span_parse(node, out) ⇒ Object



50
51
52
53
54
# File 'lib/isodoc/iso/word_dis_convert.rb', line 50

def span_parse(node, out)
  out.span **{ class: node["class"] } do |x|
    node.children.each { |n| parse(n, x) }
  end
end

#span_style(xpath, style) ⇒ Object



177
178
179
180
181
182
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 177

def span_style(xpath, style)
  xpath.each do |elem|
    elem.name = "span"
    elem["class"] = style
  end
end

#stripbgcolor(docxml) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 53

def stripbgcolor(docxml)
  @bgstripcolor == "true" or return
  %w(aucollab audeg aufname aurole ausuffix ausurname bibarticle bibetal
     bibfname bibfpage bibissue bibjournal biblpage bibnumber
     biborganization bibsuppl bibsurname biburl bibvolume bibyear
     citebib citeen citefig citefn citetbl bibextlink citeeq citetfn
     auprefix citeapp citesec stddocNumber stddocPartNumber
     stddocTitle aumember stdfootnote stdpublisher stdsection stdyear
     stddocumentType bibalt-year bibbook bbichapterno bibchaptertitle
     bibed-etal bibed-fname bibeditionno bibed-organization bibed-suffix
     bibed-surname bibinstitution bibisbn biblocation bibpagecount
     bibpatent bibpublisher bibreportnum bibschool bibseries bibseriesno
     bibtrans stdsuppl citesection).each do |t|
    docxml.xpath("//span[@class = '#{t}']").each do |s|
      s["style"] ||= ""
      s["style"] = "mso-pattern:none;#{s['style']}"
    end
  end
end

#table_title_attrs(_node) ⇒ Object



46
47
48
# File 'lib/isodoc/iso/word_dis_convert.rb', line 46

def table_title_attrs(_node)
  { class: "TableTitle", style: "text-align:center;" }
end

#table_toc_classObject



247
248
249
250
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 247

def table_toc_class
  ["Table title", "Tabletitle", "Annex Table Title", "AnnexTableTitle"] +
    super
end

#toWord(result, filename, dir, header) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/isodoc/iso/word_dis_convert.rb', line 70

def toWord(result, filename, dir, header)
  result = from_xhtml(word_cleanup(to_xhtml(result)))
    .gsub(/-DOUBLE_HYPHEN_ESCAPE-/, "--")
  @wordstylesheet = wordstylesheet_update
  ::Html2Doc::IsoDIS.new(
    filename: filename,
    imagedir: @localdir,
    stylesheet: @wordstylesheet&.path,
    header_file: header&.path, dir: dir,
    asciimathdelims: [@openmathdelim, @closemathdelim],
    liststyles: { ul: @ulstyle, ol: @olstyle }
  ).process(result)
  header&.unlink
  @wordstylesheet.unlink if @wordstylesheet.is_a?(Tempfile)
end

#update_coverpage(docxml) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/isodoc/iso/word_dis_convert.rb', line 32

def update_coverpage(docxml)
  stage = docxml.at(ns("//bibdata/status/stage"))&.text
  substage = docxml.at(ns("//bibdata/status/substage"))&.text
  if /^9/.match?(stage) || (stage == "60" && substage == "60")
    @wordcoverpage = html_doc_path("word_iso_titlepage.html")
  elsif stage == "60" && substage == "00"
    @wordcoverpage = html_doc_path("word_iso_titlepage-prf.html")
  end
end

#word_annex_cleanup1(docxml, lvl) ⇒ Object



184
185
186
187
188
189
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 184

def word_annex_cleanup1(docxml, lvl)
  docxml.xpath("//h#{lvl}[ancestor::*[@class = 'Section3']]").each do |h2|
    h2.name = "p"
    h2["class"] = "a#{lvl}"
  end
end

#word_cleanup(docxml) ⇒ Object



191
192
193
194
195
196
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 191

def word_cleanup(docxml)
  word_table_cell_para(docxml)
  super
  word_section_end_empty_para(docxml)
  docxml
end

#word_section_end_empty_para(docxml) ⇒ Object



231
232
233
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 231

def word_section_end_empty_para(docxml)
  docxml.at("//div[@class='WordSection1']/p[last()]").remove
end

#word_table_cell_para(docxml) ⇒ Object



235
236
237
238
239
240
241
242
243
244
245
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 235

def word_table_cell_para(docxml)
  docxml.xpath("//td | //th").each do |t|
    s = t["header"] == "true" ? "Tableheader" : "Tablebody"
    t.delete("header")
    if t.at("./p |./div")
      t.xpath("./p | ./div").each { |p| p["class"] = s }
    else
      t.children = "<div class='#{s}'>#{to_xml(t.children)}</div>"
    end
  end
end

#word_toc_preface(level) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/isodoc/iso/word_dis_convert.rb', line 56

def word_toc_preface(level)
  "    <span lang=\"EN-GB\"><span\n    style='mso-element:field-begin'></span><span\n    style='mso-spacerun:yes'>&#xA0;</span>TOC \\\\o \"2-\#{level}\" \\\\h \\\\z \\\\t\n    \"Heading 1,1,ANNEX,1,Biblio Title,1,Foreword Title,1,Intro Title,1,ANNEXN,1,ANNEXZ,1,na2,1,na3,1,na4,1,na5,1,na6,1,Title,1,Base_Heading,1,Box-title,1,Front Head,1,Index Head,1,AMEND Terms Heading,1,AMEND Heading 1 Unnumbered,1\"\n     <span style='mso-element:field-separator'></span></span>\n  TOC\nend\n".freeze