Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue when generating gradiant #28

Closed
NitroG42 opened this issue Mar 21, 2019 · 3 comments
Closed

Issue when generating gradiant #28

NitroG42 opened this issue Mar 21, 2019 · 3 comments

Comments

@NitroG42
Copy link

I'm joining the svg as attachment.
The first issue is using s2v -i ~/Downloads/warning.svg -o warning.xml it triggers the following issue:
Error floatPrecision is not defined while converting file warning.svg
Displaying the stacktrace show:

ReferenceError: floatPrecision is not defined
at JS2XML.addGradientToElement (/usr/local/lib/node_modules/svg2vectordrawable/lib/svg-to-vectordrawable.js:400:51)
at gradientPaths.forEach.path (/usr/local/lib/node_modules/svg2vectordrawable/lib/svg-to-vectordrawable.js:193:30)
at Array.forEach ()
at elemGradients.forEach.gradient (/usr/local/lib/node_modules/svg2vectordrawable/lib/svg-to-vectordrawable.js:192:35)
at Array.forEach ()
at JS2XML.refactorData (/usr/local/lib/node_modules/svg2vectordrawable/lib/svg-to-vectordrawable.js:187:23)
at JS2XML.convert (/usr/local/lib/node_modules/svg2vectordrawable/lib/svg-to-vectordrawable.js:557:10)
at result (/usr/local/lib/node_modules/svg2vectordrawable/lib/svg-to-vectordrawable.js:691:44)
at SAXParser.sax.onend (/usr/local/lib/node_modules/svg2vectordrawable/node_modules/svgo/lib/svgo/svg2js.js:169:13)
at emit (/usr/local/lib/node_modules/svg2vectordrawable/node_modules/sax/lib/sax.js:624:35)

I fixed the error by first putting 2 instead of floatPrecision, then using the floatPrecision.

In both case, the generated vectordrawable isn't usable by Android, it displays nothing.
It seems the issue comes from the path generated.
I'm joining both result and android-studio-generated xml.
Thank you for your great tool!
issue.zip

@Ashung
Copy link
Owner

Ashung commented Mar 21, 2019

In some case SVGO does not remove transform, but I ingore this. svg/svgo#624 sketch-hq/svgo-compressor#20

input

svgo -s '<?xml version="1.0" encoding="UTF-8"?>
<svg width="121px" height="102px" viewBox="0 0 121 102" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <!-- Generator: Sketch 53.1 (72631) - https://sketchapp.com -->
    <title>warning</title>
    <desc>Created with Sketch.</desc>
    <defs>
        <linearGradient x1="102.560139%" y1="97.6856033%" x2="0%" y2="97.6856033%" id="linearGradient-1">
            <stop stop-color="#2A5595" offset="0%"></stop>
            <stop stop-color="#B53D85" offset="100%"></stop>
        </linearGradient>
    </defs>
        <g id="Home-no-connection" transform="translate(-127.000000, -227.000000)" fill="url(#linearGradient-1)" fill-rule="nonzero">
            <path d="M180.105497,231.909955 C184.191641,225.355541 190.826327,225.371161 194.902733,231.909955 L245.553407,313.156592 C251.008366,321.906664 247.034809,329 236.683375,329 L138.324855,329 C127.971113,329 123.982247,321.934923 129.454823,313.156592 L180.105497,231.909955 Z M184.468173,233.653848 L132.786982,316.453805 C130.0527,320.834479 132.047274,324.343762 137.209685,324.343762 L237.637808,324.34376 C242.745533,324.34376 244.780181,320.811306 242.060177,316.453803 L190.375495,233.653848 C188.749314,231.048671 186.09938,231.040444 184.468173,233.653848 Z M187.505869,259.15643 C184.91214,259.15643 182.809508,261.265875 182.809508,263.79884 L182.809508,291.763925 C182.809508,294.327857 184.894057,296.406334 187.505869,296.406334 C190.099597,296.406334 192.20223,294.296889 192.20223,291.763925 L192.20223,263.79884 C192.20223,261.234908 190.11768,259.15643 187.505869,259.15643 L187.505869,259.15643 Z M187.505869,315.031286 C190.099597,315.031286 192.20223,312.946618 192.20223,310.375048 C192.20223,307.803479 190.099597,305.71881 187.505869,305.71881 C184.91214,305.71881 182.809508,307.803479 182.809508,310.375048 C182.809508,312.946618 184.91214,315.031286 187.505869,315.031286 L187.505869,315.031286 Z" id="warning"></path>
        </g>
</svg>'

output

