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, #br, #colophon, #convert, #default_fonts, #definition_parse, #figure_cleanup, #figure_name_parse, #font_choice, #footnote_reference_format, #index_cleanup, #indexsect, #indexsect_title, #make_WordToC, #make_body, #para_class, #quote_style, #style_cleanup, #table_attrs, #table_parse, #table_parse_tail, #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, #figure_parse1, #foreword, #implicit_reference, #indexsect, #measurement_units, #middle, #middle_title_amd, #middle_title_main, #node_begins_with_para, #ol_attrs, #render_identifier, #table_parse, #table_parse_tail, #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



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

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



117
118
119
120
121
122
123
124
125
# File 'lib/isodoc/iso/word_dis_convert.rb', line 117

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



174
175
176
177
178
179
180
181
182
183
184
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 174

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



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

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


137
138
139
140
141
142
143
# File 'lib/isodoc/iso/word_dis_convert.rb', line 137

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(&:remove)
end


127
128
129
130
131
132
133
134
135
# File 'lib/isodoc/iso/word_dis_convert.rb', line 127

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(&:remove)
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



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

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
52
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 42

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

#example_continued_style(docxml) ⇒ Object



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

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



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

def example_style(docxml)
  example_continued_style(docxml)
end

#figure_name_attrs(_node) ⇒ Object



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

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

#figure_style(docxml) ⇒ Object



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

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



234
235
236
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 234

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

#formula_style(docxml) ⇒ Object



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

def formula_style(docxml)
  docxml.xpath("//div[@class = 'Formula']").each do |f|
    f.xpath(".//p[not(@class)]").each do |p|
      p["class"] = "Formula"
    end
  end
end

#init_dis(opt) ⇒ Object



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

def init_dis(opt); end

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



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

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

#middle_title(_isoxml, out) ⇒ Object



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

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

#middle_title_dis(out) ⇒ Object



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

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



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

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



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

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



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

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

#para_style_change(div, class1, class2) ⇒ Object



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

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



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

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



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

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



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

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



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

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

#stripbgcolor(docxml) ⇒ Object



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

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



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

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

#table_toc_classObject



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

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

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



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

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



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

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



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

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



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

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



207
208
209
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 207

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

#word_table_cell_para(docxml) ⇒ Object



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

def word_table_cell_para(docxml)
  docxml.xpath("//td | //th").each do |t|
    s = word_table_cell_para_style(t)
    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_table_cell_para_style(cell) ⇒ Object



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

def word_table_cell_para_style(cell)
  ret = cell["header"] == "true" ? "Tableheader" : "Tablebody"
  cell["class"] == "rouge-code" and ret = "Code"
  ret
end

#word_toc_preface(level) ⇒ Object



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

def word_toc_preface(level)
  <<~TOC.freeze
    <span lang="EN-GB"><span
    style='mso-element:field-begin'></span><span
    style='mso-spacerun:yes'>&#xA0;</span>TOC \\o "2-#{level}" \\h \\z \\t
    "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"
     <span style='mso-element:field-separator'></span></span>
  TOC
end