class IsoDoc::Mpfd::PdfConvert

A {Converter} implementation that generates PDF HTML output, and a document schema encapsulation of the document for validation

Constants

FRONT_CLAUSE
TERM_CLAUSE

Public Class Methods

new(options) click to toggle source
Calls superclass method
# File lib/isodoc/mpfd/pdf_convert.rb, line 13
def initialize(options)
  super
  @htmlstylesheet = generate_css(rsd_html_path("htmlstyle.scss"), true, default_fonts(options))
  @htmlcoverpage = rsd_html_path("html_rsd_titlepage.html")
  @htmlintropage = rsd_html_path("html_rsd_intro.html")
  @scripts = rsd_html_path("scripts.html")
  system "cp #{rsd_html_path('logo.jpg')} logo.jpg"
  system "cp #{rsd_html_path('mpfa-logo-no-text@4x.png')} mpfa-logo-no-text@4x.png"
  @files_to_delete << "logo.jpg"
  @files_to_delete << "mpfa-logo-no-text@4x.png"
end

Public Instance Methods

annex_name(annex, name, div) click to toggle source
# File lib/isodoc/mpfd/pdf_convert.rb, line 71
def annex_name(annex, name, div)
  div.h1 **{ class: "Annex" } do |t|
    t << "#{get_anchors[annex['id']][:label]} "
    t << "<b>#{name.text}</b>"
  end
end
annex_name_lbl(clause, num) click to toggle source
# File lib/isodoc/mpfd/pdf_convert.rb, line 78
def annex_name_lbl(clause, num)
  obl = l10n("(#{@inform_annex_lbl})")
  obl = l10n("(#{@norm_annex_lbl})") if clause["obligation"] == "normative"
  l10n("<b>#{@annex_lbl} #{num}</b> #{obl}")
end
annex_names(clause, num) click to toggle source
# File lib/isodoc/mpfd/pdf_convert.rb, line 316
def annex_names(clause, num)
  @anchors[clause["id"]] = { label: annex_name_lbl(clause, num),
                             xref: "#{@annex_lbl} #{num}", level: 1 }
  i = 0
  clause.xpath(ns("./clause")).each do |c|
    i = annex_naming(c, num, 1, i)
  end
  hierarchical_asset_names(clause, num)
end
annex_names1(clause, num, level) click to toggle source
# File lib/isodoc/mpfd/pdf_convert.rb, line 326
def annex_names1(clause, num, level)
  @anchors[clause["id"]] = { label: num, xref: "#{@annex_lbl} #{num}",
                             level: level }
  i = 0
  clause.xpath(ns("./clause")).each do |c|
    i = annex_naming(c, num, level, i)
  end
end
annex_naming(c, num, lvl, i) click to toggle source
# File lib/isodoc/mpfd/pdf_convert.rb, line 307
def annex_naming(c, num, lvl, i)
  if c["guidance"] then annex_names1(c, "#{num}E", lvl + 1)
  else
    i+= 1
    annex_names1(c, "#{num}.#{i}", lvl + 1)
  end
  i
end
clause(isoxml, out) click to toggle source
# File lib/isodoc/mpfd/pdf_convert.rb, line 335
def clause(isoxml, out)
  isoxml.xpath(ns(MIDDLE_CLAUSE)).each do |c|
    out.div **attr_code(id: c["id"]) do |s|
      clause_name(get_anchors[c['id']][:label],
                  c&.at(ns("./title"))&.content, s, class: c["container"] ? "containerhdr" : nil )
      c.elements.reject { |c1| c1.name == "title" }.each do |c1|
        parse(c1, s)
      end
    end
  end
end
clause_names(docxml, sect_num) click to toggle source
# File lib/isodoc/mpfd/pdf_convert.rb, line 259
     def clause_names(docxml, sect_num)
  q = "//clause[parent::sections]"
  @topnum = nil
  lvl = 0
  docxml.xpath(ns(q)).each do |c|
    container_names(c, 0)
    sect_num, lvl = sect_names(c, nil, sect_num, 0, lvl)
  end
end
clause_parse_title(node, div, c1, out) click to toggle source
# File lib/isodoc/mpfd/pdf_convert.rb, line 347
def clause_parse_title(node, div, c1, out)
  if node["inline-header"] == "true"
    inline_header_title(out, node, c1)
  else
    attrs = { class: node["container"] ? "containerhdr" : nil }
    div.send "h#{get_anchors[node['id']][:level]}", **attr_code(attrs) do |h|
      lbl = get_anchors[node['id']][:label]
      h << "#{lbl}. " if lbl
      c1&.children&.each { |c2| parse(c2, h) }
    end
  end
