1 /********************************************** 2 * Copyright (C) 2010-2011 Lukas Laag 3 * This file is part of lib-gwt-svg. 4 * 5 * libgwtsvg is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU Lesser General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * libgwtsvg is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with libgwtsvg. If not, see http://www.gnu.org/licenses/ 17 **********************************************/ 18 /* 19 * Copyright (c) 2004 World Wide Web Consortium, 20 * 21 * (Massachusetts Institute of Technology, European Research Consortium for 22 * Informatics and Mathematics, Keio University). All Rights Reserved. This 23 * work is distributed under the W3C(r) Software License [1] in the hope that 24 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied 25 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 26 * 27 * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 28 */ 29 30 package org.vectomatic.dom.svg; 31 32 import org.vectomatic.dom.svg.events.ActivateEvent; 33 import org.vectomatic.dom.svg.events.ActivateHandler; 34 import org.vectomatic.dom.svg.events.FocusInEvent; 35 import org.vectomatic.dom.svg.events.FocusInHandler; 36 import org.vectomatic.dom.svg.events.FocusOutEvent; 37 import org.vectomatic.dom.svg.events.FocusOutHandler; 38 import org.vectomatic.dom.svg.events.HasGraphicalHandlers; 39 import org.vectomatic.dom.svg.impl.SVGTextContentElement; 40 import org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired; 41 import org.vectomatic.dom.svg.itf.ISVGLangSpace; 42 import org.vectomatic.dom.svg.itf.ISVGStylable; 43 import org.vectomatic.dom.svg.itf.ISVGTests; 44 45 import com.google.gwt.core.client.JavaScriptException; 46 import com.google.gwt.event.dom.client.ClickEvent; 47 import com.google.gwt.event.dom.client.ClickHandler; 48 import com.google.gwt.event.dom.client.DragEndEvent; 49 import com.google.gwt.event.dom.client.DragEndHandler; 50 import com.google.gwt.event.dom.client.DragEnterEvent; 51 import com.google.gwt.event.dom.client.DragEnterHandler; 52 import com.google.gwt.event.dom.client.DragEvent; 53 import com.google.gwt.event.dom.client.DragHandler; 54 import com.google.gwt.event.dom.client.DragLeaveEvent; 55 import com.google.gwt.event.dom.client.DragLeaveHandler; 56 import com.google.gwt.event.dom.client.DragOverEvent; 57 import com.google.gwt.event.dom.client.DragOverHandler; 58 import com.google.gwt.event.dom.client.DragStartEvent; 59 import com.google.gwt.event.dom.client.DragStartHandler; 60 import com.google.gwt.event.dom.client.DropEvent; 61 import com.google.gwt.event.dom.client.DropHandler; 62 import com.google.gwt.event.dom.client.LoadEvent; 63 import com.google.gwt.event.dom.client.LoadHandler; 64 import com.google.gwt.event.dom.client.MouseDownEvent; 65 import com.google.gwt.event.dom.client.MouseDownHandler; 66 import com.google.gwt.event.dom.client.MouseMoveEvent; 67 import com.google.gwt.event.dom.client.MouseMoveHandler; 68 import com.google.gwt.event.dom.client.MouseOutEvent; 69 import com.google.gwt.event.dom.client.MouseOutHandler; 70 import com.google.gwt.event.dom.client.MouseOverEvent; 71 import com.google.gwt.event.dom.client.MouseOverHandler; 72 import com.google.gwt.event.dom.client.MouseUpEvent; 73 import com.google.gwt.event.dom.client.MouseUpHandler; 74 import com.google.gwt.event.dom.client.TouchCancelEvent; 75 import com.google.gwt.event.dom.client.TouchCancelHandler; 76 import com.google.gwt.event.dom.client.TouchEndEvent; 77 import com.google.gwt.event.dom.client.TouchEndHandler; 78 import com.google.gwt.event.dom.client.TouchMoveEvent; 79 import com.google.gwt.event.dom.client.TouchMoveHandler; 80 import com.google.gwt.event.dom.client.TouchStartEvent; 81 import com.google.gwt.event.dom.client.TouchStartHandler; 82 import com.google.gwt.event.shared.HandlerRegistration; 83 84 /** 85 * <p>The {@link org.vectomatic.dom.svg.OMSVGTextContentElement} is inherited 86 * by various text-related interfaces, such as {@link org.vectomatic.dom.svg.OMSVGTextElement}, 87 * {@link org.vectomatic.dom.svg.OMSVGTSpanElement}, {@link org.vectomatic.dom.svg.OMSVGTRefElement}, 88 * {@link org.vectomatic.dom.svg.OMSVGAltGlyphElement} and {@link org.vectomatic.dom.svg.OMSVGTextPathElement}.</p> 89 * <p>For the methods on this interface that refer to an index to a character 90 * or a number of characters, these references are to be interpreted as an 91 * index to a UTF-16 code unit or a number of UTF-16 code units, respectively. 92 * This is for consistency with DOM Level 2 Core, where methods on the <code>CharacterData</code> 93 * interface use UTF-16 code units as indexes and counts within the character 94 * data. Thus for example, if the text content of a <a href='http://www.w3.org/TR/SVG11/text.html#TextElement' 95 * title='text element specification'>text</a> element is a single non-BMP 96 * character, such as U+10000, then invoking {@link org.vectomatic.dom.svg.OMSVGTextContentElement#getNumberOfChars()} 97 * on that element will return 2 since there are two UTF-16 code units (the 98 * surrogate pair) used to represent that one character.</p> 99 */ 100 public 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 }