1 18 package org.apache.batik.svggen; 19 20 import java.awt.Color ; 21 import java.awt.Paint ; 22 import java.util.HashMap ; 23 import java.util.Map ; 24 25 import org.apache.batik.ext.awt.g2d.GraphicContext; 26 27 35 public class SVGColor extends AbstractSVGConverter{ 36 39 public static final Color aqua = new Color (0x00, 0xff, 0xff); 40 public static final Color black = Color.black; 41 public static final Color blue = Color.blue; 42 public static final Color fuchsia = new Color (0xff, 0x00, 0xff); 43 public static final Color gray = new Color (0x80, 0x80, 0x80); 44 public static final Color green = new Color (0x00, 0x80, 0x00); 45 public static final Color lime = new Color (0x00, 0xff, 0x00); 46 public static final Color maroon = new Color (0x80, 0x00, 0x00); 47 public static final Color navy = new Color (0x00, 0x00, 0x80); 48 public static final Color olive = new Color (0x80, 0x80, 00); 49 public static final Color purple = new Color (0x80, 0x00, 0x80); 50 public static final Color red = new Color (0xff, 0x00, 0x00); 51 public static final Color silver = new Color (0xc0, 0xc0, 0xc0); 52 public static final Color teal = new Color (0x00, 0x80, 0x80); 53 public static final Color white = Color.white; 54 public static final Color yellow = Color.yellow; 55 56 59 private static Map colorMap = new HashMap (); 60 61 static { 62 colorMap.put(black, "black"); 63 colorMap.put(silver, "silver"); 64 colorMap.put(gray, "gray"); 65 colorMap.put(white, "white"); 66 colorMap.put(maroon, "maroon"); 67 colorMap.put(red, "red"); 68 colorMap.put(purple, "purple"); 69 colorMap.put(fuchsia, "fuchsia"); 70 colorMap.put(green, "green"); 71 colorMap.put(lime, "lime"); 72 colorMap.put(olive, "olive"); 73 colorMap.put(yellow, "yellow"); 74 colorMap.put(navy, "navy"); 75 colorMap.put(blue, "blue"); 76 colorMap.put(teal, "teal"); 77 colorMap.put(aqua, "aqua"); 78 } 79 80 84 public SVGColor(SVGGeneratorContext generatorContext) { 85 super(generatorContext); 86 } 87 88 98 public SVGDescriptor toSVG(GraphicContext gc) { 99 Paint paint = gc.getPaint(); 100 return toSVG((Color )paint, generatorContext); 101 } 102 103 107 public static SVGPaintDescriptor toSVG(Color color, SVGGeneratorContext gc) { 108 String cssColor = (String )colorMap.get(color); 112 if (cssColor==null) { 113 StringBuffer cssColorBuffer = new StringBuffer (RGB_PREFIX); 115 cssColorBuffer.append(color.getRed()); 116 cssColorBuffer.append(COMMA); 117 cssColorBuffer.append(color.getGreen()); 118 cssColorBuffer.append(COMMA); 119 cssColorBuffer.append(color.getBlue()); 120 cssColorBuffer.append(RGB_SUFFIX); 121 cssColor = cssColorBuffer.toString(); 122 } 123 124 float alpha = color.getAlpha()/255f; 128 129 String alphaString = gc.doubleString(alpha); 130 131 return new SVGPaintDescriptor(cssColor, alphaString); 132 } 133 } 134 | Popular Tags |