Class: IsoDoc::Ieee::WordWPConvert

Inherits:
WordConvert
  • Object
show all
Defined in:
lib/isodoc/ieee/word_wp_cleanup.rb,
lib/isodoc/ieee/word_wp_convert.rb

Constant Summary collapse

APPENDIX_STYLE =
%w(Appendix Appendixlevel2 Appendixlevel3).freeze
BLUELINE =
<<~XHTML.freeze
  <o:wrapblock><v:line id="Line_x0020_23" o:spid="_x0000_s2052"
  style='visibility:visible;mso-wrap-style:square;mso-left-percent:-10001;
  mso-top-percent:-10001;mso-position-horizontal:absolute;
  mso-position-horizontal-relative:char;mso-position-vertical:absolute;
  mso-position-vertical-relative:line;mso-left-percent:-10001;mso-top-percent:-10001'
  from="55.05pt,2953.75pt" to="217pt,2953.75pt"
    o:gfxdata="UEsDBBQABgAIAAAAIQC2gziS/gAAAOEBAAATAAAAW0NvbnRlbnRfVHlwZXNdLnhtbJSRQU7DMBBF
  90jcwfIWJU67QAgl6YK0S0CoHGBkTxKLZGx5TGhvj5O2G0SRWNoz/78nu9wcxkFMGNg6quQqL6RA
  0s5Y6ir5vt9lD1JwBDIwOMJKHpHlpr69KfdHjyxSmriSfYz+USnWPY7AufNIadK6MEJMx9ApD/oD
  OlTrorhX2lFEilmcO2RdNtjC5xDF9pCuTyYBB5bi6bQ4syoJ3g9WQ0ymaiLzg5KdCXlKLjvcW893
  SUOqXwnz5DrgnHtJTxOsQfEKIT7DmDSUCaxw7Rqn8787ZsmRM9e2VmPeBN4uqYvTtW7jvijg9N/y
  JsXecLq0q+WD6m8AAAD//wMAUEsDBBQABgAIAAAAIQA4/SH/1gAAAJQBAAALAAAAX3JlbHMvLnJl
  bHOkkMFqwzAMhu+DvYPRfXGawxijTi+j0GvpHsDYimMaW0Yy2fr2M4PBMnrbUb/Q94l/f/hMi1qR
  JVI2sOt6UJgd+ZiDgffL8ekFlFSbvV0oo4EbChzGx4f9GRdb25HMsYhqlCwG5lrLq9biZkxWOiqY
  22YiTra2kYMu1l1tQD30/bPm3wwYN0x18gb45AdQl1tp5j/s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VCpYSqoHpPJuDEkZ6k0rE3e9El4X+H6T8BgAA//8DAFBLAQIt
  ABQABgAIAAAAIQC2gziS/gAAAOEBAAATAAAAAAAAAAAAAAAAAAAAAABbQ29udGVudF9UeXBlc10u
  eG1sUEsBAi0AFAAGAAgAAAAhADj9If/WAAAAlAEAAAsAAAAAAAAAAAAAAAAALwEAAF9yZWxzLy5y
  ZWxzUEsBAi0AFAAGAAgAAAAhAD9cmSSyAQAATQMAAA4AAAAAAAAAAAAAAAAALgIAAGRycy9lMm9E
  b2MueG1sUEsBAi0AFAAGAAgAAAAhAPA1J7PhAAAAEAEAAA8AAAAAAAAAAAAAAAAADAQAAGRycy9k
  b3ducmV2LnhtbFBLBQYAAAAABAAEAPMAAAAaBQAAAAA=
  " strokecolor="#00aeef" strokeweight="8pt">
    <o:lock v:ext="edit" shapetype="f"/>
    <w:wrap type="topAndBottom" anchorx="page"/>
   </v:line></o:wrapblock><br style='mso-ignore:vglayout' clear='ALL'/>
XHTML
ABSTRACT_MARGIN =
"margin-top:18.0pt;margin-right:7.2pt;margin-bottom:6.0pt;" \
"margin-left:0cm;".freeze

Constants inherited from WordConvert

IsoDoc::Ieee::WordConvert::MAIN_ELEMENTS, IsoDoc::Ieee::WordConvert::SECTIONBREAK

Instance Method Summary collapse

Methods inherited from WordConvert

