1 18 package org.apache.batik.svggen; 19 20 import org.apache.batik.util.SVGConstants; 21 22 import java.util.Iterator ; 23 import java.util.Map ; 24 import java.util.HashMap ; 25 import java.util.Vector ; 26 27 import org.w3c.dom.Element ; 28 29 36 public class DefaultStyleHandler implements StyleHandler, SVGConstants { 37 41 static HashMap ignoreAttributes = new HashMap (); 42 43 static { 44 Vector textAttributes = new Vector (); 45 textAttributes.addElement(SVG_FONT_SIZE_ATTRIBUTE); 46 textAttributes.addElement(SVG_FONT_FAMILY_ATTRIBUTE); 47 textAttributes.addElement(SVG_FONT_STYLE_ATTRIBUTE); 48 textAttributes.addElement(SVG_FONT_WEIGHT_ATTRIBUTE); 49 50 ignoreAttributes.put(SVG_RECT_TAG, textAttributes); 51 ignoreAttributes.put(SVG_CIRCLE_TAG, textAttributes); 52 ignoreAttributes.put(SVG_ELLIPSE_TAG, textAttributes); 53 ignoreAttributes.put(SVG_POLYGON_TAG, textAttributes); 54 ignoreAttributes.put(SVG_POLYGON_TAG, textAttributes); 55 ignoreAttributes.put(SVG_LINE_TAG, textAttributes); 56 ignoreAttributes.put(SVG_PATH_TAG, textAttributes); 57 } 58 59 67 public void setStyle(Element element, Map styleMap, 68 SVGGeneratorContext generatorContext) { 69 String tagName = element.getTagName(); 70 Iterator iter = styleMap.keySet().iterator(); 71 String styleName = null; 72 while (iter.hasNext()) { 73 styleName = (String )iter.next(); 74 if (element.getAttributeNS(null, styleName).length() == 0){ 75 if (appliesTo(styleName, tagName)) { 76 element.setAttributeNS(null, styleName, 77 (String )styleMap.get(styleName)); 78 } 79 } 80 } 81 } 82 83 87 protected boolean appliesTo(String styleName, String tagName) { 88 Vector v = (Vector )ignoreAttributes.get(tagName); 89 if (v == null) { 90 return true; 91 } else { 92 return !v.contains(styleName); 93 } 94 } 95 } 96 | Popular Tags |