<svg width="121" height="102" xmlns="http://www.w3.org/2000/svg">
<defs>
<linearGradient x1="102.56%" y1="97.686%" x2="0%" y2="97.686%" id="a">
<stop stop-color="#2A5595" offset="0%"/>
<stop stop-color="#B53D85" offset="100%"/>
</linearGradient>
</defs>
<path d="M180.105 231.91c4.087-6.554 10.721-6.539 14.798 0l50.65 81.247c5.455 8.75 1.482 15.843-8.87 15.843h-98.358c-10.354 0-14.343-7.065-8.87-15.843l50.65-81.247zm4.363 1.744l-51.681 82.8c-2.734 4.38-.74 7.89 4.423 7.89h100.428c5.108 0 7.142-3.533 4.422-7.89l-51.685-82.8c-1.626-2.605-4.276-2.614-5.907 0zm3.038 25.502c-2.594 0-4.696 2.11-4.696 4.643v27.965c0 2.564 2.084 4.642 4.696 4.642 2.594 0 4.696-2.11 4.696-4.642v-27.965c0-2.564-2.084-4.643-4.696-4.643zm0 55.875c2.594 0 4.696-2.084 4.696-4.656 0-2.572-2.102-4.656-4.696-4.656s-4.696 2.084-4.696 4.656c0 2.572 2.102 4.656 4.696 4.656z" transform="translate(-127 -227)" fill="url(#a)"/>
</svg>

input

svgo -s '<?xml version="1.0" encoding="UTF-8"?>
<svg width="121px" height="102px" viewBox="0 0 121 102" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g transform="translate(-127.000000, -227.000000)" fill="#000" fill-rule="nonzero">
    <path d="M180.105497,231.909955 C184.191641,225.355541 190.826327,225.371161 194.902733,231.909955 L245.553407,313.156592 C251.008366,321.906664 247.034809,329 236.683375,329 L138.324855,329 C127.971113,329 123.982247,321.934923 129.454823,313.156592 L180.105497,231.909955 Z M184.468173,233.653848 L132.786982,316.453805 C130.0527,320.834479 132.047274,324.343762 137.209685,324.343762 L237.637808,324.34376 C242.745533,324.34376 244.780181,320.811306 242.060177,316.453803 L190.375495,233.653848 C188.749314,231.048671 186.09938,231.040444 184.468173,233.653848 Z M187.505869,259.15643 C184.91214,259.15643 182.809508,261.265875 182.809508,263.79884 L182.809508,291.763925 C182.809508,294.327857 184.894057,296.406334 187.505869,296.406334 C190.099597,296.406334 192.20223,294.296889 192.20223,291.763925 L192.20223,263.79884 C192.20223,261.234908 190.11768,259.15643 187.505869,259.15643 L187.505869,259.15643 Z M187.505869,315.031286 C190.099597,315.031286 192.20223,312.946618 192.20223,310.375048 C192.20223,307.803479 190.099597,305.71881 187.505869,305.71881 C184.91214,305.71881 182.809508,307.803479 182.809508,310.375048 C182.809508,312.946618 184.91214,315.031286 187.505869,315.031286 L187.505869,315.031286 Z"></path>
</g>
</svg>'

output

<svg width="121" height="102" xmlns="http://www.w3.org/2000/svg">
<path d="M53.105 4.91c4.087-6.554 10.721-6.539 14.798 0l50.65 81.247c5.455 8.75 1.482 15.843-8.87 15.843H11.325C.97 102-3.018 94.935 2.455 86.157L53.105 4.91zm4.363 1.744l-51.681 82.8c-2.734 4.38-.74 7.89 4.423 7.89h100.428c5.108 0 7.142-3.533 4.422-7.89l-51.685-82.8c-1.626-2.605-4.276-2.614-5.907 0zm3.038 25.502c-2.594 0-4.696 2.11-4.696 4.643v27.965c0 2.564 2.084 4.642 4.696 4.642 2.594 0 4.696-2.11 4.696-4.642V36.799c0-2.564-2.084-4.643-4.696-4.643zm0 55.875c2.594 0 4.696-2.084 4.696-4.656 0-2.572-2.102-4.656-4.696-4.656s-4.696 2.084-4.696 4.656c0 2.572 2.102 4.656 4.696 4.656z"/>
</svg>

@JohannesKrohn
Copy link

I have the same error but there is no transform involved:
Input:

<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 48 48">
  <defs>
    <linearGradient id="cloud1-a" x1="34.393%" x2="85.57%" y1="39.111%" y2="60.889%">
      <stop offset="0%" stop-color="#ECF0F9"/>
      <stop offset="100%" stop-color="#D9E2F2"/>
    </linearGradient>
  </defs>
  <g fill="none" fill-rule="evenodd">
    <polygon points="0 0 48 0 48 48 0 48"/>
    <path fill="url(#cloud1-a)" d="M35 25a4 4 0 1 1 0 8H13a4 4 0 1 1 0-8h.07a7.002 7.002 0 0 1 13.44-1.58A5.001 5.001 0 0 1 34.584 25h.415z"/>
  </g>
</svg>

Ashung pushed a commit that referenced this issue Mar 23, 2019
- Fix SVGO do not move transform from group to path which have id attribute. #28
- Fix SVGO do not apply transform to path that attribute value is url(). #28
@Ashung
Copy link
Owner

Ashung commented Mar 23, 2019

Fixed update 2.6.11.

@Ashung Ashung closed this as completed Mar 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants