Skip to content

Commit

Permalink
Merge pull request #540 from metanorma/fix/emf-shadowing-restrict
Browse files Browse the repository at this point in the history
do not convert SVG to EMF if Word output is not supported: https://gi…
  • Loading branch information
opoudjis authored Oct 17, 2023
2 parents 328b998 + de85288 commit e4106fa
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 30 deletions.
3 changes: 3 additions & 0 deletions Gemfile.devel
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
gem "metanorma", git: "https://github.com/metanorma/metanorma", branch: "fix/propagate_output_formats"


3 changes: 2 additions & 1 deletion lib/isodoc/convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Convert < ::IsoDoc::Common
# sourcehighlighter: whether to apply sourcecode highlighting
# semantic_xml_insert: whether to insert into presentation XML
# a copy of semantic XML
# output_formats: hash of supported output formats and suffixes
def initialize(options) # rubocop:disable Lint/MissingSuper
@options = options_preprocess(options)
init_stylesheets(@options)
Expand Down Expand Up @@ -97,7 +98,7 @@ def convert1(docxml, filename, dir)
end

def convert_init(file, input_filename, debug)
docxml = Nokogiri::XML(file) { |config| config.huge }
docxml = Nokogiri::XML(file, &:huge)
filename, dir = init_file(input_filename, debug)
docxml.root.default_namespace = ""
convert_i18n_init(docxml)
Expand Down
1 change: 1 addition & 0 deletions lib/isodoc/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def init_rendering(options)
@aligncrosselements = options[:aligncrosselements]
@modspecidentifierbase = options[:modspecidentifierbase]
@sourcehighlighter = options[:sourcehighlighter]
@output_formats = options[:output_formats] || {}
end

def init_arrangement(options)
Expand Down
1 change: 1 addition & 0 deletions lib/isodoc/presentation_function/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def eps_to_svg(node)
end

def svg_to_emf(node)
@output_formats[:doc] or return
uri = svg_to_emf_uri(node)
svg_impose_height_attr(node)
ret = imgfile_suffix(uri, "emf")
Expand Down
14 changes: 7 additions & 7 deletions spec/isodoc/figures_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,11 @@
<foreword displayorder='2'>
<figure id='figureA-1'>
<name>Figure 1</name>
<image src='' mimetype='image/svg+xml' height='' width=''>
<image src='' mimetype='image/svg+xml' height='auto' width='auto'>
<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'>
<circle fill='#009' r='45' cx='50' cy='50'/>
<path d='M33,26H78A37,37,0,0,1,33,83V57H59V43H33Z' fill='#FFF'/>
</svg>
<emf src='data:image/emf;base64,AQAAAPwAAAAAAAAAAAAAAPsEAAD7BAAAAAAAAAAAAACLCgAAiwoAACBFTUYAAAEAWAQAACgAAAACAAAARwAAAGwAAAAAAAAA3ScAAH0zAADYAAAAFwEAAAAAAAAAAAAAAAAAAMBLAwDYQQQASQBuAGsAcwBjAGEAcABlACAAMQAuADIALgAxACAAKAA5AGMANgBkADQAMQBlACwAIAAyADAAMgAyAC0AMAA3AC0AMQA0ACkAIAAAAGkAbQBhAGcAZQAyADAAMgAyADAAOQAxADMALQA4ADMAMQA3ADYALQA2AHcAYwB1AGMAdgAuAGUAbQBmAAAAAAAAAAAAEQAAAAwAAAABAAAAJAAAACQAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAACAAAARgAAACwAAAAgAAAAU2NyZWVuPTEwMjA1eDEzMTgxcHgsIDIxNngyNzltbQBGAAAAMAAAACMAAABEcmF3aW5nPTEwMC4weDEwMC4wcHgsIDI2LjV4MjYuNW1tAAASAAAADAAAAAEAAAATAAAADAAAAAIAAAAWAAAADAAAABgAAAAYAAAADAAAAAAAAAAUAAAADAAAAA0AAAAnAAAAGAAAAAEAAAAAAAAAAACZAAYAAAAlAAAADAAAAAEAAAA7AAAACAAAABsAAAAQAAAApAQAAHECAAAFAAAANAAAAAAAAAAAAAAA//////////8DAAAApAQAAKgDAACoAwAApAQAAHECAACkBAAABQAAADQAAAAAAAAAAAAAAP//////////AwAAADoBAACkBAAAPwAAAKgDAAA/AAAAcQIAAAUAAAA0AAAAAAAAAAAAAAD//////////wMAAAA/AAAAOgEAADoBAAA/AAAAcQIAAD8AAAAFAAAANAAAAAAAAAAAAAAA//////////8DAAAAqAMAAD8AAACkBAAAOgEAAKQEAABxAgAAPQAAAAgAAAA8AAAACAAAAD4AAAAYAAAAAAAAAAAAAAD//////////yUAAAAMAAAABQAAgCgAAAAMAAAAAQAAACcAAAAYAAAAAQAAAAAAAAD///8ABgAAACUAAAAMAAAAAQAAADsAAAAIAAAAGwAAABAAAACdAQAARQEAADYAAAAQAAAAzwMAAEUBAAAFAAAANAAAAAAAAAAAAAAA//////////8DAAAAXwQAAO0BAABkBAAA4wIAANsDAACRAwAABQAAADQAAAAAAAAAAAAAAP//////////AwAAAFIDAAA+BAAAYQIAAHMEAACdAQAADgQAADYAAAAQAAAAnQEAAMkCAAA2AAAAEAAAAOICAADJAgAANgAAABAAAADiAgAAGgIAADYAAAAQAAAAnQEAABoCAAA9AAAACAAAADwAAAAIAAAAPgAAABgAAAAAAAAAAAAAAP//////////JQAAAAwAAAAFAACAKAAAAAwAAAABAAAADgAAABQAAAAAAAAAAAAAAFgEAAA='/>
</image>
</figure>
</foreword>
Expand Down Expand Up @@ -562,7 +561,8 @@
</html>
DOC