#abstract_header, #admonition_class, #admonition_cleanup, #admonition_name_parse, #annex_attrs, #annex_name, #annex_name1, #authority_cleanup1, #authority_cleanup_hdr, #biblio_cleanup, #caption_cleanup, #convert, #div_cleanup, #dt_dd?, #example_caption, #feedback_footnote, #feedback_style, #feedback_style1, #figure_caption, #figure_toc_class, #formula_parse, #formula_where, #formula_where1, #headings_cleanup, #headings_cleanup1, #headings_strip, #introduction_cleanup, #introduction_cleanup1, #license_style, #make_WordToC, #note_style_cleanup, #note_style_cleanup1, #notesequence, #officeholder_style, #officeorgrep_style, #para_type_cleanup, #sourcecode_cleanup, #sourcecode_style, #style_cleanup, #table_caption, #table_of_contents, #table_toc_class, #tbody_cleanup, #tbody_cleanup1, #tbody_head_cleanup, #td_style, #termnote_label, #termnote_parse, #thead_cell_cleanup, #thead_cleanup, #three_column_officemembers, #three_column_officemembers_render, #three_column_officemembers_split, #word_cleanup

Methods included from Init

#bibrenderer, #fileloc, #i18n_init, #metadata_init, #std_docid_sdo, #std_docid_semantic, #std_docid_semantic1, #std_docid_semantic_full, #xref_init

Methods included from BaseConvert

#clause_attrs, #example_label, #middle_clause, #note_p_parse, #note_parse1, #para_attrs, #scope, #top_element_render

Constructor Details

#initialize(options) ⇒ WordWPConvert

Returns a new instance of WordWPConvert.



6
7
8
9
10
# File 'lib/isodoc/ieee/word_wp_convert.rb', line 6

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

Instance Method Details

#abstract(clause, out) ⇒ Object



80
81
82
83
84
85
# File 'lib/isodoc/ieee/word_wp_convert.rb', line 80

def abstract(clause, out)
  out.div **attr_code(id: clause["id"], class: "abstract_div") do |s|
    abstract_body(clause, s)
  end
  page_break(out)
end

#abstract_body(clause, out) ⇒ Object



87
88
89
90
91
92
# File 'lib/isodoc/ieee/word_wp_convert.rb', line 87

def abstract_body(clause, out)
  clause_name(clause, clause.at(ns("./title")), out,
              { class: stylesmap[:AbstractTitle],
                style: ABSTRACT_MARGIN })
  clause.elements.each { |e| parse(e, out) unless e.name == "title" }
end

#abstract_cleanup(docxml) ⇒ Object



201
202
203
204
205
# File 'lib/isodoc/ieee/word_wp_cleanup.rb', line 201

def abstract_cleanup(docxml)
  if f = docxml.at("//div[@class = 'abstract_div']")
    abstract_cleanup1(f, nil)
  end
end

#abstract_cleanup1(source, _dest) ⇒ Object



207
208
209
210
211
212
213
214
# File 'lib/isodoc/ieee/word_wp_cleanup.rb', line 207

def abstract_cleanup1(source, _dest)
  source.elements.reject { |e| %w(h1 h2).include?(e.name) }.each do |e|
    e.xpath("self::p | .//p").each do |p|
      p["class"] ||= stylesmap[:abstract]
      p["style"] = "margin-left:0cm;margin-right:0.25cm;#{p['style']}"
    end
  end
end

#authority_cleanup(docxml) ⇒ Object



98
99
100
101
102
103
# File 'lib/isodoc/ieee/word_wp_cleanup.rb', line 98

def authority_cleanup(docxml)
  %w(copyright disclaimers tm participants).each do |t|
    authority_cleanup1(docxml, t)
  end
  authority_style(docxml)
end

#authority_style(docxml) ⇒ Object



105
106
107
108
109
# File 'lib/isodoc/ieee/word_wp_cleanup.rb', line 105

def authority_style(docxml)
  copyright_style(docxml)
  legal_style(docxml)
  officer_style(docxml)
end

#backcover(out) ⇒ Object



53
54
55
56
57
# File 'lib/isodoc/ieee/word_wp_convert.rb', line 53

def backcover(out)
  out << populate_template(
    File.read(html_doc_path("word_ieee_colophon_wp.html")), :word
  )
end

#clause(node, out) ⇒ Object



94
95
96
97
# File 'lib/isodoc/ieee/word_wp_convert.rb', line 94

def clause(node, out)
  super
  node.next_element and page_break(out) # only main clauses
end

#clause_parse_subtitle(title, heading) ⇒ Object



108
109
110
# File 'lib/isodoc/ieee/word_wp_convert.rb', line 108

def clause_parse_subtitle(title, heading)
  title&.parent&.name == "annex" or return super
end

#convert1(docxml, filename, dir) ⇒ Object



33
34
35
36
37
38
# File 'lib/isodoc/ieee/word_wp_convert.rb', line 33

def convert1(docxml, filename, dir)
  s = docxml.at(ns("//bibdata/ext/subdoctype"))&.text
  s == "industry-connection-report" and
    @wordcoverpage = html_doc_path("word_ieee_titlepage_icr.html")
  super
end


132
133
134
135
136
137
138
# File 'lib/isodoc/ieee/word_wp_cleanup.rb', line 132

