toyluck / svg-android

Automatically exported from code.google.com/p/svg-android
0 stars 0 forks source link

whitespace handling bug in ParserHelper.parseFloat() #1

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. use the following simple example taken (and simplified) from here: 
http://www.w3.org/TR/SVGTiny12/paths.html#PathData

<?xml version="1.0"?>
<svg width="400" height="400" viewBox="0 0 400 400" 
xmlns="http://www.w3.org/2000/svg" version="1.2" baseProfile="tiny">
  <path d="M 100 100 L 300 100 L 200 300 z"
        fill="#ff0000" stroke="#0000ff" stroke-width="3" />
</svg>

2. the spaces in the path data cause NaNs when parsing the X values.

What version of the product are you using? On what operating system?
Latest from svn

Please provide any additional information below.
A snippet of the ParserHelper.parseFloat() method is below, with a line added 
to ignore space chars (the line marked // fix)

    public float parseFloat() {
        int     mant     = 0;
        int     mantDig  = 0;
        boolean mantPos  = true;
        boolean mantRead = false;

        int     exp      = 0;
        int     expDig   = 0;
        int     expAdj   = 0;
        boolean expPos   = true;

        switch (current) {
        case '-':
            mantPos = false;
            // fallthrough
        case '+':
            current = read();
            break;
        case ' ': current = read(); // fix
        }

Original issue reported on code.google.com by jamie.mc...@gmail.com on 15 May 2011 at 10:25

GoogleCodeExporter commented 8 years ago
That suggested fix is no good if the space is followed by:
'-'
'+'
or another space (although it shouldn't be).
A call to skip the whitespace needs to instead be done prior to the parseing of 
the float.

Original comment by jamie.mc...@gmail.com on 16 May 2011 at 6:08

GoogleCodeExporter commented 8 years ago
Try the latest version (1.1) which should resolve the issue.

Original comment by watkin...@gmail.com on 17 May 2011 at 7:35

GoogleCodeExporter commented 8 years ago
Yes - that has fixed it, thanks.

Original comment by jamie.mc...@gmail.com on 17 May 2011 at 8:46

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
I've tried to load picture 
http://lib.custis.ru/images/generated/pic_svg/2/2c/2c1c5e7fa7d19e5944348476538ed
cff/pic_svg.source.svg

java code:
SVG svg;
/*android.svg from 
http://code.google.com/p/svg-android/downloads/detail?name=android.svg&can=2&q= 
for test
*/
//parse fine, tried to draw after - looks great!
svg = SVGParser.getSVGFromResource(getResources(), R.raw.android);
        svgPic = svg.getPicture();
//parseFloat exception (see logcat below)
svg = SVGParser.getSVGFromResource(getResources(), R.raw.inkscape_logo);
        octaves = svg.getPicture();

LogCat:

11-12 16:30:44.110: W/dalvikvm(675): threadid=3: thread exiting with uncaught 
exception (group=0x4001b188)
11-12 16:30:44.114: E/AndroidRuntime(675): Uncaught handler: thread main 
exiting due to uncaught exception
11-12 16:30:44.345: E/AndroidRuntime(675): java.lang.RuntimeException: Unable 
to start activity 
ComponentInfo{com.appspot.alexeyslepov.melodybird/com.appspot.alexeyslepov.melod
ybird.GameActivity}: android.view.InflateException: Binary XML file line #26: 
Error inflating class com.appspot.alexeyslepov.melodybird.Game
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
android.app.ActivityThread.access$2200(ActivityThread.java:119)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
android.os.Handler.dispatchMessage(Handler.java:99)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
android.os.Looper.loop(Looper.java:123)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
android.app.ActivityThread.main(ActivityThread.java:4363)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
java.lang.reflect.Method.invokeNative(Native Method)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
java.lang.reflect.Method.invoke(Method.java:521)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
dalvik.system.NativeStart.main(Native Method)
11-12 16:30:44.345: E/AndroidRuntime(675): Caused by: 
android.view.InflateException: Binary XML file line #26: Error inflating class 
com.appspot.alexeyslepov.melodybird.Game
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
android.view.LayoutInflater.createView(LayoutInflater.java:513)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
android.view.LayoutInflater.inflate(LayoutInflater.java:407)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
android.view.LayoutInflater.inflate(LayoutInflater.java:320)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
android.view.LayoutInflater.inflate(LayoutInflater.java:276)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198
)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
android.app.Activity.setContentView(Activity.java:1622)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
com.appspot.alexeyslepov.melodybird.GameActivity.onCreate(GameActivity.java:37)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
11-12 16:30:44.345: E/AndroidRuntime(675):  ... 11 more
11-12 16:30:44.345: E/AndroidRuntime(675): Caused by: 
java.lang.reflect.InvocationTargetException
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
com.appspot.alexeyslepov.melodybird.Game.<init>(Game.java:155)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
java.lang.reflect.Constructor.constructNative(Native Method)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
java.lang.reflect.Constructor.newInstance(Constructor.java:446)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
android.view.LayoutInflater.createView(LayoutInflater.java:500)
11-12 16:30:44.345: E/AndroidRuntime(675):  ... 21 more
11-12 16:30:44.345: E/AndroidRuntime(675): Caused by: 
com.larvalabs.svgandroid.SVGParseException: java.lang.NumberFormatException: 
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
com.larvalabs.svgandroid.SVGParser.parse(Unknown Source)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
com.larvalabs.svgandroid.SVGParser.getSVGFromResource(Unknown Source)
11-12 16:30:44.345: E/AndroidRuntime(675):  ... 25 more
11-12 16:30:44.345: E/AndroidRuntime(675): Caused by: 
java.lang.NumberFormatException: 
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
org.apache.harmony.luni.util.FloatingPointParser.parseFltImpl(Native Method)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
org.apache.harmony.luni.util.FloatingPointParser.parseFloat(FloatingPointParser.
java:321)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
java.lang.Float.parseFloat(Float.java:288)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
com.larvalabs.svgandroid.SVGParser.getFloatAttr(Unknown Source)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
com.larvalabs.svgandroid.SVGParser.getFloatAttr(Unknown Source)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
com.larvalabs.svgandroid.SVGParser.access$700(Unknown Source)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
com.larvalabs.svgandroid.SVGParser$SVGHandler.startElement(Unknown Source)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
org.apache.harmony.xml.ExpatParser.startElement(ExpatParser.java:145)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
org.apache.harmony.xml.ExpatParser.append(Native Method)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:506)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:467)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:329)
11-12 16:30:44.345: E/AndroidRuntime(675):  at 
org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:286)
11-12 16:30:44.345: E/AndroidRuntime(675):  ... 27 more

Original comment by alexey.s...@gmail.com on 12 Nov 2011 at 1:33

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
share please original SVG files that you show in SampleImages page 
http://code.google.com/p/svg-android/wiki/SampleImages
and what program did you use to do those images that are parsed properly by 
svg-android lib

Original comment by alexey.s...@gmail.com on 12 Nov 2011 at 2:37