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

NumberFormatException: Invalid float for certain SVGs #4

Closed
teslacoil opened this issue Jan 9, 2015 · 10 comments
Closed

NumberFormatException: Invalid float for certain SVGs #4

teslacoil opened this issue Jan 9, 2015 · 10 comments
Assignees

Comments

@teslacoil
Copy link

Some SVGs remove spaces between floating point numbers that start with a "." (eg "1.11.89" is two floats, 1.11 and .89). Android does not handle this. It can be fixed by adding spaces (eg "1.11 .89").

Example https://github.com/google/material-design-icons/blob/master/av/svg/production/ic_play_shopping_bag_24px.svg

See https://stackoverflow.com/questions/27561170/vectordrawable-causes-numberformatexception

@yuraj11 yuraj11 self-assigned this Jan 9, 2015
@eboye
Copy link

eboye commented Jan 13, 2015

After path replace line https://github.com/inloop/svg2android/blob/gh-pages/js/main.js#L155

I've added this code:

path = path.replace(/(\ |-)./g, " 0.");

and it works flawlessly :)

@yuraj11
Copy link
Collaborator

yuraj11 commented Jan 13, 2015

Thanks for report.
eboye, that line was not working for me properly, i have added this:
path = path.replace(/(\.\d+)(\.\d)/g, "\$1 \$2");
It's pushed, could you test It guys?

@eboye
Copy link

eboye commented Jan 14, 2015

@yuraj11 yes, it does work :) Maybe I haven't covered all the situations with my regex.

Thanks for the fix.

I don't know if I should start a new issue, but when is added, it always messes from which XY coordinate it should start for the second path. I don't know if this is fixable at all.

edit: the problem is with no fill path ... once removed everything works as expected ;)

@yuraj11
Copy link
Collaborator

yuraj11 commented Jan 16, 2015

If there is another issue not related to this please create new issue.

@yuraj11 yuraj11 closed this as completed Jan 16, 2015
@teslacoil
Copy link
Author

It seems that regex still doesn't work for some SVGs (looks like it might need to be run multiple times), such as https://github.com/google/material-design-icons/blob/master/action/svg/production/ic_history_24px.svg :

Caused by: java.lang.NumberFormatException: Invalid float: ".07.14"

9H1l3.89 3.89.07.14L9 12H6c0-3.87

@yuraj11 yuraj11 reopened this Jan 23, 2015
@yuraj11
Copy link
Collaborator

yuraj11 commented Jan 23, 2015

Not sure, but I have tried changing It to .07 .14 but got this weird result in preview:
deformed_svg
android svg renderer bug or something else hm

@teslacoil
Copy link
Author

I noticed that too after changing it by hand. I'm guessing it's an android bug and not an issue with svg2android. We've had to manually tune some SVGs before converting them (not just converting polygons into paths, but sometimes fudging the paths a bit so they don't have completely straight lines)

@yuraj11
Copy link
Collaborator

yuraj11 commented Jan 26, 2015

@teslacoil I have changed regex a bit so number format should be fixed now, please check It. We can create new issue for rendering bug and see If there is a workaround.

@yuraj11
Copy link
Collaborator

yuraj11 commented Jan 26, 2015

found problem with weird rendering - It is bug in svg2android, I have tried changing M to m and was rendered correctly, must explore this.

Edit: #8 fixed It 🔨 tried a few icons from /google/material-design-icons and It works fine

@yuraj11 yuraj11 closed this as completed Jan 26, 2015
@snodnipper
Copy link

https://code.google.com/p/android/issues/detail?id=202670

Reported the issue before establishing the cause (old graphics)

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