pashapm / svg-android-2

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

Parse exception when <width> / <height> are in "pt" rather than in "px" #23

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have many SVGs that specify width and heght in "pt" rather than in "px", ie. 
<svg><width>200pt</width>...
The method parseFloat will throw an exception right at the start, and skip 
decoding the SVG.
The fix is super-easy, in SVGParser.java line 720:
---------------------------------

    private static Float getFloatAttr(String name, Attributes attributes, Float defaultValue) {
        String v = getStringAttr(name, attributes);
        if (v == null) {
            return defaultValue;
        } else {
            if (v.endsWith("px") || (v.endsWith("pt))) { // added by rlp@nebular.tv to handle "pt" too.  
                v = v.substring(0, v.length() - 2);
            }   

            //            Log.d(TAG, "Float parsing '" + name + "=" + v + "'");
            return Float.parseFloat(v);
        }
    }

---------------------------------
I am no expert in SVG units, maybe there are a few more missing, may be worth 
to strip whatever unit with a regex and parse the float?

Original issue reported on code.google.com by kowloon....@gmail.com on 30 Apr 2013 at 10:33

GoogleCodeExporter commented 9 years ago
Added support for all SVG units

Original comment by suh...@google.com on 7 Nov 2013 at 3:55