Skip to content

Commit

Permalink
Merge pull request #541 from metanorma/features/private-charset
Browse files Browse the repository at this point in the history
custom-charset for Private Use character codepoints: https://github.c…
  • Loading branch information
opoudjis authored Nov 8, 2023
2 parents 4f4579c + e072f4a commit 6933d17
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/isodoc/presentation_function/inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions lib/isodoc/presentation_xml_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def inline(docxml)
variant docxml
identifier docxml
date docxml
inline_format docxml
end

def terms(docxml)
Expand Down
28 changes: 28 additions & 0 deletions spec/isodoc/presentation_xml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1839,6 +1839,34 @@
.to be_equivalent_to (presxml)
end

it "realises custom charsets" do
input = <<~INPUT
<standard-document xmlns="https://www.metanorma.org/ns/standoc" type="semantic">
<presentation-metadata><custom-charset-font>weather:"OGC Weather Symbols"</custom-charset-font></presentation-metadata>
<presentation-metadata><custom-charset-font>conscript:"Code 2000"</custom-charset-font></presentation-metadata>
<preface>
<foreword id="A">
<p id="_214f7090-c6d4-8fdc-5e6a-837ebb515871"><span custom-charset="weather">ﶀ</span></p>
</foreword></preface></standard-document>
INPUT
presxml = <<~OUTPUT
<standard-document xmlns="https://www.metanorma.org/ns/standoc" type="presentation">
<presentation-metadata><custom-charset-font>weather:"OGC Weather Symbols"</custom-charset-font></presentation-metadata>
<presentation-metadata><custom-charset-font>conscript:"Code 2000"</custom-charset-font></presentation-metadata>
<preface><clause type="toc" id="_" displayorder="1"><title depth="1">Table of contents</title></clause>
<foreword id="A" displayorder="2">
<p id="_"><span custom-charset="weather" style=";font-family:&quot;OGC Weather Symbols&quot;">&#xFD80;</span></p>
</foreword></preface></standard-document>
OUTPUT
expect(strip_guid(IsoDoc::PresentationXMLConvert
.new(presxml_options)
.convert("test", input, true))
.sub(%r{<localized-strings>.*</localized-strings>}m, ""))
.to be_equivalent_to (presxml)
end


private

def mock_symbols
Expand Down

0 comments on commit 6933d17

Please sign in to comment.