expect(strip_guid(xmlpp(IsoDoc::PresentationXMLConvert.new(presxml_options)
expect(strip_guid(xmlpp(IsoDoc::PresentationXMLConvert
.new(presxml_options.merge(output_formats: { html: "html", doc: "doc" }))
.convert("test", input, true)
.gsub(/&lt;/, "&#x3c;")
.gsub(%r{data:image/emf;base64,[^"']+}, "data:image/emf;base64"))))
Expand Down Expand Up @@ -662,7 +662,8 @@
</body>
</html>
OUTPUT
expect(strip_guid(xmlpp(IsoDoc::PresentationXMLConvert.new(presxml_options)
expect(strip_guid(xmlpp(IsoDoc::PresentationXMLConvert
.new(presxml_options.merge(output_formats: { html: "html", doc: "doc" }))
.convert("test", input, true)
.gsub(/&lt;/, "&#x3c;"))
.gsub(%r{data:image/emf;base64,[^"']+}, "data:image/emf;base64")))
Expand Down Expand Up @@ -698,7 +699,8 @@
</iso-standard>
INPUT
expect do
IsoDoc::PresentationXMLConvert.new(presxml_options)
IsoDoc::PresentationXMLConvert
.new(presxml_options.merge(output_formats: { html: "html", doc: "doc" }))
.convert("test", input, true)
end.to raise_error("Inkscape missing in PATH, unable" \
"to convert image spec/assets/odf1.svg. Aborting.")
Expand Down Expand Up @@ -801,12 +803,10 @@
<sections>
<figure id='_'>
<image src='spec/assets/action_schemaexpg1.svg' id='_' mimetype='image/svg+xml' height='auto' width='auto'>
<emf src="data:image/emf;base64"/>
</image>
</figure>
<figure id='_'>
<image src='spec/assets/action_schemaexpg2.svg' id='_' mimetype='image/svg+xml' height='auto' width='auto' alt='Workmap'>
<emf src="data:image/emf;base64"/>
</image>
</figure>
</sections>
Expand Down
102 changes: 80 additions & 22 deletions spec/isodoc/presentation_xml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,65 @@
</sections>
</iso-standard>
OUTPUT
expect(xmlpp(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options)
expect(xmlpp(strip_guid(IsoDoc::PresentationXMLConvert
.new(presxml_options.merge(output_formats: { html: "html", doc: "doc" }))
.convert("test", input, true)
.sub(%r{<localized-strings>.*</localized-strings>}m, "")
.gsub(%r{"data:image/emf;base64,[^"]+"},
'"data:image/emf;base64"')
.gsub(%r{"data:application/x-msmetafile;base64,[^"]+"},
'"data:application/x-msmetafile;base64"'))))
.to be_equivalent_to (output)

output = <<~OUTPUT
<iso-standard xmlns="http://riboseinc.com/isoxml" type="presentation">
<bibdata/>
<preface>
<clause type="toc" id="_" displayorder="1">
<title depth="1">Table of contents</title>
</clause>
</preface>
<sections>
<clause id="A" inline-header="false" obligation="normative" displayorder="2">
<title depth="1">1.<tab/>Clause</title>
<figure id="B">
<name>Figure 1</name>
<image src="spec/assets/odf.svg" mimetype="image/svg+xml" alt="1"/>
<image src="" mimetype="image/svg+xml" alt="2">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="1275.0000" height="1275.0000">
<g transform="translate(-0.0000, -0.0000)">
<g transform="matrix(1.0000 0.0000 0.0000 1.0000 0.0000 0.0000)">
<path d="M 1188.0000,625.0000 C 1188.0000,936.0000 936.0000,1188.0000 625.0000,1188.0000 C 314.0000,1188.0000 63.0000,936.0000 63.0000,625.0000 C 63.0000,314.0000 314.0000,63.0000 625.0000,63.0000 C 936.0000,63.0000 1188.0000,314.0000 1188.0000,625.0000 Z " fill="#000099" stroke="none"/>
<path d="M 413.0000,325.0000 L 975.0000,325.0000 C 1119.0000,493.0000 1124.0000,739.0000 987.0000,913.0000 C 850.0000,1086.0000 609.0000,1139.0000 413.0000,1038.0000 L 413.0000,713.0000 L 738.0000,713.0000 L 738.0000,538.0000 L 413.0000,538.0000 Z " fill="#FFFFFF" stroke="none"/>
</g>
</g>
</svg>
<emf src="data:image/emf;base64"/>
</image>
<image src="" mimetype="image/svg+xml" alt="3">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
<circle fill="#009" r="45" cx="50" cy="50"/>
<path d="M33,26H78A37,37,0,0,1,33,83V57H59V43H33Z" fill="#FFF"/>
</svg>
</image>
<image src="" mimetype="image/svg+xml" alt="4">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="1275.0000" height="1275.0000">
<g transform="translate(-0.0000, -0.0000)">
<g transform="matrix(1.0000 0.0000 0.0000 1.0000 0.0000 0.0000)">
<path d="M 1188.0000,625.0000 C 1188.0000,936.0000 936.0000,1188.0000 625.0000,1188.0000 C 314.0000,1188.0000 63.0000,936.0000 63.0000,625.0000 C 63.0000,314.0000 314.0000,63.0000 625.0000,63.0000 C 936.0000,63.0000 1188.0000,314.0000 1188.0000,625.0000 Z " fill="#000099" stroke="none"/>
<path d="M 413.0000,325.0000 L 975.0000,325.0000 C 1119.0000,493.0000 1124.0000,739.0000 987.0000,913.0000 C 850.0000,1086.0000 609.0000,1139.0000 413.0000,1038.0000 L 413.0000,713.0000 L 738.0000,713.0000 L 738.0000,538.0000 L 413.0000,538.0000 Z " fill="#FFFFFF" stroke="none"/>
</g>
</g>
</svg>
<emf src="data:application/x-msmetafile;base64"/>
</image>
</figure>
</clause>
</sections>
</iso-standard>
OUTPUT
expect(xmlpp(strip_guid(IsoDoc::PresentationXMLConvert
.new(presxml_options.merge(output_formats: { html: "html" }))
.convert("test", input, true)
.sub(%r{<localized-strings>.*</localized-strings>}m, "")
.gsub(%r{"data:image/emf;base64,[^"]+"},
Expand Down Expand Up @@ -1598,26 +1656,26 @@
</standard-document>
INPUT
presxml = <<~OUTPUT
<standard-document xmlns="https://www.metanorma.org/ns/standoc" type="presentation">
<bibdata/>
<standard-document xmlns="https://www.metanorma.org/ns/standoc" type="presentation">
<bibdata/>
<preface>
<clause type="toc" id="_" displayorder="1">
<title depth="1">Table of contents</title>
</clause>
<abstract displayorder="2"/>
<foreword displayorder="3"/>
<introduction displayorder="4"/>
<p type="floating-title" displayorder="5">FL 1</p>
<p type="floating-title" displayorder="6">FL 2</p>
<p type="floating-title" displayorder="7">FL 3</p>
<p type="floating-title" displayorder="8">FL 4</p>
<p type="floating-title" displayorder="9">FL 5</p>
<p type="floating-title" displayorder="10">FL 6</p>
<p type="floating-title" displayorder="11">FL 0</p>
<acknowledgements displayorder="12"/>
</preface>
</standard-document>
<preface>
<clause type="toc" id="_" displayorder="1">
<title depth="1">Table of contents</title>
</clause>
<abstract displayorder="2"/>
<foreword displayorder="3"/>
<introduction displayorder="4"/>
<p type="floating-title" displayorder="5">FL 1</p>
<p type="floating-title" displayorder="6">FL 2</p>
<p type="floating-title" displayorder="7">FL 3</p>
<p type="floating-title" displayorder="8">FL 4</p>
<p type="floating-title" displayorder="9">FL 5</p>
<p type="floating-title" displayorder="10">FL 6</p>
<p type="floating-title" displayorder="11">FL 0</p>
<acknowledgements displayorder="12"/>
</preface>
</standard-document>
OUTPUT
expect(xmlpp(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options)
.convert("test", input, true))
Expand Down Expand Up @@ -1774,10 +1832,10 @@
</table>
</foreword></preface></standard-document>
OUTPUT
expect((strip_guid(IsoDoc::PresentationXMLConvert
expect(strip_guid(IsoDoc::PresentationXMLConvert
.new(presxml_options.merge(breakupurlsintables: "true"))
.convert("test", input, true))
.sub(%r{<localized-strings>.*</localized-strings>}m, "")))
.sub(%r{<localized-strings>.*</localized-strings>}m, ""))
.to be_equivalent_to (presxml)
end

Expand Down

0 comments on commit e4106fa

Please sign in to comment.