BluesZhang / svg-android-2

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

Fix for colors expressed as three-digits hexadecimal #xxx #1

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
From http://www.w3.org/TR/SVG/types.html#DataTypeColor: "The format of an RGB 
value in hexadecimal notation is a "#" immediately followed by either three or 
six hexadecimal characters. The three-digit RGB notation (#rgb) is converted 
into six-digit form (#rrggbb) by replicating digits, not by adding zeros. For 
example, #fb0 expands to #ffbb00."

This is the fixed getColorValue, starting at line 801 of SVGParser.java

        public Integer getColorValue(String name) {
            String v = getAttr(name);
            if (v == null) {
                return null;
            } else if (v.startsWith("#")) {
                try {
                    String hc = v.substring(1);
                    if (hc.length() == 3) {
                        hc = new String(new char[] {
                                hc.charAt(0), hc.charAt(0),
                                hc.charAt(1), hc.charAt(1),
                                hc.charAt(2), hc.charAt(2),
                                }); 
                    }
                    return Integer.parseInt(hc, 16);
                } catch (NumberFormatException nfe) {
                    // todo - parse word-based color here
                    return null;
                }
            } else {
                return SVGColors.mapColor(v);
            }
        }

Original issue reported on code.google.com by neclep...@gmail.com on 21 Oct 2011 at 6:38

GoogleCodeExporter commented 9 years ago
I checked in a slightly different fix for this issue.  Let me know if it 
doesn't 
work fro you

Original comment by suh...@google.com on 24 Oct 2011 at 11:00