lairabalmeida / svg-android

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

Incomplete attribute units support leads to NumberFormatException #30

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create an SVG file in GIMP, which by default uses inches for width and 
height attributes of SVG.
2. Try to load the file using the library.
3. You'll get a stack with exceptions, something like this:

04-29 23:17:22.189: E/AndroidRuntime(331): java.lang.RuntimeException: Unable 
to start activity 
ComponentInfo{com.example.graphics.svg/com.example.graphics.svg.SVGTestActivity}
: com.larvalabs.svgandroid.SVGParseException: java.lang.NumberFormatException
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
android.os.Handler.dispatchMessage(Handler.java:99)
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
android.os.Looper.loop(Looper.java:123)
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
android.app.ActivityThread.main(ActivityThread.java:3683)
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
java.lang.reflect.Method.invokeNative(Native Method)
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
java.lang.reflect.Method.invoke(Method.java:507)
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
dalvik.system.NativeStart.main(Native Method)
04-29 23:17:22.189: E/AndroidRuntime(331): Caused by: 
com.larvalabs.svgandroid.SVGParseException: java.lang.NumberFormatException
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
com.larvalabs.svgandroid.SVGParser.parse(Unknown Source)
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
com.larvalabs.svgandroid.SVGParser.getSVGFromResource(Unknown Source)
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
com.example.graphics.svg.SVGTestActivity.onCreate(SVGTestActivity.java:22)
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
04-29 23:17:22.189: E/AndroidRuntime(331):  ... 11 more
04-29 23:17:22.189: E/AndroidRuntime(331): Caused by: 
java.lang.NumberFormatException
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
org.apache.harmony.luni.util.FloatingPointParser.parseFltImpl(Native Method)
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
org.apache.harmony.luni.util.FloatingPointParser.parseFloat(FloatingPointParser.
java:321)
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
java.lang.Float.parseFloat(Float.java:323)
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
com.larvalabs.svgandroid.SVGParser.getFloatAttr(Unknown Source)
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
com.larvalabs.svgandroid.SVGParser.getFloatAttr(Unknown Source)
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
com.larvalabs.svgandroid.SVGParser.access$700(Unknown Source)
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
com.larvalabs.svgandroid.SVGParser$SVGHandler.startElement(Unknown Source)
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
org.apache.harmony.xml.ExpatParser.startElement(ExpatParser.java:145)
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
org.apache.harmony.xml.ExpatParser.appendBytes(Native Method)
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:518)
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:479)
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:318)
04-29 23:17:22.189: E/AndroidRuntime(331):  at 
org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:275)
04-29 23:17:22.189: E/AndroidRuntime(331):  ... 16 more

What is the expected output? What do you see instead?
The SVG-file should be displayed.

What version of the product are you using? On what operating system?
The latest 1.1.

Please provide any additional information below.
The problem is in line 601 of SVGParser which processes only "px" suffix of 
attributes, whereas a file may contain "in" as well. Currently, if an attribute 
is specified as, for example, "200in", the library passes the value as is for 
float parsing, which is incorrect float, of course.

Original issue reported on code.google.com by mo...@tushino.ru on 29 Apr 2012 at 7:29

GoogleCodeExporter commented 8 years ago
Same issue with "mm" as size.

Original comment by jpg21...@gmail.com on 24 Aug 2013 at 9:06