1 18 package org.apache.batik.css.engine.value.svg; 19 20 import org.apache.batik.css.engine.CSSEngine; 21 import org.apache.batik.css.engine.CSSStylableElement; 22 import org.apache.batik.css.engine.StyleMap; 23 import org.apache.batik.css.engine.value.ListValue; 24 import org.apache.batik.css.engine.value.URIValue; 25 import org.apache.batik.css.engine.value.Value; 26 import org.apache.batik.css.engine.value.ValueManager; 27 import org.apache.batik.util.CSSConstants; 28 import org.w3c.css.sac.LexicalUnit; 29 import org.w3c.dom.css.CSSPrimitiveValue; 30 import org.w3c.dom.css.CSSValue; 31 import org.w3c.dom.DOMException ; 32 33 39 public class SVGPaintManager extends SVGColorManager { 40 41 44 public SVGPaintManager(String prop) { 45 super(prop); 46 } 47 48 53 public SVGPaintManager(String prop, Value v) { 54 super(prop, v); 55 } 56 57 60 public boolean isInheritedProperty() { 61 return true; 62 } 63 64 67 public Value createValue(LexicalUnit lu, CSSEngine engine) 68 throws DOMException { 69 switch (lu.getLexicalUnitType()) { 70 case LexicalUnit.SAC_IDENT: 71 if (lu.getStringValue().equalsIgnoreCase 72 (CSSConstants.CSS_NONE_VALUE)) { 73 return SVGValueConstants.NONE_VALUE; 74 } 75 default: 77 return super.createValue(lu, engine); 78 case LexicalUnit.SAC_URI: 79 } 80 String value = lu.getStringValue(); 81 String uri = resolveURI(engine.getCSSBaseURI(), value); 82 lu = lu.getNextLexicalUnit(); 83 if (lu == null) { 84 return new URIValue(value, uri); 85 } 86 87 ListValue result = new ListValue(' '); 88 result.append(new URIValue(value, uri)); 89 90 if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) { 91 if (lu.getStringValue().equalsIgnoreCase 92 (CSSConstants.CSS_NONE_VALUE)) { 93 result.append(SVGValueConstants.NONE_VALUE); 94 return result; 95 } 96 } 97 Value v = super.createValue(lu, engine); 98 if (v.getCssValueType() == CSSValue.CSS_CUSTOM) { 99 ListValue lv = (ListValue)v; 100 for (int i = 0; i < lv.getLength(); i++) { 101 result.append(lv.item(i)); 102 } 103 } else { 104 result.append(v); 105 } 106 return result; 107 } 108 109 113 public Value computeValue(CSSStylableElement elt, 114 String pseudo, 115 CSSEngine engine, 116 int idx, 117 StyleMap sm, 118 Value value) { 119 if (value == SVGValueConstants.NONE_VALUE) { 120 return value; 121 } 122 if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) { 123 ListValue lv = (ListValue)value; 124 Value v = lv.item(0); 125 if (v.getPrimitiveType() == CSSPrimitiveValue.CSS_URI) { 126 v = lv.item(1); 127 if (v == SVGValueConstants.NONE_VALUE) { 128 return value; 129 } 130 Value t = super.computeValue(elt, pseudo, engine, idx, sm, v); 131 if (t != v) { 132 ListValue result = new ListValue(' '); 133 result.append(lv.item(0)); 134 result.append(t); 135 if (lv.getLength() == 3) { 136 result.append(lv.item(1)); 137 } 138 return result; 139 } 140 return value; 141 } 142 } 143 return super.computeValue(elt, pseudo, engine, idx, sm, value); 144 } 145 } 146 | Popular Tags |