- private static int stringToColor(String s) {
- // FIXME support three-char strings by doubling digits
- if (s == null) return 0x00000000;
- else if (SVG.colors.get(s) != null) return 0xFF000000 | toInt(SVG.colors.get(s));
- else if (s.length() == 7 && s.charAt(0) == '#') try {
- // FEATURE alpha
- return 0xFF000000 |
- (Integer.parseInt(s.substring(1, 3), 16) << 16) |
- (Integer.parseInt(s.substring(3, 5), 16) << 8) |
- Integer.parseInt(s.substring(5, 7), 16);
- } catch (NumberFormatException e) {
- Log.info(Box.class, "invalid color " + s);
- return 0;
- }
- else return 0; // FEATURE: error?
- }
-
- private static String colorToString(int argb) {
- if ((argb & 0xFF000000) == 0) return null;
- String red = Integer.toHexString((argb & 0x00FF0000) >> 16);
- String green = Integer.toHexString((argb & 0x0000FF00) >> 8);
- String blue = Integer.toHexString(argb & 0x000000FF);
- if (red.length() < 2) red = "0" + red;
- if (blue.length() < 2) blue = "0" + blue;
- if (green.length() < 2) green = "0" + green;
- return "#" + red + green + blue;
- }
-