lib/metanorma/compile.rb in metanorma-1.2.7 vs lib/metanorma/compile.rb in metanorma-1.2.8
- old
+ new
@@ -1,8 +1,9 @@
require "fileutils"
require "nokogiri"
require "htmlentities"
+require "yaml"
require "fontist"
require "fontist/manifest/install"
module Metanorma
@@ -249,10 +250,14 @@
end.each do |ext|
isodoc_options = @processor.extract_options(file)
isodoc_options[:datauriimage] = true if options[:datauriimage]
file_extension = @processor.output_formats[ext]
outfilename = f.sub(/\.[^.]+$/, ".#{file_extension}")
+ if ext == :pdf
+ font_locations = fontist_font_locations(options)
+ isodoc_options[:mn2pdf] = { font_manifest_file: font_locations.path } if font_locations
+ end
if ext == :rxl
options[:relaton] = outfilename
relaton_export(isodoc, options)
else
begin
@@ -262,10 +267,13 @@
rescue StandardError => e
puts e.message
puts e.backtrace.join("\n")
end
end
+ if ext == :pdf
+ # font_locations.unlink
+ end
wrap_html(options, file_extension, outfilename)
end
end
def install_fonts(options)
@@ -273,52 +281,87 @@
Util.log("[fontist] Skip font installation because" \
" --no-install-fonts argument passed", :debug)
return
end
- if !@processor.respond_to?(:fonts_manifest) || @processor.fonts_manifest.nil?
+ if missing_fontist_manifest?
Util.log("[fontist] Skip font installation because font_manifest is missing", :debug)
return
end
@updated_formulas_repo = false
manifest = @processor.fonts_manifest
agree_to_terms = options[:agree_to_terms] || false
continue_without_fonts = options[:continue_without_fonts] || false
+ no_progress = options[:no_progress] || false
- install_fonts_safe(manifest, agree_to_terms, continue_without_fonts)
+ install_fonts_safe(manifest, agree_to_terms, continue_without_fonts, no_progress)
end
private
- def install_fonts_safe(manifest, agree, continue)
- fontist_install(manifest, agree)
+ def install_fonts_safe(manifest, agree, continue, no_progress)
+ fontist_install(manifest, agree, no_progress)
rescue Fontist::Errors::LicensingError
if continue
- Util.log("[fontist] Processing will continue without fonts installed", :debug)
+ Util.log(
+ "[fontist] Processing will continue without fonts installed",
+ :debug
+ )
else
Util.log("[fontist] Aborting without proper fonts installed," \
" make sure that you have set option --agree-to-terms", :fatal)
end
rescue Fontist::Errors::FontError => e
log_level = continue ? :warning : :fatal
Util.log("[fontist] '#{e.font}' font is not supported. " \
- "Please report this issue at github.com/metanorma/metanorma-#{@processor.short}/issues" \
- " to report this issue.", log_level)
+ "Please report this issue at github.com/metanorma/metanorma-"\
+ "#{@processor.short}/issues to report this issue.", log_level)
rescue Fontist::Errors::FormulaIndexNotFoundError
- Util.log("[fontist] Bug: formula index not found after 'fontist update'", :fatal) if @updated_formulas_repo
+ if @updated_formulas_repo
+ Util.log(
+ "[fontist] Bug: formula index not found after 'fontist update'",
+ :fatal
+ )
+ end
Util.log("[fontist] Missing formula index. Fetching it...", :debug)
Fontist::Formula.update_formulas_repo
@updated_formulas_repo = true
- install_fonts_safe(manifest, agree, continue)
+ install_fonts_safe(manifest, agree, continue, no_progress)
end
- def fontist_install(manifest, agree)
+ def fontist_install(manifest, agree, no_progress)
Fontist::Manifest::Install.from_hash(
manifest,
- confirmation: agree ? "yes" : "no"
+ confirmation: agree ? "yes" : "no",
+ no_progress: no_progress
)
+ end
+
+ def fontist_font_locations(options)
+ return nil if missing_fontist_manifest? || options[:no_install_fonts]
+
+ dump_fontist_manifest_locations(@processor.fonts_manifest)
+ rescue Fontist::Errors::FormulaIndexNotFoundError
+ raise unless options[:continue_without_fonts]
+
+ nil
+ end
+
+ def dump_fontist_manifest_locations(manifest)
+ location_manifest = Fontist::Manifest::Locations.from_hash(
+ manifest
+ )
+ location_manifest_file = Tempfile.new(["fontist_locations", ".yml"])
+ location_manifest_file.write location_manifest.to_yaml
+ location_manifest_file.flush
+
+ location_manifest_file
+ end
+
+ def missing_fontist_manifest?
+ !@processor.respond_to?(:fonts_manifest) || @processor.fonts_manifest.nil?
end
# @param options [Hash]
# @return [String]
def change_output_dir(options)