Class: IsoDoc::XslfoPdfConvert

Inherits:
Convert show all
Defined in:
lib/isodoc/xslfo_convert.rb

Constant Summary collapse

MN_OPTIONS_KEY =
:mn2pdf
MN2PDF_FONT_MANIFEST =
:font_manifest
MN2PDF_OPTIONS =
{ pdfencryptionlength: "--encryption-length",
pdfownerpassword: "--owner-password",
pdfuserpassword: "--user-password",
pdfallowprint: "--allow-print",
pdfallowcopycontent: "--allow-copy-content",
pdfalloweditcontent: "--allow-edit-content",
pdfalloweditannotations: "--allow-edit-annotations",
pdfallowfillinforms: "--allow-fill-in-forms",
pdfallowaccesscontent: "--allow-access-content",
pdfallowassembledocument: "--allow-assemble-document",
pdfallowprinthq: "--allow-print-hq",
pdfencryptmetadata: "--encrypt-metadata" }.freeze
MN2PDF_DEFAULT_ARGS =
{ "--syntax-highlight": nil }.freeze

Constants included from Function::Utils

Function::Utils::CLAUSE_ANCESTOR, Function::Utils::DOCTYPE_HDR, Function::Utils::NOTE_CONTAINER_ANCESTOR

Constants included from Function::Table

Function::Table::SW

Constants included from Function::Section

Function::Section::TERM_CLAUSE

Constants included from Function::Lists

Function::Lists::OL_STYLE

Constants included from Function::Inline

Function::Inline::MATHML

Constants included from Function::Cleanup

Function::Cleanup::FIGURE_WITH_FOOTNOTES

Constants included from Function::Blocks

Function::Blocks::EXAMPLE_TBL_ATTR, Function::Blocks::EXAMPLE_TD_ATTR

Instance Attribute Summary

Attributes inherited from Convert

#i18n, #meta, #options, #reqt_models, #requirements_processor, #xrefs

Instance Method Summary collapse

Methods inherited from Convert

#bibitem_lookup, #convert1, #convert_i18n_init, #convert_init, #convert_scss, #default_file_locations, #default_fonts, #fonts_options, #generate_css, #html_doc_path, #i18n_init, #init_covers, #init_fonts, #init_i18n, #init_locations, #init_processing, #init_rendering, #init_stylesheets, #init_toc, #l10n, #localpath, #metadata_init, #middle_clause, #options_preprocess, #populate_css, #precompiled_style_or_original, #scss_fontheader, #target_pdf, #tmpfilesdir_suffix, #xref_init

Methods included from ClassUtils

#case_strict, #case_strict1, #case_with_markup, #date_range, #liquid, #nearest_block_parent, #ns, #start_of_sentence

Methods included from Function::Utils

#attr_code, #cleanup_entities, #date_range, #emf?, #empty2nil, #eps?, #external_path, #extract_delims, #from_xhtml, #get_clause_id, #get_note_container_id, #header_strip, #header_strip_elem?, #image_localfile, #insert_tab, #labelled_ancestor, #liquid, #noko, #ns, #numeric_escapes, #populate_template, #save_dataimage, #save_svg, #sentence_join, #start_of_sentence, #to_xhtml, #to_xhtml_fragment, #to_xhtml_prep

Methods included from Function::ToWordHtml

#body_attr, #boilerplate, #define_head, #in_sourcecode, #info, #init_dir, #init_file, #make_body, #make_body1, #make_body2, #make_body3, #middle, #note?, #parse, #rel_tmpimagedir, #set_termdomain, #tmpimagedir

Methods included from Function::Terms

#admitted_term_parse, #definition_parse, #deprecated_term_parse, #modification_parse, #para_then_remainder, #term_parse, #termdef_parse, #termdocsource_parse, #termnote_delim, #termnote_parse, #termref_parse

Methods included from Function::Table

#colgroup, #make_tr_attr, #table_attrs, #table_parse, #table_title_parse, #tbody_parse, #tcaption, #tfoot_parse, #thead_parse, #tr_parse

Methods included from Function::Section

#abstract, #acknowledgements, #annex, #annex_attrs, #annex_name, #clause, #clause_attrs, #clause_name, #clause_parse, #clause_parse_subtitle, #clause_parse_title, #clause_parse_title1, #clause_title_depth, #clausedelim, #clausedelimspace, #copyright_parse, #feedback_parse, #foreword, #inline_header_title, #introduction, #is_clause?, #legal_parse, #license_parse, #preceding_floating_titles, #preface, #preface_block, #scope, #single_term_clause?, #symbols_abbrevs, #symbols_parse, #terms_defs, #terms_parse, #variant_title

Methods included from Function::References

#bibitem_ref_code, #biblio_list, #bibliography, #bibliography_parse, #bibliography_xpath, #bracket_if_num, #date_note_process, #docid_l10n, #docid_prefix, #implicit_reference, #iso_bibitem_entry_attrs, #nonstd_bibitem, #norm_ref, #norm_ref_xpath, #omit_docid_prefix, #pref_ref_code, #prefix_bracketed_ref, #ref_entry_code, #reference_format, #render_identifier, #standard?, #std_bibitem_entry, #unbracket, #unbracket1

Methods included from Function::Lists

#dl_attrs, #dl_parse, #dl_parse1, #dt_dd?, #dt_parse, #li_parse, #list_title_parse, #ol_attrs, #ol_depth, #ol_parse, #ol_style, #ul_attrs, #ul_parse

Methods included from Function::Inline

