001: /*
002:
003: Licensed to the Apache Software Foundation (ASF) under one or more
004: contributor license agreements. See the NOTICE file distributed with
005: this work for additional information regarding copyright ownership.
006: The ASF licenses this file to You under the Apache License, Version 2.0
007: (the "License"); you may not use this file except in compliance with
008: the License. You may obtain a copy of the License at
009:
010: http://www.apache.org/licenses/LICENSE-2.0
011:
012: Unless required by applicable law or agreed to in writing, software
013: distributed under the License is distributed on an "AS IS" BASIS,
014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: See the License for the specific language governing permissions and
016: limitations under the License.
017:
018: */
019: package org.apache.batik.dom.svg;
020:
021: import org.apache.batik.dom.AbstractDocument;
022: import org.apache.batik.dom.util.DoublyIndexedTable;
023: import org.apache.batik.dom.util.XMLSupport;
024: import org.apache.batik.util.SVGTypes;
025:
026: import org.w3c.dom.DOMException;
027: import org.w3c.dom.svg.SVGAnimatedBoolean;
028: import org.w3c.dom.svg.SVGAnimatedEnumeration;
029: import org.w3c.dom.svg.SVGAnimatedLength;
030: import org.w3c.dom.svg.SVGLength;
031: import org.w3c.dom.svg.SVGPoint;
032: import org.w3c.dom.svg.SVGRect;
033: import org.w3c.dom.svg.SVGStringList;
034:
035: /**
036: * This class provides a common superclass for all graphics elements.
037: *
038: * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
039: * @version $Id: SVGOMTextContentElement.java 501495 2007-01-30 18:00:36Z dvholten $
040: */
041: public abstract class SVGOMTextContentElement extends
042: SVGStylableElement {
043:
044: /**
045: * Table mapping XML attribute names to TraitInformation objects.
046: */
047: protected static DoublyIndexedTable xmlTraitInformation;
048: static {
049: DoublyIndexedTable t = new DoublyIndexedTable(
050: SVGStylableElement.xmlTraitInformation);
051: t.put(null, SVG_TEXT_LENGTH_ATTRIBUTE, new TraitInformation(
052: true, SVGTypes.TYPE_LENGTH, PERCENTAGE_VIEWPORT_SIZE));
053: t.put(null, SVG_LENGTH_ADJUST_ATTRIBUTE, new TraitInformation(
054: true, SVGTypes.TYPE_IDENT));
055: t.put(null, SVG_EXTERNAL_RESOURCES_REQUIRED_ATTRIBUTE,
056: new TraitInformation(true, SVGTypes.TYPE_BOOLEAN));
057: xmlTraitInformation = t;
058: }
059:
060: /**
061: * The 'lengthAdjust' attribute values.
062: */
063: protected static final String[] LENGTH_ADJUST_VALUES = { "",
064: SVG_SPACING_ATTRIBUTE, SVG_SPACING_AND_GLYPHS_VALUE };
065:
066: /**
067: * The 'externalResourcesRequired' attribute value.
068: */
069: protected SVGOMAnimatedBoolean externalResourcesRequired;
070:
071: /**
072: * The 'textLength' attribute value.
073: */
074: protected AbstractSVGAnimatedLength textLength;
075:
076: /**
077: * The 'lengthAdjust' attribute value.
078: */
079: protected SVGOMAnimatedEnumeration lengthAdjust;
080:
081: /**
082: * Creates a new SVGOMTextContentElement.
083: */
084: protected SVGOMTextContentElement() {
085: }
086:
087: /**
088: * Creates a new SVGOMTextContentElement object.
089: * @param prefix The namespace prefix.
090: * @param owner The owner document.
091: */
092: protected SVGOMTextContentElement(String prefix,
093: AbstractDocument owner) {
094: super (prefix, owner);
095: initializeLiveAttributes();
096: }
097:
098: /**
099: * Initializes all live attributes for this element.
100: */
101: protected void initializeAllLiveAttributes() {
102: super .initializeAllLiveAttributes();
103: initializeLiveAttributes();
104: }
105:
106: /**
107: * Initializes the live attribute values of this element.
108: */
109: private void initializeLiveAttributes() {
110: externalResourcesRequired = createLiveAnimatedBoolean(null,
111: SVG_EXTERNAL_RESOURCES_REQUIRED_ATTRIBUTE, false);
112: lengthAdjust = createLiveAnimatedEnumeration(null,
113: SVG_LENGTH_ADJUST_ATTRIBUTE, LENGTH_ADJUST_VALUES,
114: (short) 1);
115: textLength = new AbstractSVGAnimatedLength(this , null,
116: SVG_TEXT_LENGTH_ATTRIBUTE,
117: SVGOMAnimatedLength.HORIZONTAL_LENGTH, true) {
118: boolean usedDefault;
119:
120: protected String getDefaultValue() {
121: usedDefault = true;
122: return String.valueOf(getComputedTextLength());
123: }
124:
125: public SVGLength getBaseVal() {
126: if (baseVal == null) {
127: baseVal = new SVGTextLength(direction);
128: }
129: return baseVal;
130: }
131:
132: class SVGTextLength extends BaseSVGLength {
133: public SVGTextLength(short direction) {
134: super (direction);
135: }
136:
137: protected void revalidate() {
138: usedDefault = false;
139:
140: super .revalidate();
141:
142: // Since the default value can change w/o notice
143: // always recompute it.
144: if (usedDefault)
145: valid = false;
146: }
147: }
148: };
149:
150: liveAttributeValues.put(null, SVG_TEXT_LENGTH_ATTRIBUTE,
151: textLength);
152: textLength
153: .addAnimatedAttributeListener(((SVGOMDocument) ownerDocument)
154: .getAnimatedAttributeListener());
155: }
156:
157: /**
158: * <b>DOM</b>: Implements {@link
159: * org.w3c.dom.svg.SVGTextContentElement#getTextLength()}.
160: */
161: public SVGAnimatedLength getTextLength() {
162: return textLength;
163: }
164:
165: /**
166: * <b>DOM</b>: Implements {@link
167: * org.w3c.dom.svg.SVGTextContentElement#getLengthAdjust()}.
168: */
169: public SVGAnimatedEnumeration getLengthAdjust() {
170: return lengthAdjust;
171: }
172:
173: /**
174: * <b>DOM</b>: Implements {@link
175: * org.w3c.dom.svg.SVGTextContentElement#getNumberOfChars()}.
176: */
177: public int getNumberOfChars() {
178: return SVGTextContentSupport.getNumberOfChars(this );
179: }
180:
181: /**
182: * <b>DOM</b>: Implements {@link
183: * org.w3c.dom.svg.SVGTextContentElement#getComputedTextLength()}.
184: */
185: public float getComputedTextLength() {
186: return SVGTextContentSupport.getComputedTextLength(this );
187: }
188:
189: /**
190: * <b>DOM</b>: Implements {@link
191: * org.w3c.dom.svg.SVGTextContentElement#getSubStringLength(int,int)}.
192: */
193: public float getSubStringLength(int charnum, int nchars)
194: throws DOMException {
195: return SVGTextContentSupport.getSubStringLength(this , charnum,
196: nchars);
197: }
198:
199: /**
200: * <b>DOM</b>: Implements {@link
201: * org.w3c.dom.svg.SVGTextContentElement#getStartPositionOfChar(int)}.
202: */
203: public SVGPoint getStartPositionOfChar(int charnum)
204: throws DOMException {
205: return SVGTextContentSupport.getStartPositionOfChar(this ,
206: charnum);
207: }
208:
209: /**
210: * <b>DOM</b>: Implements {@link
211: * org.w3c.dom.svg.SVGTextContentElement#getEndPositionOfChar(int)}.
212: */
213: public SVGPoint getEndPositionOfChar(int charnum)
214: throws DOMException {
215: return SVGTextContentSupport
216: .getEndPositionOfChar(this , charnum);
217: }
218:
219: /**
220: * <b>DOM</b>: Implements {@link
221: * org.w3c.dom.svg.SVGTextContentElement#getExtentOfChar(int)}.
222: */
223: public SVGRect getExtentOfChar(int charnum) throws DOMException {
224: return SVGTextContentSupport.getExtentOfChar(this , charnum);
225: }
226:
227: /**
228: * <b>DOM</b>: Implements {@link
229: * org.w3c.dom.svg.SVGTextContentElement#getRotationOfChar(int)}.
230: */
231: public float getRotationOfChar(int charnum) throws DOMException {
232: return SVGTextContentSupport.getRotationOfChar(this , charnum);
233: }
234:
235: /**
236: * <b>DOM</b>: Implements {@link
237: * org.w3c.dom.svg.SVGTextContentElement#getCharNumAtPosition(SVGPoint)}.
238: */
239: public int getCharNumAtPosition(SVGPoint point) {
240: return SVGTextContentSupport.getCharNumAtPosition(this , point
241: .getX(), point.getY());
242: }
243:
244: /**
245: * <b>DOM</b>: Implements {@link
246: * org.w3c.dom.svg.SVGTextContentElement#selectSubString(int,int)}.
247: */
248: public void selectSubString(int charnum, int nchars)
249: throws DOMException {
250: SVGTextContentSupport.selectSubString(this , charnum, nchars);
251: }
252:
253: // SVGExternalResourcesRequired support /////////////////////////////
254:
255: /**
256: * <b>DOM</b>: Implements {@link
257: * org.w3c.dom.svg.SVGExternalResourcesRequired#getExternalResourcesRequired()}.
258: */
259: public SVGAnimatedBoolean getExternalResourcesRequired() {
260: return externalResourcesRequired;
261: }
262:
263: // SVGLangSpace support //////////////////////////////////////////////////
264:
265: /**
266: * <b>DOM</b>: Returns the xml:lang attribute value.
267: */
268: public String getXMLlang() {
269: return XMLSupport.getXMLLang(this );
270: }
271:
272: /**
273: * <b>DOM</b>: Sets the xml:lang attribute value.
274: */
275: public void setXMLlang(String lang) {
276: setAttributeNS(XML_NAMESPACE_URI, XML_LANG_QNAME, lang);
277: }
278:
279: /**
280: * <b>DOM</b>: Returns the xml:space attribute value.
281: */
282: public String getXMLspace() {
283: return XMLSupport.getXMLSpace(this );
284: }
285:
286: /**
287: * <b>DOM</b>: Sets the xml:space attribute value.
288: */
289: public void setXMLspace(String space) {
290: setAttributeNS(XML_NAMESPACE_URI, XML_SPACE_QNAME, space);
291: }
292:
293: // SVGTests support ///////////////////////////////////////////////////
294:
295: /**
296: * <b>DOM</b>: Implements {@link
297: * org.w3c.dom.svg.SVGTests#getRequiredFeatures()}.
298: */
299: public SVGStringList getRequiredFeatures() {
300: return SVGTestsSupport.getRequiredFeatures(this );
301: }
302:
303: /**
304: * <b>DOM</b>: Implements {@link
305: * org.w3c.dom.svg.SVGTests#getRequiredExtensions()}.
306: */
307: public SVGStringList getRequiredExtensions() {
308: return SVGTestsSupport.getRequiredExtensions(this );
309: }
310:
311: /**
312: * <b>DOM</b>: Implements {@link
313: * org.w3c.dom.svg.SVGTests#getSystemLanguage()}.
314: */
315: public SVGStringList getSystemLanguage() {
316: return SVGTestsSupport.getSystemLanguage(this );
317: }
318:
319: /**
320: * <b>DOM</b>: Implements {@link
321: * org.w3c.dom.svg.SVGTests#hasExtension(String)}.
322: */
323: public boolean hasExtension(String extension) {
324: return SVGTestsSupport.hasExtension(this , extension);
325: }
326:
327: /**
328: * Returns the table of TraitInformation objects for this element.
329: */
330: protected DoublyIndexedTable getTraitInformationTable() {
331: return xmlTraitInformation;
332: }
333: }
|