1 18 package org.apache.batik.svggen; 19 20 import java.util.HashMap ; 21 import java.util.LinkedList ; 22 import java.util.List ; 23 import java.util.Map ; 24 25 import org.apache.batik.ext.awt.g2d.GraphicContext; 26 import org.apache.batik.ext.awt.g2d.TransformStackElement; 27 28 37 public class SVGGraphicContextConverter { 38 private static final int GRAPHIC_CONTEXT_CONVERTER_COUNT = 6; 39 40 private SVGTransform transformConverter; 41 private SVGPaint paintConverter; 42 private SVGBasicStroke strokeConverter; 43 private SVGComposite compositeConverter; 44 private SVGClip clipConverter; 45 private SVGRenderingHints hintsConverter; 46 private SVGFont fontConverter; 47 private SVGConverter converters[] = 48 new SVGConverter[GRAPHIC_CONTEXT_CONVERTER_COUNT]; 49 50 public SVGTransform getTransformConverter() { return transformConverter; } 51 public SVGPaint getPaintConverter(){ return paintConverter; } 52 public SVGBasicStroke getStrokeConverter(){ return strokeConverter; } 53 public SVGComposite getCompositeConverter(){ return compositeConverter; } 54 public SVGClip getClipConverter(){ return clipConverter; } 55 public SVGRenderingHints getHintsConverter(){ return hintsConverter; } 56 public SVGFont getFontConverter(){ return fontConverter; } 57 58 62 public SVGGraphicContextConverter(SVGGeneratorContext generatorContext) { 63 if (generatorContext == null) 64 throw new SVGGraphics2DRuntimeException(ErrorConstants.ERR_CONTEXT_NULL); 65 66 transformConverter = new SVGTransform(generatorContext); 67 paintConverter = new SVGPaint(generatorContext); 68 strokeConverter = new SVGBasicStroke(generatorContext); 69 compositeConverter = new SVGComposite(generatorContext); 70 clipConverter = new SVGClip(generatorContext); 71 hintsConverter = new SVGRenderingHints(generatorContext); 72 fontConverter = new SVGFont(generatorContext); 73 74 int i=0; 75 converters[i++] = paintConverter; 76 converters[i++] = strokeConverter; 77 converters[i++] = compositeConverter; 78 converters[i++] = clipConverter; 79 converters[i++] = hintsConverter; 80 converters[i++] = fontConverter; 81 } 82 83 87 public String toSVG(TransformStackElement transformStack[]) { 88 return transformConverter.toSVGTransform(transformStack); 89 } 90 91 95 public SVGGraphicContext toSVG(GraphicContext gc) { 96 Map groupAttrMap = new HashMap (); 98 99 for (int i=0; i<converters.length; i++) { 100 SVGDescriptor desc = converters[i].toSVG(gc); 101 if (desc != null) 102 desc.getAttributeMap(groupAttrMap); 103 } 104 105 return new SVGGraphicContext(groupAttrMap, 107 gc.getTransformStack()); 108 } 109 110 114 public List getDefinitionSet() { 115 List defSet = new LinkedList (); 116 for(int i=0; i<converters.length; i++) 117 defSet.addAll(converters[i].getDefinitionSet()); 118 119 return defSet; 120 } 121 } 122 | Popular Tags |