From 2cbb2764cc3804260983057eb8eb07e1ae1edd48 Mon Sep 17 00:00:00 2001 From: Alexey Morozov Date: Tue, 12 Dec 2023 17:55:33 +0100 Subject: [PATCH] WIP: Draft eps2svg --- lib/isodoc/presentation_function/image.rb | 15 ++++++++++++++- spec/isodoc/presentation_xml_spec.rb | 12 ++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/isodoc/presentation_function/image.rb b/lib/isodoc/presentation_function/image.rb index bb1b1594..3b522755 100644 --- a/lib/isodoc/presentation_function/image.rb +++ b/lib/isodoc/presentation_function/image.rb @@ -63,7 +63,7 @@ def figure_label(elem) end def eps2svg(img) - # pp "Running eps2svg" + pp "Running eps2svg" return unless eps?(img["mimetype"]) img["mimetype"] = "image/svg+xml" @@ -111,6 +111,19 @@ def eps_to_svg(node) ret = imgfile_suffix(uri, "svg") File.exist?(ret) and return ret inkscape_convert(uri, ret, "--export-plain-svg --export-type='svg'") + # pp "called" + # if node.text.strip.empty? + # pp "text empty" + # uri = node["src"] + # ret = imgfile_suffix(uri, "svg") + # File.exist?(ret) and return ret + # Vectory::Eps.from_path(uri).to_svg.write(ret).path + # else + # pp "else" + # a = Base64.strict_encode64(node.children.to_xml) + # datauri_src = "data:application/postscript;base64,#{a}" + # Vectory::Datauri.new(datauri_src).to_vector.to_svg.write.path + # end end def svg_to_emf(node) diff --git a/spec/isodoc/presentation_xml_spec.rb b/spec/isodoc/presentation_xml_spec.rb index 3b08cd61..00e244d2 100644 --- a/spec/isodoc/presentation_xml_spec.rb +++ b/spec/isodoc/presentation_xml_spec.rb @@ -798,7 +798,7 @@ .to be_equivalent_to (output) end - xit "converts EPS to SVG files" do + it "converts EPS to SVG files" do input = <<~INPUT @@ -1012,7 +1012,8 @@ INPUT output = <<~OUTPUT - + + Table of contents @@ -1025,11 +1026,14 @@ OUTPUT - expect(xmlpp(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options) + first = xmlpp(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options) .convert("test", input, true) .sub(%r{.*}m, "") .gsub(%r{src="[^"]+?\.emf"}, 'src="_.emf"') - .gsub(%r{src="[^"]+?\.svg"}, 'src="_.svg"')))) + .gsub(%r{src="[^"]+?\.svg"}, 'src="_.svg"'))) + File.write("first", first) + File.write("second", output) + expect(first) .to be_equivalent_to (output) end