diff --git a/lib/isodoc/xslfo_convert.rb b/lib/isodoc/xslfo_convert.rb index 1e2d8d0c..c8c2a3b1 100644 --- a/lib/isodoc/xslfo_convert.rb +++ b/lib/isodoc/xslfo_convert.rb @@ -39,7 +39,13 @@ def pdf_stylesheet(_docxml) nil end - def pdf_options(_docxml) + def baseassetpath(filename) + !@baseassetpath && filename and + @baseassetpath = File.expand_path(Pathname.new(filename).parent.to_s) + end + + def pdf_options(_docxml, filename) + baseassetpath(filename) ret = {} font_manifest = @options.dig(MN_OPTIONS_KEY, MN2PDF_FONT_MANIFEST) and ret[MN2PDF_FONT_MANIFEST] = font_manifest @@ -61,7 +67,7 @@ def convert(input_fname, file = nil, debug = false, @doctype = Nokogiri::XML(file).at(ns("//bibdata/ext/doctype"))&.text ::Metanorma::Output::XslfoPdf.new.convert( filename, output_fname || output_filename(input_fname), - xsl, pdf_options(docxml) + xsl, pdf_options(docxml, input_fname) ) end diff --git a/spec/isodoc/xslfo_convert_spec.rb b/spec/isodoc/xslfo_convert_spec.rb index 90540376..950a814b 100644 --- a/spec/isodoc/xslfo_convert_spec.rb +++ b/spec/isodoc/xslfo_convert_spec.rb @@ -8,7 +8,7 @@ }, ) - expect(convert.pdf_options(nil)).to eq({ "--syntax-highlight": nil }) + expect(convert.pdf_options(nil, nil)).to eq({ "--syntax-highlight": nil }) end it "test default pdf_options for nil font_manifest_file" do @@ -21,7 +21,7 @@ }, ) - expect(convert.pdf_options(nil)).to eq({ "--syntax-highlight": nil }) + expect(convert.pdf_options(nil, nil)).to eq({ "--syntax-highlight": nil }) end it "test --font-manifest pdf_options" do @@ -36,7 +36,7 @@ }, ) - expect(convert.pdf_options(nil)).to eq(mn2pdf_opts) + expect(convert.pdf_options(nil, nil)).to eq(mn2pdf_opts) end it "test --param align-cross-elements pdf_options" do @@ -47,7 +47,7 @@ }, ) - expect(convert.pdf_options(nil)) + expect(convert.pdf_options(nil, nil)) .to eq({ "--param align-cross-elements=" => "clause table note", "--syntax-highlight": nil }) end @@ -60,9 +60,22 @@ }, ) - expect(convert.pdf_options(nil)) + expect(convert.pdf_options(nil, nil)) .to eq({ "--param baseassetpath=" => "ABC", "--syntax-highlight": nil }) + + convert = IsoDoc::XslfoPdfConvert.new( + { + datauriimage: false, + }, + ) + + expect(convert.pdf_options(nil, nil)) + .to eq({ "--syntax-highlight": nil }) + + expect(convert.pdf_options(nil, "test.xml")) + .to eq({ "--param baseassetpath=" => File.expand_path("."), + "--syntax-highlight": nil }) end it "test pdf encryption options" do @@ -83,7 +96,7 @@ }, ) - expect(convert.pdf_options(nil)) + expect(convert.pdf_options(nil, nil)) .to eq({ "--allow-access-content" => "i", "--allow-assemble-document" => "j",