1 18 package org.apache.batik.svggen; 19 20 import java.awt.Color ; 21 import java.awt.GradientPaint ; 22 import java.awt.Paint ; 23 import java.awt.TexturePaint ; 24 import java.util.LinkedList ; 25 import java.util.List ; 26 27 import org.apache.batik.ext.awt.g2d.GraphicContext; 28 29 39 public class SVGPaint implements SVGConverter { 40 43 private SVGLinearGradient svgLinearGradient; 44 45 48 private SVGTexturePaint svgTexturePaint; 49 50 53 private SVGColor svgColor; 54 55 58 private SVGCustomPaint svgCustomPaint; 59 60 63 private SVGGeneratorContext generatorContext; 64 65 68 public SVGPaint(SVGGeneratorContext generatorContext) { 69 this.svgLinearGradient = new SVGLinearGradient(generatorContext); 70 this.svgTexturePaint = new SVGTexturePaint(generatorContext); 71 this.svgCustomPaint = new SVGCustomPaint(generatorContext); 72 this.svgColor = new SVGColor(generatorContext); 73 this.generatorContext = generatorContext; 74 } 75 76 80 public List getDefinitionSet(){ 81 List paintDefs = new LinkedList (svgLinearGradient.getDefinitionSet()); 82 paintDefs.addAll(svgTexturePaint.getDefinitionSet()); 83 paintDefs.addAll(svgCustomPaint.getDefinitionSet()); 84 paintDefs.addAll(svgColor.getDefinitionSet()); 85 return paintDefs; 86 } 87 88 public SVGTexturePaint getTexturePaintConverter(){ 89 return svgTexturePaint; 90 } 91 92 public SVGLinearGradient getGradientPaintConverter(){ 93 return svgLinearGradient; 94 } 95 96 public SVGCustomPaint getCustomPaintConverter(){ 97 return svgCustomPaint; 98 } 99 100 public SVGColor getColorConverter(){ 101 return svgColor; 102 } 103 104 114 public SVGDescriptor toSVG(GraphicContext gc){ 115 return toSVG(gc.getPaint()); 116 } 117 118 122 public SVGPaintDescriptor toSVG(Paint paint){ 123 SVGPaintDescriptor paintDesc = svgCustomPaint.toSVG(paint); 126 127 if (paintDesc == null) { 128 if (paint instanceof Color ) 129 paintDesc = SVGColor.toSVG((Color )paint, generatorContext); 130 else if (paint instanceof GradientPaint ) 131 paintDesc = svgLinearGradient.toSVG((GradientPaint )paint); 132 else if (paint instanceof TexturePaint ) 133 paintDesc = svgTexturePaint.toSVG((TexturePaint )paint); 134 } 135 136 return paintDesc; 137 } 138 } 139 | Popular Tags |