Parses the "color" datatype only, and prints an error if it is not of this form. http://www.w3.org/TR/SVG/types.html#DataTypeColor @return 0xRRGGBB (no alpha). Zero on error.
(String colorText)
| 1315 | * @return 0xRRGGBB (no alpha). Zero on error. |
| 1316 | */ |
| 1317 | static protected int parseSimpleColor(String colorText) { |
| 1318 | colorText = colorText.toLowerCase().trim(); |
| 1319 | //if (colorNames.containsKey(colorText)) { |
| 1320 | if (colorNames.hasKey(colorText)) { |
| 1321 | return colorNames.get(colorText); |
| 1322 | } else if (colorText.startsWith("#")) { |
| 1323 | if (colorText.length() == 4) { |
| 1324 | // Short form: #ABC, transform to long form #AABBCC |
| 1325 | colorText = colorText.replaceAll("^#(.)(.)(.)$", "#$1$1$2$2$3$3"); |
| 1326 | } |
| 1327 | return (Integer.parseInt(colorText.substring(1), 16)) & 0xFFFFFF; |
| 1328 | //System.out.println("hex for fill is " + PApplet.hex(fillColor)); |
| 1329 | } else if (colorText.startsWith("rgb")) { |
| 1330 | return parseRGB(colorText); |
| 1331 | } else { |
| 1332 | System.err.println("Cannot parse \"" + colorText + "\"."); |
| 1333 | return 0; |
| 1334 | } |
| 1335 | } |
| 1336 | |
| 1337 | |
| 1338 | /** |
no test coverage detected