Sha256: 6a601217f73120f972ee3c9cdf51b7d881771064b165236c88ea10fb9ffbddca

Contents?: true

Size: 1.86 KB

Versions: 5

Compression:

Stored size: 1.86 KB

Contents

require "metanorma"

module IsoDoc
  class XslfoPdfConvert < ::IsoDoc::Convert
    MN2PDF_OPTIONS = :mn2pdf
    MN2PDF_FONT_MANIFEST = :font_manifest

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

    def tmpimagedir_suffix
      "_pdfimages"
    end

    def pdf_stylesheet(_docxml)
      nil
    end

    def pdf_options(_docxml)
      ret = {}
      font_manifest = @options.dig(MN2PDF_OPTIONS,
                                   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
    end

    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

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

    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
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
isodoc-1.8.2.2 lib/isodoc/xslfo_convert.rb
isodoc-1.8.2.1 lib/isodoc/xslfo_convert.rb
isodoc-1.8.2 lib/isodoc/xslfo_convert.rb
isodoc-1.8.1 lib/isodoc/xslfo_convert.rb
isodoc-1.8.0 lib/isodoc/xslfo_convert.rb