#add_parse, #asciimath_parse, #bookmark_parse, #br_parse, #callout_parse, #del_parse, #em_parse, #eref_parse, #eref_target, #eref_url, #error_parse, #hr_parse, #image_parse, #image_title_parse, #index_parse, #index_xref_parse, #keyword_parse, #latexmath_parse, #link_parse, #location_parse, #mathml_parse, #no_locality_parse, #origin_parse, #page_break, #pagebreak_parse, #section_break, #smallcap_parse, #span_parse, #stem_parse, #strike_parse, #strong_parse, #sub_parse, #suffix_url, #sup_parse, #termrefelem_parse, #text_parse, #tt_parse, #underline_parse

Methods included from Function::Form

#form_parse, #input_parse, #label_parse, #option_parse, #select_parse, #text_input, #textarea_parse

Methods included from Function::Cleanup

#admonition_cleanup, #break_up_long_strings, #break_up_long_strings1, #cleanup, #example_cleanup, #figure_aside_process, #figure_cleanup, #figure_get_or_make_dl, #footnote_cleanup, #footnote_reference_format, #inline_header_cleanup, #merge_fnref_into_fn_text, #new_fullcolspan_row, #passthrough_cleanup, #remove_bottom_border, #symbols_cleanup, #table_cleanup, #table_footnote_cleanup, #table_footnote_cleanup_propagate, #table_footnote_reference_format, #table_get_or_make_tfoot, #table_long_strings_cleanup, #table_note_cleanup, #textcleanup

Methods included from Function::Blocks

#admonition_attrs, #admonition_class, #admonition_name, #admonition_name_parse, #admonition_parse, #annotation_parse, #div_parse, #example_div_attr, #example_div_parse, #example_label, #example_parse, #example_table_attr, #example_table_parse, #figure_attrs, #figure_key, #figure_name_parse, #figure_parse, #figure_parse1, #formula_attrs, #formula_parse, #formula_parse1, #formula_where, #keep_style, #middle_admonitions, #middle_title, #note_attrs, #note_delim, #note_p_parse, #note_parse, #note_parse1, #para_attrs, #para_class, #para_parse, #passthrough_parse, #permission_parse, #pre_parse, #pseudocode_attrs, #pseudocode_parse, #quote_attribution, #quote_parse, #recommendation_name, #recommendation_parse, #recommendation_parse1, #reqt_attrs, #requirement_parse, #sourcecode_attrs, #sourcecode_name_parse, #sourcecode_parse, #svg_parse, #toc_parse

Constructor Details

#initialize(options) ⇒ XslfoPdfConvert

Returns a new instance of XslfoPdfConvert.



19
20
21
22
23
24
# File 'lib/isodoc/xslfo_convert.rb', line 19

def initialize(options)
  @format = :pdf
  @suffix = "pdf"
  @pdf_cmd_options = extract_cmd_options(options)
  super
end

Instance Method Details

#convert(input_filename, file = nil, debug = false, output_filename = nil) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/isodoc/xslfo_convert.rb', line 54

def convert(input_filename, file = nil, debug = false,
            output_filename = nil)
  file = File.read(input_filename, encoding: "utf-8") if file.nil?
  input_filename, docxml, filename = input_xml_path(input_filename,
                                                    file, debug)
  ::Metanorma::Output::XslfoPdf.new.convert(
    input_filename,
    output_filename || "#{filename}.#{@suffix}",
    File.join(@libdir, pdf_stylesheet(docxml)),
    pdf_options(docxml),
  )
end

#extract_cmd_options(options) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/isodoc/xslfo_convert.rb', line 26

def extract_cmd_options(options)
  ret = MN2PDF_DEFAULT_ARGS.dup
  MN2PDF_OPTIONS.each do |key, opt|
    value = options[key] and ret[opt] = value
  end
  ret
end

#input_xml_path(input_filename, xml_file, debug) ⇒ Object



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

def input_xml_path(input_filename, xml_file, debug)
  docxml, filename, dir = convert_init(xml_file, input_filename, debug)
  unless /\.xml$/.match?(input_filename)
    input_filename = Tempfile.open([filename, ".xml"],
                                   encoding: "utf-8") do |f|
      f.write xml_file
      f.path
    end
  end
  FileUtils.rm_rf dir

  [input_filename, docxml, filename]
end

#pdf_options(_docxml) ⇒ Object



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

def pdf_options(_docxml)
  ret = {}
  font_manifest = @options.dig(MN_OPTIONS_KEY, MN2PDF_FONT_MANIFEST) and
    ret[MN2PDF_FONT_MANIFEST] = font_manifest
  @aligncrosselements && !@aligncrosselements.empty? and
    ret["--param align-cross-elements="] =
      @aligncrosselements.gsub(/,/, " ")
  @baseassetpath and
    ret["--param baseassetpath="] = @baseassetpath
  ret.merge(@pdf_cmd_options)
end

#pdf_stylesheet(_docxml) ⇒ Object



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

def pdf_stylesheet(_docxml)
  nil
end

#tmpimagedir_suffixObject



34
35
36
# File 'lib/isodoc/xslfo_convert.rb', line 34

def tmpimagedir_suffix
  "_#{SecureRandom.hex(8)}_pdfimages"
end

#xref_parse(node, out) ⇒ Object



67
68
69
# File 'lib/isodoc/xslfo_convert.rb', line 67

def xref_parse(node, out)
  out.a(**{ href: target_pdf(node) }) { |l| l << get_linkend(node) }
end