1 /*
2
3    Licensed to the Apache Software Foundation (ASF) under one or more
4    contributor license agreements.  See the NOTICE file distributed with
5    this work for additional information regarding copyright ownership.
6    The ASF licenses this file to You under the Apache License, Version 2.0
7    (the "License"); you may not use this file except in compliance with
8    the License.  You may obtain a copy of the License at
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
12    Unless required by applicable law or agreed to in writing, software
13    distributed under the License is distributed on an "AS IS" BASIS,
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    See the License for the specific language governing permissions and
16    limitations under the License.
17
18  */

19 package org.apache.batik.css.engine.value.css2;
20
21 import org.apache.batik.css.engine.CSSEngine;
22 import org.apache.batik.css.engine.value.AbstractValueManager;
23 import org.apache.batik.css.engine.value.FloatValue;
24 import org.apache.batik.css.engine.value.Value;
25 import org.apache.batik.css.engine.value.ValueConstants;
26 import org.apache.batik.css.engine.value.ValueManager;
27 import org.apache.batik.util.CSSConstants;
28 import org.apache.batik.util.SVGTypes;
29
30 import org.w3c.css.sac.LexicalUnit;
31 import org.w3c.dom.DOMException;
32 import org.w3c.dom.css.CSSPrimitiveValue;
33
34 /**
35  * This class provides a manager for the 'font-size-adjust' property values.
36  *
37  * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
38  * @version $Id: FontSizeAdjustManager.java 1733416 2016-03-03 07:07:13Z gadams $
39  */

40 public class FontSizeAdjustManager extends AbstractValueManager {
41
42     /**
43      * Implements {@link ValueManager#isInheritedProperty()}.
44      */

45     public boolean isInheritedProperty() {
46         return true;
47     }
48
49     /**
50      * Implements {@link ValueManager#isAnimatableProperty()}.
51      */

52     public boolean isAnimatableProperty() {
53         return true;
54     }
55
56     /**
57      * Implements {@link ValueManager#isAdditiveProperty()}.
58      */

59     public boolean isAdditiveProperty() {
60         return false;
61     }
62
63     /**
64      * Implements {@link ValueManager#getPropertyType()}.
65      */

66     public int getPropertyType() {
67         return SVGTypes.TYPE_FONT_SIZE_ADJUST_VALUE;
68     }
69
70     /**
71      * Implements {@link ValueManager#getPropertyName()}.
72      */

73     public String getPropertyName() {
74         return CSSConstants.CSS_FONT_SIZE_ADJUST_PROPERTY;
75     }
76     
77     /**
78      * Implements {@link ValueManager#getDefaultValue()}.
79      */

80     public Value getDefaultValue() {
81         return ValueConstants.NONE_VALUE;
82     }
83
84     /**
85      * Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}.
86      */

87     public Value createValue(LexicalUnit lu, CSSEngine engine)
88         throws DOMException {
89         switch (lu.getLexicalUnitType()) {
90         case LexicalUnit.SAC_INHERIT:
91             return ValueConstants.INHERIT_VALUE;
92
93         case LexicalUnit.SAC_INTEGER:
94             return new FloatValue(CSSPrimitiveValue.CSS_NUMBER,
95                                   lu.getIntegerValue());
96
97         case LexicalUnit.SAC_REAL:
98             return new FloatValue(CSSPrimitiveValue.CSS_NUMBER,
99                                   lu.getFloatValue());
100
101         case LexicalUnit.SAC_IDENT:
102             if (lu.getStringValue().equalsIgnoreCase
103                 (CSSConstants.CSS_NONE_VALUE)) {
104                 return ValueConstants.NONE_VALUE;
105             }
106             throw createInvalidIdentifierDOMException(lu.getStringValue());
107         }
108         throw createInvalidLexicalUnitDOMException(lu.getLexicalUnitType());
109     }
110
111     /**
112      * Implements {@link
113      * ValueManager#createStringValue(short,String,CSSEngine)}.
114      */

115     public Value createStringValue(short type, String value, CSSEngine engine)
116         throws DOMException {
117         if (type != CSSPrimitiveValue.CSS_IDENT) {
118             throw createInvalidStringTypeDOMException(type);
119         }
120         if (value.equalsIgnoreCase(CSSConstants.CSS_NONE_VALUE)) {
121             return ValueConstants.NONE_VALUE;
122         }
123         throw createInvalidIdentifierDOMException(value);
124     }
125
126     /**
127      * Implements {@link ValueManager#createFloatValue(short,float)}.
128      */

129     public Value createFloatValue(short type, float floatValue)
130         throws DOMException {
131         if (type == CSSPrimitiveValue.CSS_NUMBER) {
132             return new FloatValue(type, floatValue);
133         }
134         throw createInvalidFloatTypeDOMException(type);
135     }
136 }
137