1 18 package org.apache.batik.bridge; 19 20 import java.awt.RenderingHints ; 21 22 import org.apache.batik.css.engine.CSSEngineEvent; 23 import org.apache.batik.css.engine.SVGCSSEngine; 24 import org.apache.batik.gvt.GraphicsNode; 25 import org.apache.batik.gvt.ShapeNode; 26 import org.apache.batik.gvt.ShapePainter; 27 import org.w3c.dom.Element ; 28 29 35 public abstract class SVGShapeElementBridge extends AbstractGraphicsNodeBridge { 36 37 40 protected SVGShapeElementBridge() {} 41 42 50 public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) { 51 ShapeNode shapeNode = (ShapeNode)super.createGraphicsNode(ctx, e); 52 if (shapeNode == null) { 53 return null; 54 } 55 buildShape(ctx, e, shapeNode); 57 58 RenderingHints hints = null; 60 hints = CSSUtilities.convertColorRendering(e, hints); 61 hints = CSSUtilities.convertShapeRendering(e, hints); 62 if (hints != null) 63 shapeNode.setRenderingHints(hints); 64 65 return shapeNode; 66 } 67 68 71 protected GraphicsNode instantiateGraphicsNode() { 72 return new ShapeNode(); 73 } 74 75 83 public void buildGraphicsNode(BridgeContext ctx, 84 Element e, 85 GraphicsNode node) { 86 ShapeNode shapeNode = (ShapeNode)node; 87 shapeNode.setShapePainter(createShapePainter(ctx, e, shapeNode)); 88 super.buildGraphicsNode(ctx, e, node); 89 } 90 91 100 protected ShapePainter createShapePainter(BridgeContext ctx, 101 Element e, 102 ShapeNode shapeNode) { 103 return PaintServer.convertFillAndStroke(e, shapeNode, ctx); 114 } 115 116 124 protected abstract void buildShape(BridgeContext ctx, 125 Element e, 126 ShapeNode node); 127 128 131 public boolean isComposite() { 132 return false; 133 } 134 135 137 140 protected void handleGeometryChanged() { 141 super.handleGeometryChanged(); 142 ShapeNode shapeNode = (ShapeNode)node; 143 shapeNode.setShapePainter(createShapePainter(ctx, e, shapeNode)); 144 } 145 146 150 protected boolean hasNewShapePainter; 151 152 157 public void handleCSSEngineEvent(CSSEngineEvent evt) { 158 hasNewShapePainter = false; 159 super.handleCSSEngineEvent(evt); 160 } 161 162 165 protected void handleCSSPropertyChanged(int property) { 166 switch(property) { 167 case SVGCSSEngine.FILL_INDEX: 168 case SVGCSSEngine.FILL_OPACITY_INDEX: 169 case SVGCSSEngine.STROKE_INDEX: 170 case SVGCSSEngine.STROKE_OPACITY_INDEX: 171 case SVGCSSEngine.STROKE_WIDTH_INDEX: 173 case SVGCSSEngine.STROKE_LINECAP_INDEX: 174 case SVGCSSEngine.STROKE_LINEJOIN_INDEX: 175 case SVGCSSEngine.STROKE_MITERLIMIT_INDEX: 176 case SVGCSSEngine.STROKE_DASHARRAY_INDEX: 177 case SVGCSSEngine.STROKE_DASHOFFSET_INDEX: { 178 if (!hasNewShapePainter) { 179 hasNewShapePainter = true; 180 ShapeNode shapeNode = (ShapeNode)node; 181 shapeNode.setShapePainter(createShapePainter(ctx, e, shapeNode)); 182 } 183 break; 184 } 185 case SVGCSSEngine.SHAPE_RENDERING_INDEX: { 186 RenderingHints hints = node.getRenderingHints(); 187 hints = CSSUtilities.convertShapeRendering(e, hints); 188 if (hints != null) { 189 node.setRenderingHints(hints); 190 } 191 break; 192 } 193 case SVGCSSEngine.COLOR_RENDERING_INDEX: { 194 RenderingHints hints = node.getRenderingHints(); 195 hints = CSSUtilities.convertColorRendering(e, hints); 196 if (hints != null) { 197 node.setRenderingHints(hints); 198 } 199 break; 200 } 201 default: 202 super.handleCSSPropertyChanged(property); 203 } 204 } 205 } 206 | Popular Tags |