Hey hey, The following produces a filled square, rather than an empty one: \startbuffer[svg] <svg> <rect width="100" height="100" style="stroke:rgb(0,0,0);;fill:none" /> </svg> \stopbuffer \starttext \placefigure{}{\includesvgbuffer[svg][conversion=mp]} \stoptext Remove the extra semicolon to get the expected result: <svg> <rect width="100" height="100" style="stroke:rgb(0,0,0);fill:none" /> </svg> It appears that a style immediately following two semicolons is ignored. The SVG was generated using the following R code: svg("filename.svg"); plot(rnorm(200)); dev.off() Arguably, R's SVG routines could be a bit tighter. Can the MP SVG parser code be relaxed to skip "empty" semicolons? $ context --version mtx-context | current version: 2022.05.02 16:19 Much appreciated.
Hi again,
In tex/texmf-context/tex/context/base/mkxl/mlib-svg.lmt the following regex
appears a few times (line 1502, 1556, and 1570):
gmatch(VAR,"%s*([^:]+):%s*([^;]+);?")
It may be helpful to first normalize the string by appending a semicolon to
the end, allowing for:
for w in (VAR .. ";"):gmatch("([^;]*);") do ...
Splitting 'w' afterwards on the colon within key:value pairs would still be
necessary, so maybe that approach is a wash.
Aside, when I made changes to the file, I couldn't get either a report() or
a print() statement to show up in the output, even when running with
--debug. Any hints on how to sprinkle debug info into the code? Or was I
barking up the wrong source file?
Cheers!
On Sun, May 8, 2022 at 1:33 AM Thangalin
Hey hey,
The following produces a filled square, rather than an empty one:
\startbuffer[svg] <svg> <rect width="100" height="100" style="stroke:rgb(0,0,0);;fill:none" /> </svg> \stopbuffer
\starttext \placefigure{}{\includesvgbuffer[svg][conversion=mp]} \stoptext
Remove the extra semicolon to get the expected result:
<svg> <rect width="100" height="100" style="stroke:rgb(0,0,0);fill:none" /> </svg>
It appears that a style immediately following two semicolons is ignored.
The SVG was generated using the following R code:
svg("filename.svg"); plot(rnorm(200)); dev.off()
Arguably, R's SVG routines could be a bit tighter. Can the MP SVG parser code be relaxed to skip "empty" semicolons?
$ context --version mtx-context | current version: 2022.05.02 16:19
Much appreciated.
Here's a screenshot comparing ConTeXt's PDF output (left) with KeenWrite's preview for the same SVG document: https://i.ibb.co/68nqwrg/render-r-plot.png I've filed a bug against Renjin's SVG exporter. Any guidance on how to fix this is greatly appreciated.
Hi there I can compile your example without any tweaks, hence could not reproduce any error. cheers Heinrich ——— R version 4.2.0 (2022-04-22) -- "Vigorous Calisthenics" Copyright (C) 2022 The R Foundation for Statistical Computing Platform: x86_64-apple-darwin17.0 (64-bit) [R.app GUI 1.78 (8075) x86_64-apple-darwin17.0]
svg("/Users/hp/filename.svg"); plot(rnorm(200)); dev.off() null device 1
——— % !TEX program = lmtx \starttext \externalfigure[/Users/hp/filename.svg][conversion=mp] \stoptext ———
On 9. May 2022, at 08:10, Thangalin via ntg-context
wrote: Here's a screenshot comparing ConTeXt's PDF output (left) with KeenWrite's preview for the same SVG document:
https://i.ibb.co/68nqwrg/render-r-plot.png https://i.ibb.co/68nqwrg/render-r-plot.png
I've filed a bug against Renjin's SVG exporter.
Any guidance on how to fix this is greatly appreciated.
___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________
Hi Heinrich,
Use the SVG I provided. R and Renjin use two different SVG generators.
Renjin uses JFreeSVG when exporting as SVG. As you pointed out, there are
no issues with R because it will export an SVG file without any double
semicolons.
In other words, try this:
\startbuffer[svg]
<svg>
<rect width="100" height="100"
style="stroke:rgb(0,0,0);;fill:none" />
</svg>
\stopbuffer
\starttext
\placefigure{}{\includesvgbuffer[svg][conversion=mp]}
\stoptext
If you get a black square, that's the bug. If you get a white square, then
there's something different about our environment setups.
Cheers!
On Mon, May 9, 2022 at 1:55 AM Heinrich Paeßens
Hi there
I can compile your example without any tweaks, hence could not reproduce any error.
cheers Heinrich
———
R version 4.2.0 (2022-04-22) -- "Vigorous Calisthenics" Copyright (C) 2022 The R Foundation for Statistical Computing Platform: x86_64-apple-darwin17.0 (64-bit)
[R.app GUI 1.78 (8075) x86_64-apple-darwin17.0]
svg("/Users/hp/filename.svg"); plot(rnorm(200)); dev.off() null device 1
———
% !TEX program = lmtx
\starttext \externalfigure[/Users/hp/filename.svg][conversion=mp] \stoptext
———
On 9. May 2022, at 08:10, Thangalin via ntg-context
wrote: Here's a screenshot comparing ConTeXt's PDF output (left) with KeenWrite's preview for the same SVG document:
https://i.ibb.co/68nqwrg/render-r-plot.png
I've filed a bug against Renjin's SVG exporter.
Any guidance on how to fix this is greatly appreciated.
___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net
___________________________________________________________________________________
Yes, now I see, but isn’t there sth missing in the export from JFreeSVG, that were supposed to fill in between the semicolons? If not, why don’t you just post-process, if possible … … sth like
gsed ’s/;;/;/g' in.svg > out.svg
;-)
On 9. May 2022, at 17:42, Thangalin
wrote: Hi Heinrich,
Use the SVG I provided. R and Renjin use two different SVG generators. Renjin uses JFreeSVG when exporting as SVG. As you pointed out, there are no issues with R because it will export an SVG file without any double semicolons.
In other words, try this:
\startbuffer[svg] <svg> <rect width="100" height="100" style="stroke:rgb(0,0,0);;fill:none" /> </svg> \stopbuffer
\starttext \placefigure{}{\includesvgbuffer[svg][conversion=mp]} \stoptext
If you get a black square, that's the bug. If you get a white square, then there's something different about our environment setups.
Cheers!
On Mon, May 9, 2022 at 1:55 AM Heinrich Paeßens
mailto:paessens@me.com> wrote: Hi there I can compile your example without any tweaks, hence could not reproduce any error.
cheers Heinrich
———
R version 4.2.0 (2022-04-22) -- "Vigorous Calisthenics" Copyright (C) 2022 The R Foundation for Statistical Computing Platform: x86_64-apple-darwin17.0 (64-bit)
[R.app GUI 1.78 (8075) x86_64-apple-darwin17.0]
svg("/Users/hp/filename.svg"); plot(rnorm(200)); dev.off() null device 1
———
% !TEX program = lmtx
\starttext \externalfigure[/Users/hp/filename.svg][conversion=mp] \stoptext
———
On 9. May 2022, at 08:10, Thangalin via ntg-context
mailto:ntg-context@ntg.nl> wrote: Here's a screenshot comparing ConTeXt's PDF output (left) with KeenWrite's preview for the same SVG document:
https://i.ibb.co/68nqwrg/render-r-plot.png https://i.ibb.co/68nqwrg/render-r-plot.png
I've filed a bug against Renjin's SVG exporter.
Any guidance on how to fix this is greatly appreciated.
___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl mailto:ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl http://www.pragma-ade.nl/ / http://context.aanhet.net http://context.aanhet.net/ archive : https://bitbucket.org/phg/context-mirror/commits/ https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net http://contextgarden.net/ ___________________________________________________________________________________
gsed ’s/;;/;/g' in.svg > out.svg
If a user has an SVG text element where ";;" goes into the document, then that'd make for an awfully awkward user experience and obscure bug to fix. For example: plot(rnorm(5), xlab=";;") Meaning, the document must be loaded, parsed, and all style/class elements sanitized. KeenWrite performs real-time rendering of documents. The code to preview the document is shared by the code that exports to XHTML for ConTeXt to render. Effectively, this would be parsing the SVG document twice, which would bog down the previewer. Changing the regexes in mlib-svg.lmt to forgive empty styles seems like the most efficient and flexible approach, which follows the robustness principle: "be conservative in what you send, be liberal in what you accept." The specs for CSS styles are ambiguous as to whether property declarations are required: https://www.w3.org/TR/2001/PR-SVG-20010719/styling.html#StyleAttribute I've since learned that Renjin uses JFreeSVG to produce the SVG file. I've logged a bug against JFreeSVG to avoid the double semicolon. However, this means waiting for a fix from JFreeSVG and then waiting for that fix to be integrated into Renjin. It'll probably be months before that'll happen. (The last release of Renjin was like 10 months ago.) Thoughts?
ok, let’s get smarter. how about sanitizing the svg-file from JFreeSVG with svgo or svgcleaner or nano or else? And as a side effect you’d have the file optimized, ie. a smaller size (lossless I suppose) … and are you sure that the ;;-issue is the only bug? After sanitizing you’ll never know but that should be ok. I’ve checked this. For your example it’s ok.
svgo in.svg in.svg: Done in 24 ms! 0.091 KiB - 26.9% = 0.066 KiB
svgcleaner /Users/hp/in2.svg /Users/hp/out2.svg Your image is 9.36% smaller now.
,__, {o,o} ./)_) -»-»-
On 9. May 2022, at 19:01, Heinrich Paeßens via ntg-context
mailto:ntg-context@ntg.nl> wrote: Yes, now I see, but isn’t there sth missing in the export from JFreeSVG, that were supposed to fill in between the semicolons? If not, why don’t you just post-process, if possible … … sth like
gsed ’s/;;/;/g' in.svg > out.svg
;-)
On 9. May 2022, at 17:42, Thangalin
mailto:thangalin@gmail.com> wrote: Hi Heinrich,
Use the SVG I provided. R and Renjin use two different SVG generators. Renjin uses JFreeSVG when exporting as SVG. As you pointed out, there are no issues with R because it will export an SVG file without any double semicolons.
In other words, try this:
\startbuffer[svg] <svg> <rect width="100" height="100" style="stroke:rgb(0,0,0);;fill:none" /> </svg> \stopbuffer
\starttext \placefigure{}{\includesvgbuffer[svg][conversion=mp]} \stoptext
If you get a black square, that's the bug. If you get a white square, then there's something different about our environment setups.
Cheers!
On Mon, May 9, 2022 at 1:55 AM Heinrich Paeßens
mailto:paessens@me.com> wrote: Hi there I can compile your example without any tweaks, hence could not reproduce any error.
cheers Heinrich
———
R version 4.2.0 (2022-04-22) -- "Vigorous Calisthenics" Copyright (C) 2022 The R Foundation for Statistical Computing Platform: x86_64-apple-darwin17.0 (64-bit)
[R.app GUI 1.78 (8075) x86_64-apple-darwin17.0]
svg("/Users/hp/filename.svg"); plot(rnorm(200)); dev.off() null device 1
———
% !TEX program = lmtx
\starttext \externalfigure[/Users/hp/filename.svg][conversion=mp] \stoptext
———
On 9. May 2022, at 08:10, Thangalin via ntg-context
mailto:ntg-context@ntg.nl> wrote: Here's a screenshot comparing ConTeXt's PDF output (left) with KeenWrite's preview for the same SVG document:
https://i.ibb.co/68nqwrg/render-r-plot.png https://i.ibb.co/68nqwrg/render-r-plot.png
I've filed a bug against Renjin's SVG exporter.
Any guidance on how to fix this is greatly appreciated.
___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl mailto:ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl http://www.pragma-ade.nl/ / http://context.aanhet.net http://context.aanhet.net/ archive : https://bitbucket.org/phg/context-mirror/commits/ https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net http://contextgarden.net/ ___________________________________________________________________________________
___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl mailto:ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl http://www.pragma-ade.nl/ / http://context.aanhet.net http://context.aanhet.net/ archive : https://bitbucket.org/phg/context-mirror/commits/ https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net http://contextgarden.net/ ___________________________________________________________________________________
That's another good idea Heinrich. I certainly could invoke another application to sanitize the SVG, but that brings with it a number of additional problems: Does the user have it installed properly? Is it cross-platform? Additionally, the typesetting code (in Java) would have to be updated to call out to sanitize the file, plus introducing more error handling for when sanitizing goes wrong. Cleaning up the input document feels more like a band-aid than solving the underlying problem, which is to relax the regex ConTeXt uses to parse the style attribute. I'm pretty sure I can provide a patch for the regex, I just need to know how to get debugging information printed to the console when compiling the document using the context command. Any ideas about how to log strings after modifying mlib-svg.lmt? I tried adding print/report statements, but none of them showed up. Does anyone know if that's even the right file to change to start looking into the issue? Thanks again!
participants (2)
-
Heinrich Paeßens
-
Thangalin