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.svg;
20
21 import org.apache.batik.css.engine.CSSEngine;
22 import org.apache.batik.css.engine.value.LengthManager;
23 import org.apache.batik.css.engine.value.Value;
24 import org.apache.batik.css.engine.value.ValueManager;
25 import org.apache.batik.util.CSSConstants;
26 import org.apache.batik.util.SVGTypes;
27
28 import org.w3c.css.sac.LexicalUnit;
29 import org.w3c.dom.DOMException;
30 import org.w3c.dom.css.CSSPrimitiveValue;
31
32 /**
33 * This class provides a manager for the 'kerning' property values.
34 *
35 * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
36 * @version $Id: KerningManager.java 1733416 2016-03-03 07:07:13Z gadams $
37 */
38 public class KerningManager extends LengthManager {
39
40 /**
41 * Implements {@link ValueManager#isInheritedProperty()}.
42 */
43 public boolean isInheritedProperty() {
44 return true;
45 }
46
47 /**
48 * Implements {@link ValueManager#getPropertyName()}.
49 */
50 public String getPropertyName() {
51 return CSSConstants.CSS_KERNING_PROPERTY;
52 }
53
54 /**
55 * Implements {@link ValueManager#isAnimatableProperty()}.
56 */
57 public boolean isAnimatableProperty() {
58 return true;
59 }
60
61 /**
62 * Implements {@link ValueManager#isAdditiveProperty()}.
63 */
64 public boolean isAdditiveProperty() {
65 return true;
66 }
67
68 /**
69 * Implements {@link ValueManager#getPropertyType()}.
70 */
71 public int getPropertyType() {
72 return SVGTypes.TYPE_KERNING_VALUE;
73 }
74
75 /**
76 * Implements {@link ValueManager#getDefaultValue()}.
77 */
78 public Value getDefaultValue() {
79 return SVGValueConstants.AUTO_VALUE;
80 }
81
82 /**
83 * Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}.
84 */
85 public Value createValue(LexicalUnit lu, CSSEngine engine)
86 throws DOMException {
87 switch (lu.getLexicalUnitType()) {
88 case LexicalUnit.SAC_INHERIT:
89 return SVGValueConstants.INHERIT_VALUE;
90
91 case LexicalUnit.SAC_IDENT:
92 if (lu.getStringValue().equalsIgnoreCase
93 (CSSConstants.CSS_AUTO_VALUE)) {
94 return SVGValueConstants.AUTO_VALUE;
95 }
96 throw createInvalidIdentifierDOMException(lu.getStringValue());
97 }
98 return super.createValue(lu, engine);
99 }
100
101 /**
102 * Implements {@link
103 * ValueManager#createStringValue(short,String,CSSEngine)}.
104 */
105 public Value createStringValue(short type, String value, CSSEngine engine)
106 throws DOMException {
107 if (type != CSSPrimitiveValue.CSS_IDENT) {
108 throw createInvalidStringTypeDOMException(type);
109 }
110 if (value.equalsIgnoreCase(CSSConstants.CSS_AUTO_VALUE)) {
111 return SVGValueConstants.AUTO_VALUE;
112 }
113 throw createInvalidIdentifierDOMException(value);
114 }
115
116 /**
117 * Indicates the orientation of the property associated with
118 * this manager.
119 */
120 protected int getOrientation() {
121 return HORIZONTAL_ORIENTATION;
122 }
123
124 }
125