Here's a fairly minimal example showing an issue, using ConTeXt LMTX. Save the following as "main.tex": % SOF \startbuffer[document] <body><img src="circle.svg"/></body> \stopbuffer \startbuffer[csvg] <svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"> <g><circle cx="50" cy="50" r="20"/></g> </svg> \stopbuffer \startxmlsetups xml:xhtml \xmlsetsetup{\xmldocument}{body|img}{xml:*} \stopxmlsetups \startxmlsetups xml:body \xmlflush{#1} \stopxmlsetups \startxmlsetups xml:img \placefigure{}{\externalfigure[\xmlatt{#1}{src}][conversion=mp]} \placefigure{}{\externalfigure[circle.svg][conversion=mp]} \placefigure{}{\includesvgbuffer[csvg][conversion=mp]} \stopxmlsetups \xmlregistersetup{xml:xhtml} \starttext \xmlprocessbuffer{xhtml}{document}{} \placefigure{}{\externalfigure[circle.svg][conversion=mp]} \placefigure{}{\externalfigure[diagram.svg][conversion=mp]} \stoptext % EOF Save the contents of "\startbuffer[csvg]" to a file named "circle.svg", to create a valid, external SVG file. Copy "circle.svg" to a file named "diagram.svg" to create a second valid, external SVG file. Run: context main.tex Expected All the SVG images appear. Actual Figures 1, 2, and 4 show only the following text: \includesvgfile[circle.svg]\resetbuffer[svg-circle-inclusion] In contrast, consider the following document: % SOF \startbuffer[csvg] <svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"> <g><circle cx="50" cy="50" r="20"/></g> </svg> \stopbuffer \starttext \placefigure{}{\includesvgbuffer[csvg][conversion=mp]} \placefigure{}{\externalfigure[circle.svg][conversion=mp]} \placefigure{}{\externalfigure[diagram.svg][conversion=mp]} \stoptext % EOF All the images appear as expected. Any idea why using XML setups appears to affect the behaviour of rendering SVG documents using MetaPost? Thank you!
On 3/9/2021 7:29 AM, Thangalin wrote:
Here's a fairly minimal example showing an issue, using ConTeXt LMTX. Save the following as "main.tex":
% SOF \startbuffer[document] <body><img src="circle.svg"/></body> \stopbuffer
\startbuffer[csvg] <svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"> <g><circle cx="50" cy="50" r="20"/></g> </svg> \stopbuffer
\startxmlsetups xml:xhtml \xmlsetsetup{\xmldocument}{body|img}{xml:*} \stopxmlsetups
\startxmlsetups xml:body \xmlflush{#1} \stopxmlsetups
\startxmlsetups xml:img \placefigure{}{\externalfigure[\xmlatt{#1}{src}][conversion=mp]} \placefigure{}{\externalfigure[circle.svg][conversion=mp]} \placefigure{}{\includesvgbuffer[csvg][conversion=mp]} \stopxmlsetups
\startxmlsetups xml:img \starttexcode \placefigure{}{\externalfigure[\xmlatt{#1}{src}][conversion=mp]} \placefigure{}{\externalfigure [circle.svg][conversion=mp]} \placefigure{}{\includesvgbuffer[csvg] [conversion=mp]} \stoptexcode \stopxmlsetups I probably need to add that wrapper in a few spots but in general if you can use that in case of issues. It has to do with catcodes, chicken and eggs. Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
Thanks, Hans. The image is now rendered. Here's a picture of the output from ConTeXt (left) and the expected output using Apache Batik: https://i.ibb.co/zPqfhjK/metapost-svg.png Would a copy of the SVG file be useful for unit testing? Thanks again.
I probably need to add that wrapper in a few spots but in general if you can use that in case of issues. It has to do with catcodes, chicken and eggs.
participants (2)
-
Hans Hagen
-
Thangalin