Skip to content

Commit

Permalink
pass fontist font names to Presentation XML: metanorma/metanorma-stan…
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis committed Apr 14, 2022
1 parent 987b9af commit 407dc1e
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/isodoc/convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class Convert < ::IsoDoc::Common
# tocfigures: add ToC for figures
# toctables: add ToC for tables
# tocrecommendations: add ToC for rcommendations
# fonts: fontist fonts to install
# fontlicenseagreement: fontist font license agreement
def initialize(options)
@libdir ||= File.dirname(__FILE__) # rubocop:disable Lint/DisjunctiveAssignmentInConstructor
options.merge!(default_fonts(options)) do |_, old, new|
Expand All @@ -57,10 +59,7 @@ def initialize(options)
init_stylesheets(options)
init_covers(options)
init_toc(options)
@normalfontsize = options[:normalfontsize]
@smallerfontsize = options[:smallerfontsize]
@monospacefontsize = options[:monospacefontsize]
@footnotefontsize = options[:footnotefontsize]
init_fonts(options)
@i18nyaml = options[:i18nyaml]
@ulstyle = options[:ulstyle]
@olstyle = options[:olstyle]
Expand Down Expand Up @@ -96,6 +95,15 @@ def initialize(options)
@tmpfilesdir_suffix = tmpfilesdir_suffix
end

def init_fonts(options)
@normalfontsize = options[:normalfontsize]
@smallerfontsize = options[:smallerfontsize]
@monospacefontsize = options[:monospacefontsize]
@footnotefontsize = options[:footnotefontsize]
@fontist_fonts = options[:fonts]
@fontlicenseagreement = options[:fontlicenseagreement]
end

def init_covers(options)
@header = options[:header]
@htmlcoverpage = options[:htmlcoverpage]
Expand Down
20 changes: 20 additions & 0 deletions lib/isodoc/presentation_function/bibdata.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
require "csv"

module IsoDoc
class PresentationXMLConvert < ::IsoDoc::Convert
def bibdata(docxml)
toc_metadata(docxml)
fonts_metadata(docxml)
docid_prefixes(docxml)
a = bibdata_current(docxml) or return
address_precompose(a)
Expand Down Expand Up @@ -34,6 +37,23 @@ def address_precompose(bib)
end
end

def fonts_metadata(xmldoc)
return unless @fontist_fonts

ins = xmldoc.at(ns("//presentation-metadata")) ||
xmldoc.at(ns("//misc-container")) || xmldoc.at(ns("//bibdata"))
CSV.parse_line(@fontist_fonts, col_sep: ";").map(&:strip).each do |f|
ins.next = presmeta("fonts", f)
end
@fontlicenseagreement and
ins.next = presmeta("font-license-agreement", @fontlicenseagreement)
end

def presmeta(name, value)
"<presentation-metadata><name>#{name}</name><value>#{value}</value>"\
"</presentation-metadata>"
end

def address_precompose1(addr)
ret = []
addr.xpath(ns("./street")).each { |s| ret << s.children.to_xml }
Expand Down
50 changes: 50 additions & 0 deletions spec/isodoc/presentation_xml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,56 @@
.to be_equivalent_to xmlpp(presxml)
end

it "passes font names to Presentation XML" do
input = <<~INPUT
<iso-standard xmlns="http://riboseinc.com/isoxml">
<bibdata/>
<sections>
<clause id="A" inline-header="false" obligation="normative">
<title>Section</title>
<figure id="B1">
<name>First</name>
</figure>
</clause>
</sections>
</iso-standard>
INPUT
presxml = <<~OUTPUT
<iso-standard xmlns='http://riboseinc.com/isoxml' type='presentation'>
<bibdata/>
<presentation-metadata>
<name>font-license-agreement</name>
<value>no-install-fonts</value>
</presentation-metadata>
<presentation-metadata>
<name>fonts</name>
<value>font2</value>
</presentation-metadata>
<presentation-metadata>
<name>fonts</name>
<value>font1</value>
</presentation-metadata>
<sections>
<clause id='A' inline-header='false' obligation='normative' displayorder='1'>
<title depth='1'>
1.
<tab/>
Section
</title>
<figure id='B1'>
<name>Figure 1&#xA0;&#x2014; First</name>
</figure>
</clause>
</sections>
</iso-standard>
OUTPUT
expect(xmlpp(IsoDoc::PresentationXMLConvert
.new({ fonts: "font1; font2", fontlicenseagreement: "no-install-fonts" })
.convert("test", input, true))
.sub(%r{<localized-strings>.*</localized-strings>}m, ""))
.to be_equivalent_to xmlpp(presxml)
end

private

def mock_symbols
Expand Down

0 comments on commit 407dc1e

Please sign in to comment.