Class: IsoDoc::XslfoPdfConvert
- 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", pdfstylesheet: "--xsl-file", pdfstylesheet_override: "--xsl-file-override", pdfencryptmetadata: "--encrypt-metadata" }.freeze
- MN2PDF_DEFAULT_ARGS =
{ "--syntax-highlight": nil }.freeze
Constants inherited from Convert
Constants included from Function::Utils
Function::Utils::CLAUSE_ANCESTOR, Function::Utils::DOCTYPE_HDR, Function::Utils::HUGESTRICT, Function::Utils::LABELLED_ANCESTOR_ELEMENTS, Function::Utils::NOTE_CONTAINER_ANCESTOR
Constants included from Function::ToWordHtml
Function::ToWordHtml::TOP_ELEMENTS
Constants included from Function::Table
Constants included from Function::Section
Function::Section::TERM_CLAUSE
Constants included from Function::Lists
Constants included from Function::Inline
Function::Inline::MATHML, Function::Inline::SPAN_UNWRAP_CLASSES
Constants included from Function::Cleanup
Function::Cleanup::TABLENOTE_CSS
Constants included from Function::Blocks
Function::Blocks::EXAMPLE_TBL_ATTR, Function::Blocks::EXAMPLE_TD_ATTR
Instance Attribute Summary
Attributes inherited from Convert
#bibrender, #doctype, #i18n, #localdir, #meta, #options, #reqt_models, #requirements_processor, #tempfile_cache, #wordcoverpage, #wordintropage, #xrefs
Instance Method Summary collapse
- #baseassetpath(filename) ⇒ Object
-
#convert(input_fname, file = nil, debug = false, output_fname = nil) ⇒ Object
input_file: keep-alive tempfile.
- #convert_prep(input_fname, file, debug) ⇒ Object
- #extract_cmd_options(options) ⇒ Object
-
#initialize(options) ⇒ XslfoPdfConvert
constructor
A new instance of XslfoPdfConvert.
- #input_xml_path(input_filename, xml_file, debug) ⇒ Object
- #output_filename(input_fname) ⇒ Object
- #pdf_options(_docxml, filename) ⇒ Object
- #pdf_stylesheet(_docxml) ⇒ Object
- #tmpimagedir_suffix ⇒ Object
- #xref_parse(node, out) ⇒ Object
Methods inherited from Convert
#agency?, #bibrenderer, #compile_scss, #connectives_spans, #convert1, #convert1_namespaces, #convert_i18n_init, #convert_i18n_init1, #convert_init, #convert_scss, #default_file_locations, #default_fonts, #docid_all_parts, #docid_l10n, #docid_prefix, #fonts_options, #generate_css, #html_doc_path, #i18n_init, #init_arrangement, #init_covers, #init_fonts, #init_i18n, #init_locations, #init_processing, #init_rendering, #init_stylesheets, #init_toc, #l10n, #load_scss_paths, #localpath, #metadata_init, #middle_clause, #omit_docid_prefix, #options_preprocess, #populate_css, #precompiled_style_or_original, #preprocess_css, #scss_fontheader, #swap_renderer, #target_pdf, #tmpfilesdir_suffix, #toc_init, #write_css, #xref_init
Methods included from ClassUtils
#case_strict, #case_strict1, #case_with_markup, #date_range, #liquid, #nearest_block_parent, #ns, #start_of_sentence, #to_xml
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, #imgfile_suffix, #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, #to_xml
Methods included from Function::ToWordHtml
#body_attr, #boilerplate, #content, #cross_align, #define_head, #info, #init_dir, #init_file, #make_body, #make_body1, #make_body2, #make_body3, #note?, #parse, #rel_tmpimagedir, #tmpimagedir, #top_element_render
Methods included from Function::Terms
#admitted_term_parse, #definition_parse, #deprecated_term_parse, #modification_parse, #semx_admitted_term_parse, #semx_deprecated_term_parse, #semx_related_parse, #semx_term_parse, #semx_termref_parse, #term_parse, #termdef_parse, #termdocsource_parse, #termdomain_parse, #termnote_p_class, #termnote_parse, #termnote_parse1, #termref_parse
Methods included from Function::Table
#bordered_table_style, #colgroup, #make_tr_attr, #make_tr_attr_style, #table_attrs, #table_attrs_style, #table_bordered?, #table_parse, #table_parse_core, #table_parse_tail, #table_title_parse, #tbody_parse, #tcaption, #tfoot_parse, #thead_parse, #tr_parse
Methods included from Function::Section
#abstract, #acknowledgements, #annex, #annex_attrs, #annex_name, #appendix_parse, #clause, #clause?, #clause_attrs, #clause_name, #clause_parse, #clause_parse_subtitle, #clause_parse_title, #clause_parse_title1, #clause_title_depth, #clausedelim, #clausedelimspace, #colophon, #copyright_parse, #executivesummary, #feedback_parse, #footnotes, #foreword, #freestanding_title, #indexsect, #inline_header_title, #introduction, #legal_parse, #license_parse, #preface, #preface_attrs, #preface_block, #preface_normal, #scope, #sections_names, #single_term_clause?, #symbols_abbrevs, #symbols_parse, #table_of_contents, #terms_defs, #terms_parse, #variant_title
Methods included from Function::References
#bibitem_entry, #biblio_list, #bibliography, #bibliography_parse, #bibliography_xpath, #iso_bibitem_entry_attrs, #norm_ref, #norm_ref_xpath, #reference_format
Methods included from Function::Lists
#dl_attrs, #dl_parse, #dl_parse1, #dl_parse_notes, #dt_dd?, #dt_parse, #li_checkbox, #li_parse, #list_title_parse, #ol_attrs, #ol_parse, #ol_style, #ul_attrs, #ul_parse
Methods included from Function::Footnotes
#fmt_annotation_body_parse, #footnote_parse, #get_table_ancestor_id, #make_table_footnote_link, #table_footnote?, #table_footnote_parse, #update_table_fn_body_ref
Methods included from Function::Inline
#add_parse, #amend_parse, #annotation_note_parse, #asciimath_parse, #author_parse, #bookmark_parse, #br_parse, #callout_parse, #children_parse, #concept_parse, #date_parse, #del_parse, #em_parse, #eref_parse, #erefstack_parse, #error_parse, #floating_title_parse, #fmt_annotation_end_parse, #fmt_annotation_start_parse, #fmt_concept_parse, #fmt_date_parse, #fmt_fn_label_parse, #fmt_footnote_container_parse, #fmt_identifier_parse, #fmt_name_parse, #hr_parse, #identifier_parse, #image_body_parse, #image_parse, #image_title_parse, #index_parse, #index_xref_parse, #keyword_parse, #latexmath_parse, #link_parse, #location_parse, #mathml_parse, #name_parse, #no_locality_parse, #origin_parse, #page_break, #pagebreak_parse, #rb_parse, #rt_parse, #ruby_parse, #section_break, #semx_definition_parse, #semx_eref_parse, #semx_link_parse, #semx_origin_parse, #semx_parse, #semx_source_parse, #semx_sourcecode_parse, #semx_stem_parse, #semx_xref_parse, #smallcap_parse, #span_parse, #stem_parse, #stem_parse1, #strike_parse, #strong_parse, #sub_parse, #suffix_url, #sup_parse, #svgmap_parse, #termrefelem_parse, #text_parse, #tt_parse, #underline_parse, #xref_label_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, #cleanup, #example_cleanup, #figure_cleanup, #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_get_or_make_tfoot, #table_note_cleanup, #textcleanup
Methods included from Function::Blocks
#admonition_attrs, #admonition_class, #admonition_name, #admonition_name_in_first_para, #admonition_name_para_delim, #admonition_name_parse, #admonition_p_parse, #admonition_parse, #admonition_parse1, #annotation_parse, #attribution_parse, #block_body_first_elem, #columnbreak_parse, #cross_align_parse, #div_parse, #example_div_attr, #example_div_parse, #example_label, #example_parse, #example_table_attr, #example_table_parse, #figure_attrs, #figure_name_parse, #figure_parse, #figure_parse1, #fmt_fn_body_parse, #formula_attrs, #formula_parse, #formula_parse1, #keep_style, #note_attrs, #note_p_class, #note_p_parse, #note_parse, #note_parse1, #para_attrs, #para_class, #para_parse, #passthrough_parse, #permission_parse, #pre_parse, #pseudocode_attrs, #pseudocode_parse, #quote_parse, #recommendation_name, #recommendation_parse, #recommendation_parse1, #reqt_attrs, #requirement_parse, #source_parse, #sourcecode_attrs, #sourcecode_name_parse, #sourcecode_parse, #sourcecode_parse1, #starts_with_para?, #svg_parse, #toc_parse
Constructor Details
#initialize(options) ⇒ XslfoPdfConvert
Returns a new instance of XslfoPdfConvert.
21 22 23 24 25 26 |
# File 'lib/isodoc/xslfo_convert.rb', line 21 def initialize() @format = :pdf @suffix = "pdf" @pdf_cmd_options = () super end |
Instance Method Details
#baseassetpath(filename) ⇒ Object
44 45 46 47 |
# File 'lib/isodoc/xslfo_convert.rb', line 44 def baseassetpath(filename) !@baseassetpath && filename and @baseassetpath = File.(Pathname.new(filename).parent.to_s) end |
#convert(input_fname, file = nil, debug = false, output_fname = nil) ⇒ Object
input_file: keep-alive tempfile
79 80 81 82 83 84 85 86 87 |
# File 'lib/isodoc/xslfo_convert.rb', line 79 def convert(input_fname, file = nil, debug = false, output_fname = nil) _, docxml, filename = convert_prep(input_fname, file, debug) opts = (docxml, input_fname) ::Metanorma::Output::XslfoPdf.new.convert( filename, output_fname || output_filename(input_fname), @xsl, opts ) end |
#convert_prep(input_fname, file, debug) ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'lib/isodoc/xslfo_convert.rb', line 89 def convert_prep(input_fname, file, debug) file ||= File.read(input_fname, encoding: "utf-8") _, docxml, filename = input_xml_path(input_fname, file, debug) @xsl = pdf_stylesheet(docxml) or return Pathname.new(@xsl).absolute? or @xsl = File.join(@libdir, @xsl) @doctype = docxml.at(ns("//bibdata/ext/doctype"))&.text [file, docxml, filename] end |
#extract_cmd_options(options) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/isodoc/xslfo_convert.rb', line 28 def () ret = MN2PDF_DEFAULT_ARGS.dup MN2PDF_OPTIONS.each do |key, opt| value = [key] and ret[opt] = value end ret end |
#input_xml_path(input_filename, xml_file, debug) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/isodoc/xslfo_convert.rb', line 108 def input_xml_path(input_filename, xml_file, debug) docxml, filename, dir = convert_init(xml_file, input_filename, debug) temp_file = Tempfile.open([File.basename(filename), ".xml"], mode: File::BINARY | File::SHARE_DELETE, encoding: "utf-8") temp_file.write docxml temp_file.flush @tempfile_cache << temp_file # Add to cache to prevent garbage collection FileUtils.rm_rf dir [temp_file, docxml, temp_file.path] end |
#output_filename(input_fname) ⇒ Object
98 99 100 101 102 |
# File 'lib/isodoc/xslfo_convert.rb', line 98 def output_filename(input_fname) out = input_fname.sub(/\.presentation\.xml$/, ".xml") File.join(File.dirname(input_fname), "#{File.basename(out, '.*')}.#{@suffix}") end |
#pdf_options(_docxml, filename) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/isodoc/xslfo_convert.rb', line 49 def (_docxml, filename) baseassetpath(filename) 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.tr(",", " ") @baseassetpath and ret["--param baseassetpath="] = @baseassetpath ret = ret.merge(@pdf_cmd_options) %w(--xsl-file --xsl-file-override).each do |x| if ret[x] ret[x] = if File.absolute_path?(ret[x]) Pathname.new(ret[x]).to_s else Pathname.new( File.(File.join(@baseassetpath, ret[x])), ).to_s end end end if ret["--xsl-file"] @xsl = ret["--xsl-file"] ret.delete("--xsl-file") end ret end |
#pdf_stylesheet(_docxml) ⇒ Object
40 41 42 |
# File 'lib/isodoc/xslfo_convert.rb', line 40 def pdf_stylesheet(_docxml) nil end |
#tmpimagedir_suffix ⇒ Object
36 37 38 |
# File 'lib/isodoc/xslfo_convert.rb', line 36 def tmpimagedir_suffix "_#{SecureRandom.hex(8)}_pdfimages" end |
#xref_parse(node, out) ⇒ Object
104 105 106 |
# File 'lib/isodoc/xslfo_convert.rb', line 104 def xref_parse(node, out) out.a(href: target_pdf(node)) { |l| l << get_linkend(node) } end |