From e072f4ab946c1151d7df44853562dbb61773d600 Mon Sep 17 00:00:00 2001 From: Nick Nicholas Date: Thu, 9 Nov 2023 00:29:25 +1100 Subject: [PATCH] custom-charset for Private Use character codepoints: https://github.com/metanorma/metanorma/issues/339 --- lib/isodoc/presentation_function/inline.rb | 20 ++++++++++++++++ lib/isodoc/presentation_xml_convert.rb | 1 + spec/isodoc/presentation_xml_spec.rb | 28 ++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/lib/isodoc/presentation_function/inline.rb b/lib/isodoc/presentation_function/inline.rb index ef50af0e..81723598 100644 --- a/lib/isodoc/presentation_function/inline.rb +++ b/lib/isodoc/presentation_function/inline.rb @@ -99,8 +99,28 @@ def date1(elem) elem.replace(@i18n.date(elem["value"], elem["format"].strip)) end + def inline_format(docxml) + custom_charset(docxml) + end + + def custom_charset(docxml) + charsets = extract_custom_charsets(docxml) + docxml.xpath(ns("//span[@custom-charset]")).each do |s| + s["style"] ||= "" + s["style"] += ";font-family:#{charsets[s['custom-charset']]}" + end + end + private + def extract_custom_charsets(docxml) + docxml.xpath(ns("//presentation-metadata/custom-charset-font")). + each_with_object({}) do |x, m| + kv = x.text.split(":", 2) + m[kv[0]] = kv[1] + end + end + def found_matching_variant_sibling(node) prev = node.xpath("./preceding-sibling::xmlns:variant") foll = node.xpath("./following-sibling::xmlns:variant") diff --git a/lib/isodoc/presentation_xml_convert.rb b/lib/isodoc/presentation_xml_convert.rb index e770b5bd..faf7d2c1 100644 --- a/lib/isodoc/presentation_xml_convert.rb +++ b/lib/isodoc/presentation_xml_convert.rb @@ -89,6 +89,7 @@ def inline(docxml) variant docxml identifier docxml date docxml + inline_format docxml end def terms(docxml) diff --git a/spec/isodoc/presentation_xml_spec.rb b/spec/isodoc/presentation_xml_spec.rb index 36ac54fd..3a2c5759 100644 --- a/spec/isodoc/presentation_xml_spec.rb +++ b/spec/isodoc/presentation_xml_spec.rb @@ -1839,6 +1839,34 @@ .to be_equivalent_to (presxml) end + it "realises custom charsets" do + input = <<~INPUT + + weather:"OGC Weather Symbols" + conscript:"Code 2000" + + +

+
+ INPUT + presxml = <<~OUTPUT + + weather:"OGC Weather Symbols" + conscript:"Code 2000" + Table of contents + + +

+
+ OUTPUT + expect(strip_guid(IsoDoc::PresentationXMLConvert + .new(presxml_options) + .convert("test", input, true)) + .sub(%r{.*}m, "")) + .to be_equivalent_to (presxml) + end + + private def mock_symbols