end
container_names(clause, lvl) click to toggle source
# File lib/isodoc/mpfd/pdf_convert.rb, line 269
def container_names(clause, lvl)
  if clause["container"]
    @anchors[clause["id"]] =
      { label: nil, xref: clause.at(ns("./title"))&.text, level: lvl+1 }
  end
  clause.xpath(ns("./clause | ./term  | ./terms | "\
                  "./definitions")).each do |c|
    container_names(c, clause["container"] ? lvl+1 : lvl)
  end
end
default_fonts(options) click to toggle source
# File lib/isodoc/mpfd/pdf_convert.rb, line 25
def default_fonts(options)
  b = options[:bodyfont] ||
    (options[:script] == "Hans" ? '"SimSun",serif' :
     '"Overpass",sans-serif')
  h = options[:headerfont] ||
    (options[:script] == "Hans" ? '"SimHei",sans-serif' :
     '"Overpass",sans-serif')
  m = options[:monospacefont] || '"Space Mono",monospace'
  "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n"
end
error_parse(node, out) click to toggle source
Calls superclass method
# File lib/isodoc/mpfd/pdf_convert.rb, line 101
def error_parse(node, out)
  # catch elements not defined in ISO
  case node.name
  when "pre"
    pre_parse(node, out)
  when "keyword"
    out.span node.text, **{ class: "keyword" }
  else
    super
  end
end
fileloc(loc) click to toggle source
# File lib/isodoc/mpfd/pdf_convert.rb, line 113
def fileloc(loc)
  File.join(File.dirname(__FILE__), loc)
end
html_head() click to toggle source
# File lib/isodoc/mpfd/pdf_convert.rb, line 40
      def html_head()
        <<~HEAD.freeze
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

    <!--TOC script import-->
    <script type="text/javascript"  src="https://cdn.rawgit.com/jgallen23/toc/0.3.2/dist/toc.min.js"></script>

    <!--Google fonts-->
    <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i|Space+Mono:400,700" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Overpass:300,300i,600,900" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Titillium+Web:400,400i,700,700i" rel="stylesheet">
    <!--Font awesome import for the link icon-->
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/solid.css" integrity="sha384-v2Tw72dyUXeU3y4aM2Y0tBJQkGfplr39mxZqlTBDUZAb9BGoC40+rdFCG0m10lXk" crossorigin="anonymous">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/fontawesome.css" integrity="sha384-q3jl8XQu1OpdLgGFvNRnPdj5VIlCvgsDQTQB6owSOHWlAurxul7f+JpUOVdAiJ5P" crossorigin="anonymous">
<style class="anchorjs"></style>
        HEAD
      end
html_toc(docxml) click to toggle source
# File lib/isodoc/mpfd/pdf_convert.rb, line 67
def html_toc(docxml)
  docxml
end
i18n_init(lang, script) click to toggle source
Calls superclass method
# File lib/isodoc/mpfd/pdf_convert.rb, line 96
def i18n_init(lang, script)
  super
  @annex_lbl = "Appendix"
end
info(isoxml, out) click to toggle source
Calls superclass method
# File lib/isodoc/mpfd/pdf_convert.rb, line 117
def info(isoxml, out)
  @meta.security isoxml, out
  super
end
initial_anchor_names(d) click to toggle source
# File lib/isodoc/mpfd/pdf_convert.rb, line 240
def initial_anchor_names(d)
  #preface_names(d.at(ns("//foreword")))
  #preface_names(d.at(ns("//introduction")))
  #preface_names(d.at(ns("//preface/terms | "\
                        #"//preface/clause[descendant::terms]")))
  d.xpath(ns(FRONT_CLAUSE)).each do |c|
    preface_names(c)
    sequential_asset_names(c)
  end
  middle_section_asset_names(d)
  clause_names(d, 0)
  termnote_anchor_names(d)
  termexample_anchor_names(d)
end
make_body(xml, docxml) click to toggle source
# File lib/isodoc/mpfd/pdf_convert.rb, line 58
def make_body(xml, docxml)
  body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72", "xml:lang": "EN-US", class: "container" }
  xml.body **body_attr do |body|
    make_body1(body, docxml)
    make_body2(body, docxml)
    make_body3(body, docxml)
  end
