1 18 package org.apache.batik.svggen; 19 20 import java.util.HashMap ; 21 import java.util.Map ; 22 23 import org.apache.batik.ext.awt.g2d.TransformStackElement; 24 import org.apache.batik.util.SVGConstants; 25 26 33 public class SVGGraphicContext implements SVGConstants, ErrorConstants { 34 private static final String leafOnlyAttributes[] = { 37 SVG_OPACITY_ATTRIBUTE, 38 SVG_FILTER_ATTRIBUTE, 39 SVG_CLIP_PATH_ATTRIBUTE 40 }; 41 42 private static final String defaultValues[] = { 43 "1", 44 SVG_NONE_VALUE, 45 SVG_NONE_VALUE 46 }; 47 48 private Map context; 49 private Map groupContext; 50 private Map graphicElementContext; 51 private TransformStackElement transformStack[]; 52 53 58 public SVGGraphicContext(Map context, 59 TransformStackElement transformStack[]) { 60 if (context == null) 61 throw new SVGGraphics2DRuntimeException(ERR_MAP_NULL); 62 if (transformStack == null) 63 throw new SVGGraphics2DRuntimeException(ERR_TRANS_NULL); 64 this.context = context; 65 this.transformStack = transformStack; 66 computeGroupAndGraphicElementContext(); 67 } 68 69 76 public SVGGraphicContext(Map groupContext, Map graphicElementContext, 77 TransformStackElement transformStack[]) { 78 if (groupContext == null || graphicElementContext == null) 79 throw new SVGGraphics2DRuntimeException(ERR_MAP_NULL); 80 if (transformStack == null) 81 throw new SVGGraphics2DRuntimeException(ERR_TRANS_NULL); 82 83 this.groupContext = groupContext; 84 this.graphicElementContext = graphicElementContext; 85 this.transformStack = transformStack; 86 computeContext(); 87 } 88 89 90 93 public Map getContext() { 94 return context; 95 } 96 97 100 public Map getGroupContext() { 101 return groupContext; 102 } 103 104 107 public Map getGraphicElementContext() { 108 return graphicElementContext; 109 } 110 111 114 public TransformStackElement[] getTransformStack() { 115 return transformStack; 116 } 117 118 private void computeContext() { 119 if (context != null) 120 return; 121 122 context = new HashMap (groupContext); 123 context.putAll(graphicElementContext); 124 } 125 126 private void computeGroupAndGraphicElementContext() { 127 if (groupContext != null) 128 return; 129 groupContext = new HashMap (context); 134 graphicElementContext = new HashMap (); 135 for (int i=0; i< leafOnlyAttributes.length; i++) { 136 Object attrValue = groupContext.get(leafOnlyAttributes[i]); 137 if (attrValue != null){ 138 if (!attrValue.equals(defaultValues[i])) 139 graphicElementContext.put(leafOnlyAttributes[i], attrValue); 140 groupContext.remove(leafOnlyAttributes[i]); 141 } 142 } 143 } 144 } 145 | Popular Tags |