1 18 package org.apache.batik.bridge; 19 20 import java.awt.geom.AffineTransform ; 21 import java.awt.geom.Rectangle2D ; 22 23 import org.apache.batik.ext.awt.image.renderable.Filter; 24 import org.apache.batik.gvt.CompositeGraphicsNode; 25 import org.apache.batik.gvt.GraphicsNode; 26 import org.apache.batik.gvt.filter.Mask; 27 import org.apache.batik.gvt.filter.MaskRable8Bit; 28 import org.w3c.dom.Element ; 29 import org.w3c.dom.Node ; 30 31 37 public class SVGMaskElementBridge extends AbstractSVGBridge 38 implements MaskBridge { 39 40 43 public SVGMaskElementBridge() {} 44 45 48 public String getLocalName() { 49 return SVG_MASK_TAG; 50 } 51 52 60 public Mask createMask(BridgeContext ctx, 61 Element maskElement, 62 Element maskedElement, 63 GraphicsNode maskedNode) { 64 65 String s; 66 67 Rectangle2D maskRegion = SVGUtilities.convertMaskRegion 69 (maskElement, maskedElement, maskedNode, ctx); 70 71 GVTBuilder builder = ctx.getGVTBuilder(); 75 CompositeGraphicsNode maskNode = new CompositeGraphicsNode(); 76 CompositeGraphicsNode maskNodeContent = new CompositeGraphicsNode(); 77 maskNode.getChildren().add(maskNodeContent); 78 boolean hasChildren = false; 79 for(Node node = maskElement.getFirstChild(); 80 node != null; 81 node = node.getNextSibling()){ 82 83 if(node.getNodeType() != Node.ELEMENT_NODE) { 85 continue; 86 } 87 88 Element child = (Element )node; 89 GraphicsNode gn = builder.build(ctx, child) ; 90 if(gn == null) { 91 continue; 92 } 93 hasChildren = true; 94 maskNodeContent.getChildren().add(gn); 95 } 96 if (!hasChildren) { 97 return null; } 99 100 AffineTransform Tx; 102 s = maskElement.getAttributeNS(null, SVG_TRANSFORM_ATTRIBUTE); 103 if (s.length() != 0) { 104 Tx = SVGUtilities.convertTransform 105 (maskElement, SVG_TRANSFORM_ATTRIBUTE, s); 106 } else { 107 Tx = new AffineTransform (); 108 } 109 110 short coordSystemType; 112 s = maskElement.getAttributeNS(null, SVG_MASK_CONTENT_UNITS_ATTRIBUTE); 113 if (s.length() == 0) { 114 coordSystemType = SVGUtilities.USER_SPACE_ON_USE; 115 } else { 116 coordSystemType = SVGUtilities.parseCoordinateSystem 117 (maskElement, SVG_MASK_CONTENT_UNITS_ATTRIBUTE, s); 118 } 119 120 if (coordSystemType == SVGUtilities.OBJECT_BOUNDING_BOX) { 122 Tx = SVGUtilities.toObjectBBox(Tx, maskedNode); 123 } 124 125 maskNodeContent.setTransform(Tx); 126 127 Filter filter = maskedNode.getFilter(); 128 if (filter == null) { 129 filter = maskedNode.getGraphicsNodeRable(true); 131 } 132 133 return new MaskRable8Bit(filter, maskNode, maskRegion); 134 } 135 } 136 | Popular Tags |