1 18 19 package org.apache.batik.css.engine.value.svg12; 20 21 import org.apache.batik.css.engine.CSSEngine; 22 import org.apache.batik.css.engine.CSSStylableElement; 23 import org.apache.batik.css.engine.StyleMap; 24 import org.apache.batik.css.engine.value.LengthManager; 25 import org.apache.batik.css.engine.value.FloatValue; 26 import org.apache.batik.css.engine.value.svg12.SVG12ValueConstants; 27 import org.apache.batik.css.engine.value.Value; 28 import org.apache.batik.css.engine.value.ValueManager; 29 import org.apache.batik.util.SVG12CSSConstants; 30 31 import org.w3c.css.sac.LexicalUnit; 32 import org.w3c.dom.css.CSSPrimitiveValue; 33 import org.w3c.dom.css.CSSValue; 34 import org.w3c.dom.DOMException ; 35 36 42 public class LineHeightManager extends LengthManager { 43 44 public LineHeightManager() { } 45 46 49 public boolean isInheritedProperty() { 50 return true; 51 } 52 53 56 public String getPropertyName() { 57 return SVG12CSSConstants.CSS_LINE_HEIGHT_PROPERTY; 58 } 59 60 63 public Value getDefaultValue() { 64 return SVG12ValueConstants.NORMAL_VALUE; 65 } 66 67 70 public Value createValue(LexicalUnit lu, CSSEngine engine) 71 throws DOMException { 72 73 switch (lu.getLexicalUnitType()) { 74 case LexicalUnit.SAC_INHERIT: 75 return SVG12ValueConstants.INHERIT_VALUE; 76 case LexicalUnit.SAC_IDENT: { 77 String s = lu.getStringValue().toLowerCase(); 78 if (SVG12CSSConstants.CSS_NORMAL_VALUE.equals(s)) 79 return SVG12ValueConstants.NORMAL_VALUE; 80 throw createInvalidIdentifierDOMException(lu.getStringValue()); 81 } 82 default: 83 return super.createValue(lu, engine); 84 } 85 } 86 87 88 92 protected int getOrientation() { 93 return VERTICAL_ORIENTATION; 95 } 96 97 98 102 public Value computeValue(CSSStylableElement elt, 103 String pseudo, 104 CSSEngine engine, 105 int idx, 106 StyleMap sm, 107 Value value) { 108 if (value.getCssValueType() != CSSValue.CSS_PRIMITIVE_VALUE) 109 return value; 110 111 switch (value.getPrimitiveType()) { 112 case CSSPrimitiveValue.CSS_NUMBER: 113 return new LineHeightValue(CSSPrimitiveValue.CSS_NUMBER, 114 value.getFloatValue(), true); 115 116 case CSSPrimitiveValue.CSS_PERCENTAGE: { 117 float v = value.getFloatValue(); 118 int fsidx = engine.getFontSizeIndex(); 119 float fs = engine.getComputedStyle 120 (elt, pseudo, fsidx).getFloatValue(); 121 return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, v * fs*.01f); 122 } 123 124 default: 125 return super.computeValue(elt, pseudo, engine, idx, sm, value); 126 } 127 } 128 } 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | Popular Tags |