ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Max Chernoff <mseven@telus.net>
To: ntg-context <ntg-context@ntg.nl>
Subject: SVG converter bugs
Date: Thu, 06 Jul 2023 04:06:41 -0600	[thread overview]
Message-ID: <6e9aecebc28843c4976545295c45167dd451b57a.camel@telus.net> (raw)

Hi Hans,

I've been using the SVG->MP converter and I've found a few bugs. Most of
the bugs are with "weird" SVG input, but I have no control over the
input, and the metadata on most of the files shows that it was exported
from Adobe Illustrator which is (unfortunately) quite popular. I've
tested all of the below with the latest ConTeXt.



If you give Metapost an out-of-order gradient, it produces an invalid
PDF. Both pages in this example:

   \startbuffer[gradient]
   <svg viewBox="0 0 200 100" xmlns="http://www.w3.org/2000/svg">
       <defs>
           <linearGradient id="gradient" x1="0%" y1="0%" x2="0" y2="100%">
               <stop offset="0%" style="stop-color:green;" />
               <stop offset="75%" style="stop-color:green;" />
               <stop offset="25%" style="stop-color:blue;" />
               <stop offset="100%" style="stop-color:blue;" />
           </linearGradient>
       </defs>
   
       <rect x="0" y="0" width="100%" height="100%" fill="url(#gradient)" />
   </svg>
   \stopbuffer
   
   \starttext
   
   \startTEXpage
       \includesvgbuffer[gradient]
   \stopTEXpage
   
   \startMPpage
       fill unitsquare xyscaled (200,100)
           withshademethod "linear"
           withshadecenteronefraction (0,1)
           withshadecentertwofraction (0,0)
           withshadestep (
               withshadefraction 0
               withshadecolors (green, green)
           )
           withshadestep (
               withshadefraction 0.75
               withshadecolors (blue, green)
           )
           withshadestep (
               withshadefraction 0.25
               withshadecolors (green, blue)
           )
           withshadestep (
               withshadefraction 1
               withshadecolors (green, blue)
           )
   ;
   \stopMPpage
   
   \stoptext

write this to the PDF

   /Bounds [
     0
     0.75
     0.25
   ]

which is invalid and renders incorrectly in every PDF reader that I've
tested. This is what the SVG 1.1 spec has to say:

   Each gradient offset value is required to be equal to or greater than
   the previous gradient stop's offset value. If a given gradient stop's
   offset value is not equal to or greater than all previous offset values,
   then the offset value is adjusted to be equal to the largest of all
   previous offset values.



The following SVG renders incorrectly, but replacing the 0% stop with
the commented one fixes it:

   <svg viewBox="0 0 200 100" xmlns="http://www.w3.org/2000/svg">
       <defs>
           <linearGradient id="gradient" x1="0%" y1="0%" x2="0" y2="100%">
               <stop offset="0%" style="stop-color:#FFFFFF;" />
               <!--<stop offset="0%" style="stop-color:#FEFFFF;" />-->
               <stop offset="100%" style="stop-color:blue;" />
           </linearGradient>
       </defs>
   
       <rect x="0" y="0" width="100%" height="100%" fill="url(#gradient)" />
   </svg>



Using a gradient as the stroke colour outputs an invalid colour to
MetaPost. This example:

   \startbuffer[gradient]
   <svg viewBox="0 0 200 100" xmlns="http://www.w3.org/2000/svg">
       <defs>
           <linearGradient id="gradient" x1="0%" y1="0%" x2="0" y2="100%">
               <stop offset="0%" style="stop-color:green;" />
               <stop offset="100%" style="stop-color:blue;" />
           </linearGradient>
       </defs>
   
       <rect x="0" y="0" width="100%" height="100%" stroke="url(#gradient)" />
   </svg>
   \stopbuffer
   
   \startluacode
       print(metapost.svgtomp{data = buffers.getcontent("gradient")})
   \stopluacode

gives this output:

   [...]
   withcolor "url(#gradient)"
   [...]



"stop-opacity" seems to be ignored:

   \startbuffer[gradient]
   <svg viewBox="0 0 200 100" xmlns="http://www.w3.org/2000/svg">
       <defs>
           <linearGradient id="gradient" x1="0%" y1="0%" x2="0" y2="100%">
               <stop offset="0%" style="stop-color:red;" stop-opacity="1" />
               <stop offset="100%" style="stop-color:red;" stop-opacity="0" />
           </linearGradient>
       </defs>
   
       <rect x="0" y="0" width="100%" height="100%" fill="url(#gradient)" />
   </svg>
   \stopbuffer
   
   \startTEXpage
       \includesvgbuffer[gradient]
   \stopTEXpage



Finally, "display:none;" doesn't work:

   \startbuffer[gradient]
   <svg viewBox="0 0 200 100" xmlns="http://www.w3.org/2000/svg">
       <rect x="0" y="0" width="100%" height="100%" fill="black" style="display:none;" />
   </svg>
   \stopbuffer
   
   \startTEXpage
       \includesvgbuffer[gradient]
   \stopTEXpage


Thanks,
-- Max
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : https://contextgarden.net
___________________________________________________________________________________


                 reply	other threads:[~2023-07-06 10:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6e9aecebc28843c4976545295c45167dd451b57a.camel@telus.net \
    --to=mseven@telus.net \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).