@Test public void testToHexColorString() { assertEquals("#000000", SVGAttributeParser.toHexColorString("#000000")); assertEquals("#123456", SVGAttributeParser.toHexColorString("#123456")); assertEquals("#0000ff", SVGAttributeParser.toHexColorString("#ff")); assertEquals("#0000ff", SVGAttributeParser.toHexColorString("blue")); assertEquals("#ff0000", SVGAttributeParser.toHexColorString("red")); assertEquals("#000000", SVGAttributeParser.toHexColorString("black")); assertEquals("#ff0000", SVGAttributeParser.toHexColorString("rgb(255,0,0)")); assertEquals("#0000ff", SVGAttributeParser.toHexColorString("rgb(0,0,255)")); }
public static String toHexColorString(final String raw) { if (raw.startsWith("#")) { return "#" + StringUtils.leftPad(raw.substring(1, raw.length()), 6, "0"); } if (raw.startsWith("rgb")) { Matcher m = RBG_PATTERN.matcher(raw); if (m.matches()) { final int r = Integer.valueOf(m.group(1)); final int g = Integer.valueOf(m.group(2)); final int b = Integer.valueOf(m.group(3)); return rgbToHexString(r, g, b); } } final ColorName name = ColorName.lookup(raw); final Color color = null != name ? ColorName.lookup(raw).getColor() : null; if (null != color) { return rgbToHexString(color.getR(), color.getG(), color.getB()); } throw new RuntimeException("RGB value cannot be parsed! [" + raw + "]"); }
SVGAttributeParser { public static String toHexColorString(final String raw) { if (raw.startsWith("#")) { return "#" + StringUtils.leftPad(raw.substring(1, raw.length()), 6, "0"); } if (raw.startsWith("rgb")) { Matcher m = RBG_PATTERN.matcher(raw); if (m.matches()) { final int r = Integer.valueOf(m.group(1)); final int g = Integer.valueOf(m.group(2)); final int b = Integer.valueOf(m.group(3)); return rgbToHexString(r, g, b); } } final ColorName name = ColorName.lookup(raw); final Color color = null != name ? ColorName.lookup(raw).getColor() : null; if (null != color) { return rgbToHexString(color.getR(), color.getG(), color.getB()); } throw new RuntimeException("RGB value cannot be parsed! [" + raw + "]"); } }
SVGAttributeParser { public static String toHexColorString(final String raw) { if (raw.startsWith("#")) { return "#" + StringUtils.leftPad(raw.substring(1, raw.length()), 6, "0"); } if (raw.startsWith("rgb")) { Matcher m = RBG_PATTERN.matcher(raw); if (m.matches()) { final int r = Integer.valueOf(m.group(1)); final int g = Integer.valueOf(m.group(2)); final int b = Integer.valueOf(m.group(3)); return rgbToHexString(r, g, b); } } final ColorName name = ColorName.lookup(raw); final Color color = null != name ? ColorName.lookup(raw).getColor() : null; if (null != color) { return rgbToHexString(color.getR(), color.getG(), color.getB()); } throw new RuntimeException("RGB value cannot be parsed! [" + raw + "]"); }  }
SVGAttributeParser { public static String toHexColorString(final String raw) { if (raw.startsWith("#")) { return "#" + StringUtils.leftPad(raw.substring(1, raw.length()), 6, "0"); } if (raw.startsWith("rgb")) { Matcher m = RBG_PATTERN.matcher(raw); if (m.matches()) { final int r = Integer.valueOf(m.group(1)); final int g = Integer.valueOf(m.group(2)); final int b = Integer.valueOf(m.group(3)); return rgbToHexString(r, g, b); } } final ColorName name = ColorName.lookup(raw); final Color color = null != name ? ColorName.lookup(raw).getColor() : null; if (null != color) { return rgbToHexString(color.getR(), color.getG(), color.getB()); } throw new RuntimeException("RGB value cannot be parsed! [" + raw + "]"); }  static double toPixelValue(final String value,
                                      final double defaultValue); static double toPixelValue(final String value); static String toHexColorString(final String raw); static String rgbToHexString(final int r, final int g, final int b); static String rgbToHexString(final int r, final int g, final int b, final int a); static String rgbToHexString(int rgb); static int toRGB(final int r,
                            final int g,
                            final int b,
                            final int a); }
SVGAttributeParser { public static String toHexColorString(final String raw) { if (raw.startsWith("#")) { return "#" + StringUtils.leftPad(raw.substring(1, raw.length()), 6, "0"); } if (raw.startsWith("rgb")) { Matcher m = RBG_PATTERN.matcher(raw); if (m.matches()) { final int r = Integer.valueOf(m.group(1)); final int g = Integer.valueOf(m.group(2)); final int b = Integer.valueOf(m.group(3)); return rgbToHexString(r, g, b); } } final ColorName name = ColorName.lookup(raw); final Color color = null != name ? ColorName.lookup(raw).getColor() : null; if (null != color) { return rgbToHexString(color.getR(), color.getG(), color.getB()); } throw new RuntimeException("RGB value cannot be parsed! [" + raw + "]"); }  static double toPixelValue(final String value,
                                      final double defaultValue); static double toPixelValue(final String value); static String toHexColorString(final String raw); static String rgbToHexString(final int r, final int g, final int b); static String rgbToHexString(final int r, final int g, final int b, final int a); static String rgbToHexString(int rgb); static int toRGB(final int r,
                            final int g,
                            final int b,
                            final int a);  }