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.FloatValue; 24 import org.apache.batik.css.engine.value.LengthManager; 25 import org.apache.batik.css.engine.value.StringMap; 26 import org.apache.batik.css.engine.value.Value; 27 import org.apache.batik.css.engine.value.ValueManager; 28 import org.apache.batik.util.CSSConstants; 29 import org.w3c.css.sac.LexicalUnit; 30 import org.w3c.dom.DOMException ; 31 import org.w3c.dom.css.CSSPrimitiveValue; 32 33 39 public class BaselineShiftManager extends LengthManager { 40 41 44 protected final static StringMap values = new StringMap(); 45 static { 46 values.put(CSSConstants.CSS_BASELINE_VALUE, 47 SVGValueConstants.BASELINE_VALUE); 48 values.put(CSSConstants.CSS_SUB_VALUE, 49 SVGValueConstants.SUB_VALUE); 50 values.put(CSSConstants.CSS_SUPER_VALUE, 51 SVGValueConstants.SUPER_VALUE); 52 } 53 54 57 public boolean isInheritedProperty() { 58 return false; 59 } 60 61 64 public String getPropertyName() { 65 return CSSConstants.CSS_BASELINE_SHIFT_PROPERTY; 66 } 67 68 71 public Value getDefaultValue() { 72 return SVGValueConstants.BASELINE_VALUE; 73 } 74 75 78 public Value createValue(LexicalUnit lu, CSSEngine engine) 79 throws DOMException { 80 switch (lu.getLexicalUnitType()) { 81 case LexicalUnit.SAC_INHERIT: 82 return SVGValueConstants.INHERIT_VALUE; 83 84 case LexicalUnit.SAC_IDENT: 85 Object v = values.get(lu.getStringValue().toLowerCase().intern()); 86 if (v == null) { 87 throw createInvalidIdentifierDOMException(lu.getStringValue()); 88 } 89 return (Value)v; 90 } 91 return super.createValue(lu, engine); 92 } 93 94 97 public Value createStringValue(short type, String value, CSSEngine engine) 98 throws DOMException { 99 if (type != CSSPrimitiveValue.CSS_IDENT) { 100 throw createInvalidIdentifierDOMException(value); 101 } 102 Object v = values.get(value.toLowerCase().intern()); 103 if (v == null) { 104 throw createInvalidIdentifierDOMException(value); 105 } 106 return (Value)v; 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.getPrimitiveType() == CSSPrimitiveValue.CSS_PERCENTAGE) { 120 sm.putLineHeightRelative(idx, true); 121 122 int fsi = engine.getLineHeightIndex(); 123 CSSStylableElement parent; 124 parent = (CSSStylableElement)elt.getParentNode(); 125 if (parent == null) { 126 parent = elt; 130 } 131 Value fs = engine.getComputedStyle(parent, pseudo, fsi); 132 float fsv = fs.getFloatValue(); 133 float v = value.getFloatValue(); 134 return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 135 (fsv * v) / 100f); 136 } 137 return super.computeValue(elt, pseudo, engine, idx, sm, value); 138 } 139 140 141 145 protected int getOrientation() { 146 return BOTH_ORIENTATION; } 148 149 } 150 | Popular Tags |