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

SwiftSVG crashes with floating value format #12

Closed
naan opened this issue Apr 29, 2016 · 3 comments
Closed

SwiftSVG crashes with floating value format #12

naan opened this issue Apr 29, 2016 · 3 comments

Comments

@naan
Copy link

naan commented Apr 29, 2016

SwiftSVG crashes with the following floating point value:

"M186.999998 336.769903 L0 129.0625 L0 7.10542736e-15 L186.999998 336.769903 Z"
assertion failed: Invalid character "e" found: file SwiftSVG/SwiftSVG/String+SVG.swift, line 494
@mchoe
Copy link
Owner

mchoe commented May 4, 2016

Hi @naan, thanks for filing the issue and the commit to fix this. Seeing this is an issue of the SVG generator not properly dealing with floating point rounding, and not one from the library, I'm not entirely convinced that the change should get merged in yet.

Can you tell me what program you're using to generate your SVGs?

@naan
Copy link
Author

naan commented May 4, 2016

Yeah, I realized that after I made a change, so I dug into this issue.

The application I'm generating SVG is Sketch, and here's original code:


<svg width="381px" height="520px" viewBox="-4 -7 381 520" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <!-- Generator: Sketch 3.7.2 (28276) - http://www.bohemiancoding.com/sketch -->
    <desc>Created with Sketch.</desc>
    <defs></defs>
    <polygon id="Path-12" stroke="none" fill-opacity="0.300000012" fill="#FFC64D" fill-rule="evenodd" style="mix-blend-mode: multiply;" points="187.136435 512.08631 0 302.480469 0 166.554688"></polygon>
    <polygon id="Path-12-Copy" stroke="none" fill-opacity="0.300000012" fill="#FFC64D" fill-rule="evenodd" style="mix-blend-mode: multiply;" transform="translate(281.499999, 343.701358) scale(-1, 1) translate(-281.499999, -343.701358) " points="374.999998 512.08631 188 304.378906 188 175.316406"></polygon>
    <polygon id="Path-13" stroke="none" fill-opacity="0.300000012" fill="#FFC64D" fill-rule="evenodd" style="mix-blend-mode: multiply;" points="187.93703 511.744987 1.42108547e-14 107.175781 1.42108547e-14 2.84217094e-14 35.8710953 2.84217094e-14"></polygon>
    <polygon id="Path-13-Copy" stroke="none" fill-opacity="0.300000012" fill="#FFC64D" fill-rule="evenodd" style="mix-blend-mode: multiply;" transform="translate(281.500000, 255.872494) scale(-1, 1) translate(-281.500000, -255.872494) " points="374.999999 511.744987 188 71.234375 188 0 223.292965 0"></polygon>
    <polygon id="Path-16" stroke="none" fill-opacity="0.300000012" fill="#FFC64D" fill-rule="evenodd" style="mix-blend-mode: multiply;" points="190.454104 511.745614 77.3398438 1.90734863e-06 169.488281 -2.84217094e-14"></polygon>
    <polygon id="Path-16-Copy" stroke="none" fill-opacity="0.300000012" fill="#FFC64D" fill-rule="evenodd" style="mix-blend-mode: multiply;" transform="translate(239.681641, 255.685072) scale(-1, 1) translate(-239.681641, -255.685072) " points="291.363282 511.370144 188 5.26313499e-06 257.167973 0"></polygon>
    <polygon id="Path-18" stroke="none" fill-opacity="0.300000012" fill="#FFC64D" fill-rule="evenodd" style="mix-blend-mode: multiply;" points="191.637218 510.559211 374.999996 346.773437 374.999996 440.890623"></polygon>
    <polygon id="Path-19" stroke="none" fill-opacity="0.300000012" fill="#FFC64D" fill-rule="evenodd" style="mix-blend-mode: multiply;" points="191.186873 509.039787 3.82425696e-07 350.667969 1.03732987e-06 429.853874"></polygon>
    <polygon id="Path-20" stroke="none" fill-opacity="0.300000012" fill="#FFC64D" fill-rule="evenodd" style="mix-blend-mode: multiply;" points="190.078634 508.659931 -5.25835276e-07 463.644531 -7.17046191e-08 508.659931"></polygon>
    <polygon id="Path-20-Copy" stroke="none" fill-opacity="0.300000012" fill="#FFC64D" fill-rule="evenodd" style="mix-blend-mode: multiply;" transform="translate(288.000000, 489.083731) scale(-1, 1) translate(-288.000000, -489.083731) " points="375 509.108866 201.000001 469.058594 201 509.108868"></polygon>
</svg>

As you pointed out, there're floating point value that is not properly rounded, and probably Sketch's error. (I assume they're using their own SVG code.) However, if I import this SVG code into say Adobe Illustrator, they handle values properly.

@mchoe
Copy link
Owner

mchoe commented May 5, 2016

Alright, I may still incorporate the change, but I want to do some benchmarking first. Thanks for sending the full SVG along and the help @naan.

@mchoe mchoe closed this as completed May 5, 2016
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

2 participants