001/**********************************************
002 * Copyright (C) 2010-2011 Lukas Laag
003 * This file is part of lib-gwt-svg.
004 * 
005 * libgwtsvg is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Lesser General Public License as published by
007 * the Free Software Foundation, either version 3 of the License, or
008 * (at your option) any later version.
009 * 
010 * libgwtsvg is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU Lesser General Public License for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public License
016 * along with libgwtsvg.  If not, see http://www.gnu.org/licenses/
017 **********************************************/
018/*
019 * Copyright (c) 2004 World Wide Web Consortium,
020 *
021 * (Massachusetts Institute of Technology, European Research Consortium for
022 * Informatics and Mathematics, Keio University). All Rights Reserved. This
023 * work is distributed under the W3C(r) Software License [1] in the hope that
024 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
025 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
026 *
027 * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
028 */
029
030package org.vectomatic.dom.svg;
031
032import org.vectomatic.dom.svg.events.ActivateEvent;
033import org.vectomatic.dom.svg.events.ActivateHandler;
034import org.vectomatic.dom.svg.events.FocusInEvent;
035import org.vectomatic.dom.svg.events.FocusInHandler;
036import org.vectomatic.dom.svg.events.FocusOutEvent;
037import org.vectomatic.dom.svg.events.FocusOutHandler;
038import org.vectomatic.dom.svg.events.HasGraphicalHandlers;
039import org.vectomatic.dom.svg.impl.SVGTextContentElement;
040import org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired;
041import org.vectomatic.dom.svg.itf.ISVGLangSpace;
042import org.vectomatic.dom.svg.itf.ISVGStylable;
043import org.vectomatic.dom.svg.itf.ISVGTests;
044
045import com.google.gwt.core.client.JavaScriptException;
046import com.google.gwt.event.dom.client.ClickEvent;
047import com.google.gwt.event.dom.client.ClickHandler;
048import com.google.gwt.event.dom.client.DragEndEvent;
049import com.google.gwt.event.dom.client.DragEndHandler;
050import com.google.gwt.event.dom.client.DragEnterEvent;
051import com.google.gwt.event.dom.client.DragEnterHandler;
052import com.google.gwt.event.dom.client.DragEvent;
053import com.google.gwt.event.dom.client.DragHandler;
054import com.google.gwt.event.dom.client.DragLeaveEvent;
055import com.google.gwt.event.dom.client.DragLeaveHandler;
056import com.google.gwt.event.dom.client.DragOverEvent;
057import com.google.gwt.event.dom.client.DragOverHandler;
058import com.google.gwt.event.dom.client.DragStartEvent;
059import com.google.gwt.event.dom.client.DragStartHandler;
060import com.google.gwt.event.dom.client.DropEvent;
061import com.google.gwt.event.dom.client.DropHandler;
062import com.google.gwt.event.dom.client.LoadEvent;
063import com.google.gwt.event.dom.client.LoadHandler;
064import com.google.gwt.event.dom.client.MouseDownEvent;
065import com.google.gwt.event.dom.client.MouseDownHandler;
066import com.google.gwt.event.dom.client.MouseMoveEvent;
067import com.google.gwt.event.dom.client.MouseMoveHandler;
068import com.google.gwt.event.dom.client.MouseOutEvent;
069import com.google.gwt.event.dom.client.MouseOutHandler;
070import com.google.gwt.event.dom.client.MouseOverEvent;
071import com.google.gwt.event.dom.client.MouseOverHandler;
072import com.google.gwt.event.dom.client.MouseUpEvent;
073import com.google.gwt.event.dom.client.MouseUpHandler;
074import com.google.gwt.event.dom.client.TouchCancelEvent;
075import com.google.gwt.event.dom.client.TouchCancelHandler;
076import com.google.gwt.event.dom.client.TouchEndEvent;
077import com.google.gwt.event.dom.client.TouchEndHandler;
078import com.google.gwt.event.dom.client.TouchMoveEvent;
079import com.google.gwt.event.dom.client.TouchMoveHandler;
080import com.google.gwt.event.dom.client.TouchStartEvent;
081import com.google.gwt.event.dom.client.TouchStartHandler;
082import com.google.gwt.event.shared.HandlerRegistration;
083
084/**
085 * <p>The {@link org.vectomatic.dom.svg.OMSVGTextContentElement} is inherited
086 * by various text-related interfaces, such as {@link org.vectomatic.dom.svg.OMSVGTextElement},
087 * {@link org.vectomatic.dom.svg.OMSVGTSpanElement}, {@link org.vectomatic.dom.svg.OMSVGTRefElement},
088 * {@link org.vectomatic.dom.svg.OMSVGAltGlyphElement} and {@link org.vectomatic.dom.svg.OMSVGTextPathElement}.</p>
089 * <p>For the methods on this interface that refer to an index to a character
090 * or a number of characters, these references are to be interpreted as an
091 * index to a UTF-16 code unit or a number of UTF-16 code units, respectively.
092 * This is for consistency with DOM Level 2 Core, where methods on the <code>CharacterData</code>
093 * interface use UTF-16 code units as indexes and counts within the character
094 * data. Thus for example, if the text content of a <a href='http://www.w3.org/TR/SVG11/text.html#TextElement'
095 * title='text element specification'>text</a> element is a single non-BMP
096 * character, such as U+10000, then invoking {@link org.vectomatic.dom.svg.OMSVGTextContentElement#getNumberOfChars()}
097 * on that element will return 2 since there are two UTF-16 code units (the
098 * surrogate pair) used to represent that one character.</p>
099 */
100public abstract class OMSVGTextContentElement extends OMSVGElement implements HasGraphicalHandlers, ISVGTests, ISVGLangSpace, ISVGExternalResourcesRequired, ISVGStylable {
101  /**
102   * The enumeration was set to a value that is not one of predefined types.
103   * It is invalid to attempt to define a new value of this type or to attempt
104   * to switch an existing value to this type.
105   */
106  public static final short LENGTHADJUST_UNKNOWN = 0;
107  /**
108   * Corresponds to value <span class='attr-value'>'spacing'</span>.
109   */
110  public static final short LENGTHADJUST_SPACING = 1;
111  /**
112   * Corresponds to value <span class='attr-value'>'spacingAndGlyphs'</span>.
113   */
114  public static final short LENGTHADJUST_SPACINGANDGLYPHS = 2;
115  protected OMSVGTextContentElement(SVGTextContentElement ot) {
116    super(ot);
117  }
118
119  // Implementation of the svg::SVGTextContentElement W3C IDL interface
120  /**
121   * Corresponds to attribute <span class='attr-name'>'textLength'</span> on
122   * the given element.
123   */
124  public final OMSVGAnimatedLength getTextLength() {
125    return ((SVGTextContentElement)ot).getTextLength();
126  }
127  /**
128   * Corresponds to attribute <span class='attr-name'>'lengthAdjust'</span>
129   * on the given element.  The value must be one of the length adjust constants
130   * defined on this interface.
131   */
132  public final OMSVGAnimatedEnumeration getLengthAdjust() {
133    return ((SVGTextContentElement)ot).getLengthAdjust();
134  }
135  /**
136   * Returns the total number of characters available for rendering within the
137   * current element, which includes referenced characters from <a href='http://www.w3.org/TR/SVG11/text.html#TRefElement'
138   * title='tref element specification'>tref</a> reference, regardless of whether
139   * they will be rendered. Effectively, this is equivalent to the length of
140   * the <a href="http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Node3-textContent">Node::textContent</a>
141   * attribute from DOM Level 3 Core ([<a href="refs.html#ref-DOM3">DOM3</a>],
142   * section 1.4), if that attribute also expanded <a href='http://www.w3.org/TR/SVG11/text.html#TRefElement'
143   * title='tref element specification'>tref</a> elements.
144   * @return Total number of characters.
145   */
146  public final int getNumberOfChars() {
147    return ((SVGTextContentElement)ot).getNumberOfChars();
148  }
149  /**
150   * The total sum of all of the advance values from rendering all of the characters
151   * within this element, including the advance value on the glyphs (horizontal
152   * or vertical), the effect of properties <code>kerning</code>, <code>letter-spacing</code>
153   * and <code>word-spacing</code> and adjustments due to attributes <code>tspan/dx</code>
154   * and <code>tspan/dy</code> on <a href='http://www.w3.org/TR/SVG11/text.html#TSpanElement'
155   * title='tspan element specification'>tspan</a> elements. For non-rendering
156   * environments, the user agent shall make reasonable assumptions about glyph
157   * metrics.
158   * @return The text advance distance.
159   */
160  public final float getComputedTextLength() {
161    return ((SVGTextContentElement)ot).getComputedTextLength();
162  }
163  /**
164   * The total sum of all of the advance values from rendering the specified
165   * substring of the characters, including the advance value on the glyphs
166   * (horizontal or vertical), the effect of properties <code>kerning</code>,
167   * <code>letter-spacing</code> and <code>word-spacing</code> and adjustments
168   * due to attributes <code>tspan/dx</code> and <code>tspan/dy</code> on <a
169   * href='http://www.w3.org/TR/SVG11/text.html#TSpanElement' title='tspan element
170   * specification'>tspan</a> elements. For non-rendering environments, the
171   * user agent shall make reasonable assumptions about glyph metrics.  If multiple
172   * consecutive characters are rendered inseparably (e.g., as a single glyph
173   * or a sequence of glyphs, or because the range encompasses half of a surrogate
174   * pair), and nchars is greater than 0 then the measured range shall be expanded
175   * so that each of the inseparable characters are included.
176   * @param charnum The index of the first character in the substring, where
177   * the first character has an index of 0.
178   * @param nchars The number of characters in the substring. If nchars   specifies
179   * more characters than are available, then the substring will   consist of
180   * all characters starting with charnum until the end of the   list of characters.
181   * @return The text advance distance.
182   * @throws DOMException(INDEX_SIZE_ERR) Raised if <var>charnum</var> or  
183   * <var>nchars</var> is negative or if <var>charnum</var> is greater than
184   * or equal to the number of characters at this node.
185   */
186  public final float getSubStringLength(int charnum, int nchars) throws JavaScriptException {
187    return ((SVGTextContentElement)ot).getSubStringLength(charnum, nchars);
188  }
189  /**
190   * Returns the current text position before rendering the character in the
191   * user coordinate system for rendering the glyph(s) that correspond to the
192   * specified character. The current text position has already taken into account
193   * the effects of any inter-character adjustments due to properties <code>kerning</code>,
194   * <code>letter-spacing</code> and <code>word-spacing</code> and adjustments
195   * due to attributes <span class='attr-name'>'x'</span>, <span class='attr-name'>'y'</span>,
196   * <span class='attr-name'>'dx'</span> and <span class='attr-name'>'dy'</span>.
197   * If multiple consecutive characters are rendered inseparably (e.g., as a
198   * single glyph or a sequence of glyphs), then each of the inseparable characters
199   * will return the start position for the first glyph.
200   * @param charnum The index of the character, where the first character has
201   * an index of 0.
202   * @return The character's start position.
203   * @throws DOMException(INDEX_SIZE_ERR) Raised if the <var>charnum</var> is
204   * negative or if <var>charnum</var> is greater than or equal to the   number
205   * of characters at this node.
206   */
207  public final OMSVGPoint getStartPositionOfChar(int charnum) throws JavaScriptException {
208    return ((SVGTextContentElement)ot).getStartPositionOfChar(charnum);
209  }
210  /**
211   * Returns the current text position after rendering the character in the
212   * user coordinate system for rendering the glyph(s) that correspond to the
213   * specified character. This current text position does <em>not</em> take
214   * into account the effects of any inter-character adjustments to prepare
215   * for the next character, such as properties <code>kerning</code>, <code>letter-spacing</code>
216   * and <code>word-spacing</code> and adjustments due to attributes <span class='attr-name'>'x'</span>,
217   * <span class='attr-name'>'y'</span>, <span class='attr-name'>'dx'</span>
218   * and <span class='attr-name'>'dy'</span>. If multiple consecutive characters
219   * are rendered inseparably (e.g., as a single glyph or a sequence of glyphs),
220   * then each of the inseparable characters will return the end position for
221   * the last glyph.
222   * @param charnum The index of the character, where the first character has
223   * an index of 0.
224   * @return The character's end position.
225   * @throws DOMException(INDEX_SIZE_ERR) Raised if the <var>charnum</var> is
226   * negative or if <var>charnum</var> is greater than or equal to the   number
227   * of characters at this node.
228   */
229  public final OMSVGPoint getEndPositionOfChar(int charnum) throws JavaScriptException {
230    return ((SVGTextContentElement)ot).getEndPositionOfChar(charnum);
231  }
232  /**
233   * Returns a tightest rectangle which defines the minimum and maximum X and
234   * Y values in the user coordinate system for rendering the glyph(s) that
235   * correspond to the specified character. The calculations assume that all
236   * glyphs occupy the full standard glyph cell for the font. If multiple consecutive
237   * characters are rendered inseparably (e.g., as a single glyph or a sequence
238   * of glyphs), then each of the inseparable characters will return the same
239   * extent.
240   * @param charnum The index of the character, where the first character has
241   * an index of 0.
242   * @return The rectangle which encloses all of the rendered glyph(s).
243   * @throws DOMException(INDEX_SIZE_ERR) Raised if the <var>charnum</var> is
244   * negative or if <var>charnum</var> is greater than or equal to the   number
245   * of characters at this node.
246   */
247  public final OMSVGRect getExtentOfChar(int charnum) throws JavaScriptException {
248    return ((SVGTextContentElement)ot).getExtentOfChar(charnum);
249  }
250  /**
251   * Returns the rotation value relative to the current user coordinate system
252   * used to render the glyph(s) corresponding to the specified character. If
253   * multiple glyph(s) are used to render the given character and the glyphs
254   * each have different rotations (e.g., due to text-on-a-path), the user agent
255   * shall return an average value (e.g., the rotation angle at the midpoint
256   * along the path for all glyphs used to render this character). The rotation
257   * value represents the rotation that is supplemental to any rotation due
258   * to properties <code>glyph-orientation-horizontal</code> and <code>glyph-orientation-vertical</code>;
259   * thus, any glyph rotations due to these properties are not included into
260   * the returned rotation value. If multiple consecutive characters are rendered
261   * inseparably (e.g., as a single glyph or a sequence of glyphs), then each
262   * of the inseparable characters will return the same rotation value.
263   * @param charnum The index of the character, where the first character has
264   * an index of 0.
265   * @return The rotation angle.
266   * @throws DOMException(INDEX_SIZE_ERR) Raised if the <var>charnum</var> is
267   * negative or if <var>charnum</var> is greater than or equal to the   number
268   * of characters at this node.
269   */
270  public final float getRotationOfChar(int charnum) throws JavaScriptException {
271    return ((SVGTextContentElement)ot).getRotationOfChar(charnum);
272  }
273  /**
274   * Returns the index of the character whose corresponding glyph cell bounding
275   * box contains the specified point. The calculations assume that all glyphs
276   * occupy the full standard glyph cell for the font. If no such character
277   * exists, a value of -1 is returned. If multiple such characters exist, the
278   * character within the element whose glyphs were rendered last (i.e., take
279   * into account any reordering such as for bidirectional text) is used. If
280   * multiple consecutive characters are rendered inseparably (e.g., as a single
281   * glyph or a sequence of glyphs), then the user agent shall allocate an equal
282   * percentage of the text advance amount to each of the contributing characters
283   * in determining which of the characters is chosen.
284   * @param point A point in user space.
285   * @return The index of the character which is at the given point, where 
286   * the first character has an index of 0.
287   */
288  public final int getCharNumAtPosition(OMSVGPoint point) {
289    return ((SVGTextContentElement)ot).getCharNumAtPosition(point);
290  }
291  /**
292   * Causes the specified substring to be selected just as if the user selected
293   * the substring interactively.
294   * @param charnum The index of the start character which is at the given 
295   * point, where the first character has an index of 0.
296   * @param nchars The number of characters in the substring. If nchars   specifies
297   * more characters than are available, then the substring   will consist of
298   * all characters starting with charnum until the end   of the list of characters.
299   * @throws DOMException(INDEX_SIZE_ERR) Raised if <var>charnum</var> or  
300   * <var>nchars</var> is negative or if <var>charnum</var> is greater   than
301   * or equal to the number of characters at this node.
302   */
303  public final void selectSubString(int charnum, int nchars) throws JavaScriptException {
304    ((SVGTextContentElement)ot).selectSubString(charnum, nchars);
305  }
306
307  // Implementation of the svg::SVGExternalResourcesRequired W3C IDL interface
308  /**
309   * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()}
310   * on the given element. Note that the SVG DOM defines the attribute {@link
311   * org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()}
312   * as being of type {@link org.vectomatic.dom.svg.OMSVGAnimatedBoolean}, whereas
313   * the SVG language definition says that {@link org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()}
314   * is not animated. Because the SVG language definition states that {@link
315   * org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()}
316   * cannot be animated, the {@link org.vectomatic.dom.svg.OMSVGAnimatedBoolean#getAnimVal()}
317   * will always be the same as the {@link org.vectomatic.dom.svg.OMSVGAnimatedBoolean#getBaseVal()}.
318   */
319  public final OMSVGAnimatedBoolean getExternalResourcesRequired() {
320    return ((SVGTextContentElement)ot).getExternalResourcesRequired();
321  }
322
323  // Implementation of the svg::SVGLangSpace W3C IDL interface
324  /**
325   * Corresponds to attribute <code>xml:lang</code> on the given element.
326   */
327  public final String getXmllang() {
328    return ((SVGTextContentElement)ot).getXmllang();
329  }
330  /**
331   * Corresponds to attribute <code>xml:lang</code> on the given element.
332   * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) Raised on an   attempt
333   * to change the value of a <a href="svgdom.html#ReadOnlyNodes">read only
334   * attribute</a>.
335   */
336  public final void setXmllang(java.lang.String value) throws JavaScriptException {
337    ((SVGTextContentElement)ot).setXmllang(value);
338  }
339  /**
340   * Corresponds to attribute <code>xml:space</code> on the given element.
341   */
342  public final String getXmlspace() {
343    return ((SVGTextContentElement)ot).getXmlspace();
344  }
345  /**
346   * Corresponds to attribute <code>xml:space</code> on the given element.
347   * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) Raised on an   attempt
348   * to change the value of a <a href="svgdom.html#ReadOnlyNodes">read only
349   * attribute</a>.
350   */
351  public final void setXmlspace(java.lang.String value) throws JavaScriptException {
352    ((SVGTextContentElement)ot).setXmlspace(value);
353  }
354
355  // Implementation of the svg::SVGTests W3C IDL interface
356  /**
357   * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTests#getRequiredFeatures()}
358   * on the given element.
359   */
360  public final OMSVGStringList getRequiredFeatures() {
361    return ((SVGTextContentElement)ot).getRequiredFeatures();
362  }
363  /**
364   * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTests#getRequiredExtensions()}
365   * on the given element.
366   */
367  public final OMSVGStringList getRequiredExtensions() {
368    return ((SVGTextContentElement)ot).getRequiredExtensions();
369  }
370  /**
371   * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTests#getSystemLanguage()}
372   * on the given element.
373   */
374  public final OMSVGStringList getSystemLanguage() {
375    return ((SVGTextContentElement)ot).getSystemLanguage();
376  }
377  /**
378   * Returns true if the user agent supports the given extension, specified
379   * by a URI.
380   * @param extension The name of the extension, expressed as a URI.
381   * @return True or false, depending on whether the given extension is   supported.
382   */
383  public final boolean hasExtension(String extension) {
384    return ((SVGTextContentElement)ot).hasExtension(extension);
385  }
386
387  @Override
388  public final HandlerRegistration addClickHandler(ClickHandler handler) {
389    return addDomHandler(handler, ClickEvent.getType());
390  }
391  @Override
392  public final HandlerRegistration addDragEndHandler(DragEndHandler handler) {
393    return addDomHandler(handler, DragEndEvent.getType());
394  }
395  @Override
396  public final HandlerRegistration addDragEnterHandler(DragEnterHandler handler) {
397    return addDomHandler(handler, DragEnterEvent.getType());
398  }
399  @Override
400  public final HandlerRegistration addDragHandler(DragHandler handler) {
401    return addDomHandler(handler, DragEvent.getType());
402  }
403  @Override
404  public final HandlerRegistration addDragLeaveHandler(DragLeaveHandler handler) {
405    return addDomHandler(handler, DragLeaveEvent.getType());
406  }
407  @Override
408  public final HandlerRegistration addDragOverHandler(DragOverHandler handler) {
409    return addDomHandler(handler, DragOverEvent.getType());
410  }
411  @Override
412  public final HandlerRegistration addDragStartHandler(DragStartHandler handler) {
413    return addDomHandler(handler, DragStartEvent.getType());
414  }
415  @Override
416  public final HandlerRegistration addDropHandler(DropHandler handler) {
417    return addDomHandler(handler, DropEvent.getType());
418  }
419  @Override
420  public final HandlerRegistration addLoadHandler(LoadHandler handler) {
421    return addDomHandler(handler, LoadEvent.getType());
422  }
423  @Override
424  public final HandlerRegistration addMouseDownHandler(MouseDownHandler handler) {
425    return addDomHandler(handler, MouseDownEvent.getType());
426  }
427  @Override
428  public final HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) {
429    return addDomHandler(handler, MouseMoveEvent.getType());
430  }
431  @Override
432  public final HandlerRegistration addMouseOutHandler(MouseOutHandler handler) {
433    return addDomHandler(handler, MouseOutEvent.getType());
434  }
435  @Override
436  public final HandlerRegistration addMouseOverHandler(MouseOverHandler handler) {
437    return addDomHandler(handler, MouseOverEvent.getType());
438  }
439  @Override
440  public final HandlerRegistration addMouseUpHandler(MouseUpHandler handler) {
441    return addDomHandler(handler, MouseUpEvent.getType());
442  }
443  @Override
444  public final HandlerRegistration addTouchCancelHandler(TouchCancelHandler handler) {
445    return addDomHandler(handler, TouchCancelEvent.getType());
446  }
447  @Override
448  public final HandlerRegistration addTouchEndHandler(TouchEndHandler handler) {
449    return addDomHandler(handler, TouchEndEvent.getType());
450  }
451  @Override
452  public final HandlerRegistration addTouchMoveHandler(TouchMoveHandler handler) {
453    return addDomHandler(handler, TouchMoveEvent.getType());
454  }
455  @Override
456  public final HandlerRegistration addTouchStartHandler(TouchStartHandler handler) {
457    return addDomHandler(handler, TouchStartEvent.getType());
458  }
459  @Override
460  public final HandlerRegistration addActivateHandler(ActivateHandler handler) {
461    return addDomHandler(handler, ActivateEvent.getType());
462  }
463  @Override
464  public final HandlerRegistration addFocusInHandler(FocusInHandler handler) {
465    return addDomHandler(handler, FocusInEvent.getType());
466  }
467  @Override
468  public final HandlerRegistration addFocusOutHandler(FocusOutHandler handler) {
469    return addDomHandler(handler, FocusOutEvent.getType());
470  }
471}