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 via email to