def copyright_style(docxml)
  docxml.at("//div[@class = 'boilerplate-copyright']")&.xpath(".//p")
    &.each do |p|
    p["class"] ||= "CopyrightInformationPage"
  end
  feedback_table(docxml)
end

#default_file_locations(_options) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/isodoc/ieee/word_wp_convert.rb', line 14

def default_file_locations(_options)
  { wordstylesheet: html_doc_path("wordstyle_wp.scss"),
    standardstylesheet: html_doc_path("ieee_wp.scss"),
    header: html_doc_path("header_wp.html"),
    wordcoverpage: html_doc_path("word_ieee_titlepage_wp.html"),
    wordintropage: html_doc_path("word_ieee_intro_wp.html"),
    ulstyle: "l23", olstyle: "l16" }
end

#default_fonts(_options) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/isodoc/ieee/word_wp_convert.rb', line 23

def default_fonts(_options)
  { bodyfont: '"Calibri",sans-serif',
    headerfont: '"Arial Black",sans-serif',
    monospacefont: '"Courier New",monospace',
    normalfontsize: "11.0pt",
    footnotefontsize: "7.0pt",
    smallerfontsize: "10.0pt",
    monospacefontsize: "10.0pt" }
end

#feedback_table(docxml) ⇒ Object



111
112
113
114
115
116
117
118
119
# File 'lib/isodoc/ieee/word_wp_cleanup.rb', line 111

def feedback_table(docxml)
  docxml.at("//div[@class = 'boilerplate-copyright']")&.xpath(".//table")
    &.each do |t|
    t.xpath(".//tr").each do |tr|
      feedback_table1(tr)
    end
    t.replace(t.at(".//tbody").elements)
  end
end

#feedback_table1(trow) ⇒ Object



121
122
123
124
125
126
127
128
129
130
# File 'lib/isodoc/ieee/word_wp_cleanup.rb', line 121

def feedback_table1(trow)
  trow.name = "p"
  trow["class"] = "CopyrightInformationPage"
  trow["align"] = "left"
  trow.xpath("./td").each do |td|
    td.next_element and td << "<span style='mso-tab-count:1'> </span>"
    td.xpath("./p").each { |p| p.replace(p.children) }
    td.replace(td.children)
  end
end

#figure_attrs(node) ⇒ Object



59
60
61
62
# File 'lib/isodoc/ieee/word_wp_convert.rb', line 59

def figure_attrs(node)
  attr_code(id: node["id"], class: "figure",
            style: "#{keep_style(node)};text-align:center;")
end

#figure_parse1(node, out) ⇒ Object



99
100
101
102
103
104
105
106
# File 'lib/isodoc/ieee/word_wp_convert.rb', line 99

def figure_parse1(node, out)
  out.div **figure_attrs(node) do |div|
    figure_name_parse(node, div, node.at(ns("./name")))
    node.children.each do |n|
      parse(n, div) unless n.name == "name"
    end
  end
end

#headings_style(hdr, idx) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/isodoc/ieee/word_wp_cleanup.rb', line 40

def headings_style(hdr, idx)
  if hdr.at("./ancestor::div[@class = 'Annex']")
    headings_style_annex(hdr, idx)
  elsif hdr.at("./ancestor::div[@class = 'Section3' or " \
               "@class = 'WordSectionContents']")
    headings_style_preface(hdr, idx)
  else
    headings_style_body(hdr, idx)
  end
end

#headings_style_annex(hdr, idx) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/isodoc/ieee/word_wp_cleanup.rb', line 51

def headings_style_annex(hdr, idx)
  hdr.delete("class")
  if idx == 1
    hdr.next = BLUELINE
    hdr["style"] = "margin-left:0cm;#{hdr['style']}"
  else
    hdr["class"] = "Unnumberedheading"
  end
end

#headings_style_body(hdr, idx) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/isodoc/ieee/word_wp_cleanup.rb', line 66

def headings_style_body(hdr, idx)
  idx == 1 and hdr.name = "p"
  if hdr["class"] != stylesmap[:AbstractTitle]
    if idx == 1
      hdr["class"] = stylesmap["level#{idx}header".to_sym]
    else
      hdr["style"] = "mso-list:l22 level#{idx} lfo33;#{hdr['style']}"
    end
  end
end

#headings_style_preface(hdr, idx) ⇒ Object



61
62
63
64
# File 'lib/isodoc/ieee/word_wp_cleanup.rb', line 61

def headings_style_preface(hdr, idx)
  hdr.name = "p"
  hdr["class"] = stylesmap["level#{idx}frontmatter".to_sym]
end

#init_wp(options) ⇒ Object



12
# File 'lib/isodoc/ieee/word_wp_convert.rb', line 12

def init_wp(options); end

#insert_toc(intro, docxml, level) ⇒ Object



216
217
218
219
220
221
222
223
224
225
# File 'lib/isodoc/ieee/word_wp_cleanup.rb', line 216

