001: /*
002:
003: ============================================================================
004: The Apache Software License, Version 1.1
005: ============================================================================
006:
007: Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
008:
009: Redistribution and use in source and binary forms, with or without modifica-
010: tion, are permitted provided that the following conditions are met:
011:
012: 1. Redistributions of source code must retain the above copyright notice,
013: this list of conditions and the following disclaimer.
014:
015: 2. Redistributions in binary form must reproduce the above copyright notice,
016: this list of conditions and the following disclaimer in the documentation
017: and/or other materials provided with the distribution.
018:
019: 3. The end-user documentation included with the redistribution, if any, must
020: include the following acknowledgment: "This product includes software
021: developed by the Apache Software Foundation (http://www.apache.org/)."
022: Alternately, this acknowledgment may appear in the software itself, if
023: and wherever such third-party acknowledgments normally appear.
024:
025: 4. The names "Batik" and "Apache Software Foundation" must not be
026: used to endorse or promote products derived from this software without
027: prior written permission. For written permission, please contact
028: apache@apache.org.
029:
030: 5. Products derived from this software may not be called "Apache", nor may
031: "Apache" appear in their name, without prior written permission of the
032: Apache Software Foundation.
033:
034: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
035: INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
036: FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
037: APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
038: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
039: DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
040: OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
041: ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
042: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
043: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
044:
045: This software consists of voluntary contributions made by many individuals
046: on behalf of the Apache Software Foundation. For more information on the
047: Apache Software Foundation, please see <http://www.apache.org/>.
048:
049: */
050:
051: package org.apache.batik.css.engine.value.css2;
052:
053: import org.apache.batik.css.engine.CSSEngine;
054: import org.apache.batik.css.engine.CSSStylableElement;
055: import org.apache.batik.css.engine.StyleMap;
056: import org.apache.batik.css.engine.value.IdentifierManager;
057: import org.apache.batik.css.engine.value.StringMap;
058: import org.apache.batik.css.engine.value.Value;
059: import org.apache.batik.css.engine.value.ValueConstants;
060: import org.apache.batik.util.CSSConstants;
061:
062: /**
063: * This class provides a manager for the 'font-stretch' property values.
064: *
065: * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
066: * @version $Id$
067: */
068: public class FontStretchManager extends IdentifierManager {
069:
070: /**
071: * The identifier values.
072: */
073: protected final static StringMap values = new StringMap();
074: static {
075: values
076: .put(CSSConstants.CSS_ALL_VALUE,
077: ValueConstants.ALL_VALUE);
078: values.put(CSSConstants.CSS_CONDENSED_VALUE,
079: ValueConstants.CONDENSED_VALUE);
080: values.put(CSSConstants.CSS_EXPANDED_VALUE,
081: ValueConstants.EXPANDED_VALUE);
082: values.put(CSSConstants.CSS_EXTRA_CONDENSED_VALUE,
083: ValueConstants.EXTRA_CONDENSED_VALUE);
084: values.put(CSSConstants.CSS_EXTRA_EXPANDED_VALUE,
085: ValueConstants.EXTRA_EXPANDED_VALUE);
086: values.put(CSSConstants.CSS_NARROWER_VALUE,
087: ValueConstants.NARROWER_VALUE);
088: values.put(CSSConstants.CSS_NORMAL_VALUE,
089: ValueConstants.NORMAL_VALUE);
090: values.put(CSSConstants.CSS_SEMI_CONDENSED_VALUE,
091: ValueConstants.SEMI_CONDENSED_VALUE);
092: values.put(CSSConstants.CSS_SEMI_EXPANDED_VALUE,
093: ValueConstants.SEMI_EXPANDED_VALUE);
094: values.put(CSSConstants.CSS_ULTRA_CONDENSED_VALUE,
095: ValueConstants.ULTRA_CONDENSED_VALUE);
096: values.put(CSSConstants.CSS_ULTRA_EXPANDED_VALUE,
097: ValueConstants.ULTRA_EXPANDED_VALUE);
098: values.put(CSSConstants.CSS_WIDER_VALUE,
099: ValueConstants.WIDER_VALUE);
100: }
101:
102: /**
103: * Implements {@link
104: * org.apache.batik.css.engine.value.ValueManager#isInheritedProperty()}.
105: */
106: public boolean isInheritedProperty() {
107: return true;
108: }
109:
110: /**
111: * Implements {@link
112: * org.apache.batik.css.engine.value.ValueManager#getPropertyName()}.
113: */
114: public String getPropertyName() {
115: return CSSConstants.CSS_FONT_STRETCH_PROPERTY;
116: }
117:
118: /**
119: * Implements {@link
120: * org.apache.batik.css.engine.value.ValueManager#getDefaultValue()}.
121: */
122: public Value getDefaultValue() {
123: return ValueConstants.NORMAL_VALUE;
124: }
125:
126: /**
127: * Implements {@link
128: * ValueManager#computeValue(CSSStylableElement,String,CSSEngine,int,StyleMap,Value)}.
129: */
130: public Value computeValue(CSSStylableElement elt, String pseudo,
131: CSSEngine engine, int idx, StyleMap sm, Value value) {
132: if (value == ValueConstants.NARROWER_VALUE) {
133: sm.putParentRelative(idx, true);
134:
135: CSSStylableElement p = CSSEngine
136: .getParentCSSStylableElement(elt);
137: if (p == null) {
138: return ValueConstants.SEMI_CONDENSED_VALUE;
139: }
140: Value v = engine.getComputedStyle(p, pseudo, idx);
141: if (v == ValueConstants.NORMAL_VALUE) {
142: return ValueConstants.SEMI_CONDENSED_VALUE;
143: }
144: if (v == ValueConstants.CONDENSED_VALUE) {
145: return ValueConstants.EXTRA_CONDENSED_VALUE;
146: }
147: if (v == ValueConstants.EXPANDED_VALUE) {
148: return ValueConstants.SEMI_EXPANDED_VALUE;
149: }
150: if (v == ValueConstants.SEMI_EXPANDED_VALUE) {
151: return ValueConstants.NORMAL_VALUE;
152: }
153: if (v == ValueConstants.SEMI_CONDENSED_VALUE) {
154: return ValueConstants.CONDENSED_VALUE;
155: }
156: if (v == ValueConstants.EXTRA_CONDENSED_VALUE) {
157: return ValueConstants.ULTRA_CONDENSED_VALUE;
158: }
159: if (v == ValueConstants.EXTRA_EXPANDED_VALUE) {
160: return ValueConstants.EXPANDED_VALUE;
161: }
162: if (v == ValueConstants.ULTRA_CONDENSED_VALUE) {
163: return ValueConstants.ULTRA_CONDENSED_VALUE;
164: }
165: return ValueConstants.EXTRA_EXPANDED_VALUE;
166: } else if (value == ValueConstants.WIDER_VALUE) {
167: sm.putParentRelative(idx, true);
168:
169: CSSStylableElement p = CSSEngine
170: .getParentCSSStylableElement(elt);
171: if (p == null) {
172: return ValueConstants.SEMI_CONDENSED_VALUE;
173: }
174: Value v = engine.getComputedStyle(p, pseudo, idx);
175: if (v == ValueConstants.NORMAL_VALUE) {
176: return ValueConstants.SEMI_EXPANDED_VALUE;
177: }
178: if (v == ValueConstants.CONDENSED_VALUE) {
179: return ValueConstants.SEMI_CONDENSED_VALUE;
180: }
181: if (v == ValueConstants.EXPANDED_VALUE) {
182: return ValueConstants.EXTRA_EXPANDED_VALUE;
183: }
184: if (v == ValueConstants.SEMI_EXPANDED_VALUE) {
185: return ValueConstants.EXPANDED_VALUE;
186: }
187: if (v == ValueConstants.SEMI_CONDENSED_VALUE) {
188: return ValueConstants.NORMAL_VALUE;
189: }
190: if (v == ValueConstants.EXTRA_CONDENSED_VALUE) {
191: return ValueConstants.CONDENSED_VALUE;
192: }
193: if (v == ValueConstants.EXTRA_EXPANDED_VALUE) {
194: return ValueConstants.ULTRA_EXPANDED_VALUE;
195: }
196: if (v == ValueConstants.ULTRA_CONDENSED_VALUE) {
197: return ValueConstants.EXTRA_CONDENSED_VALUE;
198: }
199: return ValueConstants.ULTRA_EXPANDED_VALUE;
200: }
201: return value;
202: }
203:
204: /**
205: * Implements {@link IdentifierManager#getIdentifiers()}.
206: */
207: protected StringMap getIdentifiers() {
208: return values;
209: }
210: }
|