end
make_body3(body, docxml) click to toggle source
# File lib/isodoc/mpfd/pdf_convert.rb, line 219
def make_body3(body, docxml)
  body.div **{ class: "main-section" } do |div3|
    preface docxml, div3
    middle docxml, div3
    footnotes div3
    comments div3
  end
end
metadata_init(lang, script, labels) click to toggle source
# File lib/isodoc/mpfd/pdf_convert.rb, line 36
def metadata_init(lang, script, labels)
  @meta = Metadata.new(lang, script, labels)
end
middle(isoxml, out) click to toggle source
# File lib/isodoc/mpfd/pdf_convert.rb, line 228
def middle(isoxml, out)
  middle_title(out)
  clause isoxml, out
  annex isoxml, out
  bibliography isoxml, out
end
ol_depth(node) click to toggle source
# File lib/isodoc/mpfd/pdf_convert.rb, line 360
def ol_depth(node)
  ol_style(node["type"])
end
pre_parse(node, out) click to toggle source
# File lib/isodoc/mpfd/pdf_convert.rb, line 84
def pre_parse(node, out)
  out.pre node.text # content.gsub(/</, "&lt;").gsub(/>/, "&gt;")
end
preface(isoxml, out) click to toggle source

FRONT_CLAUSE = “//clause | //terms[parent::preface]”.freeze

# File lib/isodoc/mpfd/pdf_convert.rb, line 204
def preface(isoxml, out)
  isoxml.xpath(ns(FRONT_CLAUSE)).each do |c|
    if c.name == "terms" then  terms_defs isoxml, out, 0
    else
      out.div **attr_code(id: c["id"]) do |s|
        clause_name(get_anchors[c['id']][:label],
                    c&.at(ns("./title"))&.content, s, nil)
        c.elements.reject { |c1| c1.name == "title" }.each do |c1|
          parse(c1, s)
        end
      end
    end
  end
end
rsd_html_path(file) click to toggle source
# File lib/isodoc/mpfd/pdf_convert.rb, line 9
def rsd_html_path(file)
  File.join(File.dirname(__FILE__), File.join("html", file))
end
sect_names(clause, num, i, lvl, prev_lvl) click to toggle source
# File lib/isodoc/mpfd/pdf_convert.rb, line 280
def sect_names(clause, num, i, lvl, prev_lvl)
  return i if clause.nil?
  curr = i
  if clause["container"]
    retlvl = lvl+1
  else
    retlvl = lvl
    i+=1
    curr = i
    name = num.nil? ? i.to_s : "#{num}.#{i}"
    @anchors[clause["id"]] = { label: name, xref: l10n("#{@clause_lbl} #{name}"), level: lvl+1 }
  end
  prev = lvl
  j = 0
  clause.xpath(ns("./clause | ./term  | ./terms | "\
                  "./definitions")).each do |c|
    if clause["container"]
      i, lvl = sect_names(c, num, i, lvl, lvl)
    else
      j, prev = sect_names(c, name, j, lvl+1, prev)
    end
  end
  i = j if j >0
  i = curr if lvl < prev
  [i, prev]
end
term_defs_boilerplate(div, source, term, preface) click to toggle source
# File lib/isodoc/mpfd/pdf_convert.rb, line 88
def term_defs_boilerplate(div, source, term, preface)
  if source.empty? && term.nil?
    div << @no_terms_boilerplate
  else
    div << term_defs_boilerplate_cont(source, term)
  end
end
termdef_parse(node, out) click to toggle source
# File lib/isodoc/mpfd/pdf_convert.rb, line 235
def termdef_parse(node, out)
  set_termdomain("")
  node.children.each { |n| parse(n, out) }
end
terms_defs(isoxml, out, num) click to toggle source
# File lib/isodoc/mpfd/pdf_convert.rb, line 190
def terms_defs(isoxml, out, num)
 f = isoxml.at(ns(TERM_CLAUSE)) or return num
 out.div **attr_code(id: f["id"]) do |div|
   clause_name(nil, terms_defs_title(f), div, nil)
   f.elements.each do |e|
     parse(e, div) unless %w{title source}.include? e.name
   end
 end
 num
end
terms_defs_title(f) click to toggle source
# File lib/isodoc/mpfd/pdf_convert.rb, line 182
      def terms_defs_title(f)
  return f&.at(ns("./title"))&.content
end