cppfw / svgren

:camera: SVG rendering library in C++
MIT License
206 stars 41 forks source link

White square with masks and use #44

Closed MobileSam closed 6 years ago

MobileSam commented 6 years ago

Hello,

We found a similar issue as before (white rectangle image) with masks. My hunch would be the special node <use [...]></use> but I'm not sure.

I'm attaching the non-working SVG and an updated version of the same SVG that works.

caltrain-non-working.svg

<?xml version="1.0" encoding="UTF-8"?>
<svg width="68px" height="68px" viewBox="0 0 68 68" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <!-- Generator: Sketch 47.1 (45422) - http://www.bohemiancoding.com/sketch -->
    <title>Page 1</title>
    <desc>Created with Sketch.</desc>
    <defs>
        <polygon id="path-1" points="34.00945 -0.0001 0 -0.0001 0 68.0009 34.00945 68.0009 68.0189 68.0009 68.0189 -0.0001"></polygon>
    </defs>
    <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
        <g>
            <mask id="mask-2" fill="white">
                <use xlink:href="#path-1"></use>
            </mask>
            <g id="Clip-2"></g>
            <path d="M40.4039,1.9929 C42.9709,1.9929 45.2869,2.2649 47.4009,2.7449 C43.2899,0.9799 38.7639,-0.0001 34.0089,-0.0001 C15.2359,-0.0001 -0.0001,15.2369 -0.0001,34.0039 C-0.0001,42.4059 3.0609,50.0939 8.1189,56.0279 C4.9529,50.5279 4.2229,43.1359 5.8389,34.8209 C9.3269,16.8639 20.8309,1.9929 40.4039,1.9929 M59.6469,11.6829 C61.7139,15.6969 62.4359,20.8359 61.7519,26.9309 L61.6979,26.9309 L61.5019,28.0819 L43.8189,28.0819 C44.8989,21.7639 43.8959,15.9559 37.8689,15.9559 C29.4399,15.9559 26.5569,28.9289 25.4119,34.8209 C24.2009,41.0759 22.5029,51.6929 31.1089,51.6929 C36.5839,51.6929 39.7979,47.2219 41.7189,41.3059 L59.2119,41.3059 C54.7749,56.7649 42.5559,66.0199 28.2359,66.0199 C25.1629,66.0199 22.4079,65.6469 19.9539,64.9569 C24.2399,66.9059 28.9959,68.0009 34.0089,68.0009 C52.7829,68.0009 68.0189,52.7699 68.0189,34.0039 C68.0189,25.4619 64.8559,17.6579 59.6469,11.6829" id="Fill-1" fill="#000000" mask="url(#mask-2)"></path>
        </g>
    </g>
</svg>

caltrain-working.svg

<?xml version="1.0" encoding="UTF-8"?>
<svg width="68px" height="68px" viewBox="0 0 68 68" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  <defs><mask id="mask">
    <polygon fill="#000000" points="34.00945 -0.0001 0 -0.0001 0 68.0009 34.00945 68.0009 68.0189 68.0009 68.0189 -0.0001"></polygon>
    <path fill="#ffffff" d="M40.4039,1.9929 C42.9709,1.9929 45.2869,2.2649 47.4009,2.7449 C43.2899,0.9799 38.7639,-0.0001 34.0089,-0.0001 C15.2359,-0.0001 -0.0001,15.2369 -0.0001,34.0039 C-0.0001,42.4059 3.0609,50.0939 8.1189,56.0279 C4.9529,50.5279 4.2229,43.1359 5.8389,34.8209 C9.3269,16.8639 20.8309,1.9929 40.4039,1.9929 M59.6469,11.6829 C61.7139,15.6969 62.4359,20.8359 61.7519,26.9309 L61.6979,26.9309 L61.5019,28.0819 L43.8189,28.0819 C44.8989,21.7639 43.8959,15.9559 37.8689,15.9559 C29.4399,15.9559 26.5569,28.9289 25.4119,34.8209 C24.2009,41.0759 22.5029,51.6929 31.1089,51.6929 C36.5839,51.6929 39.7979,47.2219 41.7189,41.3059 L59.2119,41.3059 C54.7749,56.7649 42.5559,66.0199 28.2359,66.0199 C25.1629,66.0199 22.4079,65.6469 19.9539,64.9569 C24.2399,66.9059 28.9959,68.0009 34.0089,68.0009 C52.7829,68.0009 68.0189,52.7699 68.0189,34.0039 C68.0189,25.4619 64.8559,17.6579 59.6469,11.6829"></path>
  </mask></defs>

  <rect width="100%" height="100%" mask="url(#mask)"/>
</svg>
igagis commented 6 years ago

I'll have a look tomorrow. Thanks for reporting!

igagis commented 6 years ago

Bug fixed. Please try svgren version 0.4.46. The problem was in that <mask> element is outside of the <defs> and it was picked up by renderer as usual visible element and rendered to the primary image instead of mask image. Now I made it so that <mask> is not rendered even if placed outside of <defs>.