def insert_toc(intro, docxml, level)
  toc = assemble_toc(docxml, level)
  if intro&.include?("WORDTOC")
    intro.sub("WORDTOC", toc)
  else
    source = docxml.at("//div[@class = 'TOC']") and
      source.children = toc
    intro
  end
end


140
141
142
143
144
145
146
147
# File 'lib/isodoc/ieee/word_wp_cleanup.rb', line 140

def legal_style(docxml)
  %w(disclaimers tm).each do |e|
    docxml.at("//div[@id = 'boilerplate-#{e}']")&.xpath(".//p")
      &.each do |p|
      p["class"] ||= "Disclaimertext"
    end
  end
end

#make_body3(body, docxml) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/isodoc/ieee/word_wp_convert.rb', line 40

def make_body3(body, docxml)
  body.div class: "WordSection3" do |div3|
    middle_title_ieee(docxml, div3)
    content(div3, docxml, ns(self.class::MAIN_ELEMENTS))
  end
  section_break(body)
  body.div class: "WordSection4" do |div3|
    backcover div3
    footnotes div3
    comments div3
  end
end

#middle_title_ieee(docxml, out) ⇒ Object



74
75
76
77
78
# File 'lib/isodoc/ieee/word_wp_convert.rb', line 74

def middle_title_ieee(docxml, out)
  super
  out << BLUELINE
  out.p
end

#officemember_style(docxml) ⇒ Object



153
154
155
156
157
158
# File 'lib/isodoc/ieee/word_wp_cleanup.rb', line 153

def officemember_style(docxml)
  docxml.xpath("//p[@type = 'officemember' or @type = 'officeorgmember']")
    .each do |p|
    p["class"] = stylesmap[:nameslist]
  end
end

#officer_style(docxml) ⇒ Object



149
150
151
# File 'lib/isodoc/ieee/word_wp_cleanup.rb', line 149

def officer_style(docxml)
  officemember_style(docxml)
end

#para_parse(node, out) ⇒ Object



68
69
70
71
72
# File 'lib/isodoc/ieee/word_wp_convert.rb', line 68

def para_parse(node, out)
  node["class"] == "zzSTDTitle1" and
    return middle_title_ieee(node.document.root, out)
  super
end

#stylesmapObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/isodoc/ieee/word_wp_cleanup.rb', line 4

def stylesmap
  {
    example: "IEEEStdsParagraph", # x
    MsoNormal: "MsoBodyText",
    NormRef: "MsoBodyText",
    Biblio: "References",
    figure: "MsoBodyText",
    formula: "IEEEStdsEquation", # x
    Sourcecode: "IEEEStdsComputerCode", # x
    TableTitle: "TableTitles",
    FigureTitle: "FigureHeadings",
    admonition: "IEEEStdsWarning", # x
    abstract: "Abstract",
    AbstractTitle: "Unnumberedheading",
    level1frontmatter: "Unnumberedheading",
    level2frontmatter: "IEEEStdsLevel2frontmatter", # x
    level3frontmatter: "IEEEStdsLevel3frontmatter", # x
    level1header: "IEEESectionHeader",
    level2header: "IEEEStdsLevel2Header", # x
    level3header: "IEEEStdsLevel3Header", # x
    level4header: "IEEEStdsLevel4Header", # x
    level5header: "IEEEStdsLevel5Header", # x
    level6header: "IEEEStdsLevel6Header", # x
    zzSTDTitle1: "Titleofdocument",
    tabledata_center: "IEEEStdsTableData-Center", # x
    tabledata_left: "Tablecelltext",
    table_head: "IEEEStdsTableLineHead", # x
    table_subhead: "IEEEStdsTableLineSubhead", # x
    table_columnhead: "Tablecolumnheader",
    nameslist: "IEEEnames",
    intro: "Intro",
  }
end

#table_cleanup(docxml) ⇒ Object



90
91
92
93
94
95
96
# File 'lib/isodoc/ieee/word_wp_cleanup.rb', line 90

def table_cleanup(docxml)
  super
  docxml.xpath("//div[@class = 'table_container']//div[@class = 'Note']//p")
    .each do |n|
    n["class"] = "Tablenotes"
  end
end

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



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/isodoc/ieee/word_wp_cleanup.rb', line 77

def toWord(result, filename, dir, header)
  ::Html2Doc::Ieee_Wp.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

#variant_title(node, out) ⇒ Object



112
113
114
115
116
117
118
# File 'lib/isodoc/ieee/word_wp_convert.rb', line 112

def variant_title(node, out)
  node.parent.name == "annex" or return super
  out.p { |e| e << "&#xa0;" }
  out.p **attr_code(class: "Unnumberedheading") do |p|
    node.children.each { |c| parse(c, p) }
  end
end