javauis/m2g_qt/javasrc/org/w3c/dom/svg/SVGLocatableElement.java
changeset 80 d6dafc5d983f
parent 56 abc41079b313
equal deleted inserted replaced
78:71ad690e91f5 80:d6dafc5d983f
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 package org.w3c.dom.svg;
       
    18 
       
    19 
       
    20 /**
       
    21  * This interface represents an SVGLocatableElement. It is implemented by all drawable SVG elements
       
    22  * in the document tree. Drawable elements are: <rect>, <circle>, <ellipse>,
       
    23  * <line>, <path> <use> <image> <text>, <svg>, <a>,
       
    24  * and &lt;g&gt;. <b>Note</b> that animations will have an effect on the values of bounding box.
       
    25  *
       
    26  * <br>
       
    27  * <br>
       
    28  * <br>
       
    29  *The following example further clarify the behavior of the getBBox()
       
    30  *method. The example have a short explanation, an SVG fragment and are
       
    31  *followed by a set of bounding box values which have the following
       
    32  *format:<br>
       
    33  *<tt><br>
       
    34  *[elementId] : {x, y, width, height} | {null}</tt><br>
       
    35  *<br>
       
    36  *where x, y, width and height define the values of the SVGRect object's
       
    37  *returned from a getBBox call on the element with the specified id.
       
    38  *There are a few cases where the bounding box may be null (see example
       
    39  *6).<br>
       
    40  *<br>
       
    41  *<h3>Example #1: Simple groups and bounds</h3>
       
    42  *<br>
       
    43  *This first example shows the values returned by the getBBox method for
       
    44  *various simple basic shapes and groups. In particular, it shows that
       
    45  *the transform, on an element, does not change the value of its user
       
    46  *space bounding box.<br>
       
    47  *<br>
       
    48  *<tt>&lt;g id="group1" transform="translate(10, 20)" fill="red" &gt;
       
    49  *<br>
       
    50  *&nbsp;&lt;rect id="rect1" transform="scale(2)" x="10" y="10" width="50"
       
    51  *height="50"/&gt;
       
    52  *<br>
       
    53  *&nbsp;&lt;rect id="rect2" x="10" y="10" width="100" height="100"/&gt;
       
    54  *<br>
       
    55  *&nbsp;&lt;g id="group2" transform="translate(10, 20)" &gt;
       
    56  *<br>
       
    57  *&nbsp;&nbsp; &lt;rect id="rect3" x="0" y="10" width="150" height="50"/&gt;
       
    58  *<br>
       
    59  *&nbsp;&nbsp; &lt;circle id="circle1" cx="20" cy="20" r="100" /&gt;
       
    60  *<br>
       
    61  *&nbsp;&lt;/g&gt;
       
    62  *<br>
       
    63  *&lt;/g&gt;
       
    64  *<br>
       
    65  *</tt><br>
       
    66  *<tt>[group1] : {-70.0, -60.0, 230.0, 200.0}
       
    67  *<br>
       
    68  *[rect1] : {10.0, 10.0, 50.0, 50.0}
       
    69  *<br>
       
    70  *[rect2] : {10.0, 10.0, 100.0, 100.0}
       
    71  *<br>
       
    72  *[group2] : {-80.0, -80.0, 230.0, 200.0}
       
    73  *<br>
       
    74  *[rect3] : {0.0, 10.0, 150.0, 50.0}
       
    75  *<br>
       
    76  *[circle1] : {-80.0, -80.0, 200.0, 200.0}
       
    77  *</tt><br>
       
    78  *<br>
       
    79  *<h3>Example #2: Bounding box on zero width or height rectangle<br>
       
    80  *</h3>
       
    81  *This example illustrates that the bounding box on elements is based on
       
    82  *the element's geometry coordinates. For example, the bounding box on a
       
    83  *zero-width rectangle is defined (see below), even though the rectangle
       
    84  *is not rendered.<br>
       
    85  *<pre><tt>&lt;g id="group1" transform="translate(10, 20)" fill="red" &gt;</tt></pre>
       
    86  *<pre><tt>&nbsp;&nbsp; </tt>&lt;rect id="rect2" x="10" y="10" width="400" height="0"/&gt;</pre>
       
    87  *<pre wrap=""><tt>   &lt;g id="group2" transform="translate(10, 20)" &gt;
       
    88  *      &lt;rect id="rect3" x="0" y="10" width="150" height="50"/&gt;
       
    89  *   &lt;/g&gt;</tt><tt>
       
    90  *&lt;/g&gt;
       
    91  *</tt></pre>
       
    92  *<pre><tt>[group1] : {10.0, 10.0, 400.0, 70.0}
       
    93  *</tt>[rect2] : {10.0, 10.0, 400.0, 0.0}<tt>
       
    94  *</tt>[group2] : {0.0, 10.0, 150.0, 50.0}<tt>
       
    95  *[rect3] : {0.0, 10.0, 150.0, 50.0}</tt>
       
    96  *</pre>
       
    97  *<h3>Example #3: Bounding Box on zero radius ellipses.</h3>
       
    98  *This is another example of how bounding boxes are based on the
       
    99  *element's geometry. Here, the bounding box of an ellipse with a zero
       
   100  *x-axis radius is still defined, even though the ellipse is not rendered.<br>
       
   101  *<pre wrap="">&lt;svg id="mySVG" width="10" height="20"&gt;
       
   102  *&lt;g id="group1" transform="translate(10, 20)" fill="red" &gt;
       
   103  *  &lt;rect id="rect1" x="10" y="10" width="100" height="100"/&gt;
       
   104  *  &lt;ellipse id="ellipse1" cx="20" cy="20" rx="0" ry="70" /&gt;
       
   105  *&lt;/g&gt;</pre>
       
   106  *<tt>[mySVG] : {20.0, -30.0, 100.0, 160.0}
       
   107  *<br>
       
   108  *[group1] : {10.0, -50.0, 100.0, 160.0}
       
   109  *<br>
       
   110  *[rect1] : {10.0, 10.0, 100.0, 100.0}
       
   111  *<br>
       
   112  *[ellipse1] : {20.0, -50.0, 0.0, 140.0}
       
   113  *</tt><br>
       
   114  *<h3>Example #4: Viewports do not clip bounding boxes</h3>
       
   115  *This example shows that no matter what the viewport is on the root SVG
       
   116  *element, the bounding boxes, based on the geometry, are still defined.
       
   117  *Here, even though the root svg has a zero width, the bounding boxes for
       
   118  *the root itself and its children is precisely defined.<br>
       
   119  *<pre wrap="">&lt;svg id="mySVG" width="0" height="50"&gt;
       
   120  *  &lt;g id="group1" transform="translate(10, 20)" fill="red" &gt;
       
   121  *    &lt;rect id="rect1" x="10" y="10" width="50" height="50"/&gt;
       
   122  *    &lt;g id="group2" transform="translate(10, 20)" &gt;
       
   123  *      &lt;rect id="rect2" x="0" y="10" width="150" height="0"/&gt;
       
   124  *      &lt;circle id="circle1" cx="20" cy="20" r="500" /&gt;
       
   125  *    &lt;/g&gt;
       
   126  *  &lt;/g&gt;
       
   127  *&lt;/svg&gt;
       
   128  *</pre>
       
   129  *<tt>[mySVG] : {-460.0, -440.0, 1000.0, 1000.0}
       
   130  *<br>
       
   131  *[group1] : {-470.0, -460.0, 1000.0, 1000.0}
       
   132  *<br>
       
   133  *[rect1] : {10.0, 10.0, 50.0, 50.0}
       
   134  *<br>
       
   135  *[group2] : {-480.0, -480.0, 1000.0, 1000.0}
       
   136  *<br>
       
   137  *[rect2] : {0.0, 10.0, 150.0, 0.0}
       
   138  *<br>
       
   139  *[circle1] : {-480.0, -480.0, 1000.0, 1000.0}
       
   140  *</tt><br>
       
   141  *<h3>Example #5: getBBox on &lt;use&gt;</h3>
       
   142  *This example shows that the bounding box for a &lt;use&gt; element
       
   143  *accounts for the x and y attributes defined on the element, just like
       
   144  *the x and y attributes impact the bounding box computation on a
       
   145  *&lt;rect&gt; or on an &lt;image&gt; element.<br>
       
   146  *<br>
       
   147  *<tt>&lt;svg&gt;
       
   148  *<br>
       
   149  *&nbsp; &lt;defs&gt;
       
   150  *<br>
       
   151  *&nbsp;&nbsp;&nbsp;&nbsp; &lt;rect id="myRect" x="0" y="0" width="60" height="40" /&gt;
       
   152  *<br>
       
   153  *&nbsp; &lt;/defs&gt;
       
   154  *<br>
       
   155  *&nbsp; &lt;use id="myUse" xlink:href="#myRect" x="-30" y="-20" /&gt;
       
   156  *<br>
       
   157  *&lt;/svg&gt;
       
   158  *<br>
       
   159  *</tt>
       
   160  *<br>
       
   161  *<tt>[myRect] : {0.0, 0.0, 60.0, 40.0}
       
   162  *<br>
       
   163  *[myUse] : {-30.0, -20.0, 60.0, 40.0}
       
   164  *</tt><br>
       
   165  *<h3>Example #6: Empty group</h3>
       
   166  *This example shows that the bounding box for an empty group is null. By
       
   167  *the same token, the bounding box of a &lt;path&gt; with an empty
       
   168  *SVGPath (i.e., one with no path commands, which may happen after
       
   169  *creating a new &lt;path&gt; element with a Document.createElementNS
       
   170  *call) is also null.<br>
       
   171  *<br>
       
   172  *<tt>&lt;g id="emptyG" /&gt;
       
   173  *<br>
       
   174  *<br>
       
   175  *[emptyG] : {null}
       
   176  *</tt><br>
       
   177  *<br>
       
   178  *<h3>Example #7: Impact of display='none' and visibility='hidden'<br>
       
   179  *</h3>
       
   180  *This example shows how the bounding box of children with display='none'
       
   181  *are not accounted for in the computation of their parent's bounding
       
   182  *box. This reflects the definition of the display property and its
       
   183  *impact on rendering and bounding box computation. The example also
       
   184  *shows that elements with a 'hidden' visibility still contribute to
       
   185  *their parent's bounding box computation.<br>
       
   186  *<br>
       
   187  *<tt>&lt;g id="g1"&gt; <br>
       
   188  *&nbsp;&nbsp;&nbsp; &lt;g id="g1.1.display.none" display="none"&gt; <br>
       
   189  *&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;rect id="rect1" x="10" y="10" width="40" height="40"/&gt;<br>
       
   190  *&nbsp;&nbsp;&nbsp; &lt;g/&gt;
       
   191  *<br>
       
   192  *&nbsp;&nbsp;&nbsp; &lt;rect id="rect2.visibility.hidden" visibility="hidden" <br>
       
   193  *&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x="30" y="60" width="10" height="20"/&gt;
       
   194  *<br>
       
   195  *&lt;/g&gt;</tt><br>
       
   196  *<br>
       
   197  *<tt>[g1] : {30.0, 60.0, 10.0, 20.0} <br>
       
   198  *[g1.1.display.none] : {10.0, 10.0, 40.0, 40.0}<br>
       
   199  *[rect1] : {10.0, 10.0, 40.0, 40.0}<br>
       
   200  *[rec2.visibility.hidden] : {30.0, 60.0, 10.0, 20.0}</tt><br>
       
   201  *<h3>Example #8: Concatenating bounding boxes in the container's user
       
   202  *space.<br>
       
   203  *</h3>
       
   204  *This example shows how the concatenation and computation of bounding
       
   205  *boxes for container element happens in the container's user space.<br>
       
   206  *<br>
       
   207  *<tt>&lt;g id="g1"&gt;<br>
       
   208  *&nbsp; &lt;line id="line1" x2="100" y2="100" transform="rotate(-45)"/&gt;<br>
       
   209  *&lt;/g&gt;</tt><br>
       
   210  *<tt><br>
       
   211  *[g1] : {0.0, 0.0, 141.42136, 0}<br>
       
   212  *[line1] : {0.0, 0.0, 100.0, 100.0}</tt><br>
       
   213  *<h3>Example #9: No influence of stroke-width.</h3>
       
   214  *This example illustrates that stroking has no impact on the computation
       
   215  *of bounding boxes.<br>
       
   216  *<tt><br>
       
   217  *&lt;g&gt;<br>
       
   218  *&nbsp;&nbsp; &lt;line id="thickLine" stroke-width="10" x2="100" y2="0" /&gt;<br>
       
   219  *&lt;/g&gt;</tt><br>
       
   220  *<br>
       
   221  *[thickLine] : {0.0, 0.0, 100.0, 0.0}<br>
       
   222  *<br>
       
   223  *<h3>Example #10: No influence of viewBox.</h3>
       
   224  *This example illustrates that viewBox has no impact on the computation
       
   225  *of bounding boxes.<br>
       
   226  *<tt><br>
       
   227  *&lt;svg id="rootSvg" width="500" height="300" viewBox="0 0 200 100" &gt;<br>
       
   228  *&nbsp;&nbsp; &lt;rect x="-100" y="-200" width="500" height="100" /&gt;<br>
       
   229  *&lt;/svg&gt;</tt><br>
       
   230  *<br>
       
   231  *[rootSVG] : {-100, -200, 500, 100}<br>
       
   232  *
       
   233  *
       
   234  */
       
   235 public interface SVGLocatableElement extends SVGElement
       
   236 {
       
   237 
       
   238     /**
       
   239      * <p>
       
   240      * Returns the tight bounding box in current user coordinate space. Tight bounding box is the smallest
       
   241      * possible rectangle that includes the geometry of all contained graphics elements excluding stroke.
       
   242      * The calculation is done in the user coordinate space of the element. When bounding box
       
   243      * is calculated elements with display property (trait) set to none are ignored. Exact rules for the bounding
       
   244      * box calculation are given in the <a href="http://www.w3.org/TR/SVG/coords.html#ObjectBoundingBox">SVG spec</a>.
       
   245      * </p>
       
   246      *
       
   247      * @return the tight bounding box in current user coordinate space.
       
   248      */
       
   249     public SVGRect getBBox();
       
   250 
       
   251     /**
       
   252      * <p>
       
   253      * Returns the transformation matrix from current user units (i.e., after application of the transform attribute, if any)
       
   254      * to the parent user agent's notion of a "pixel". For display devices, ideally this represents a physical screen pixel.
       
   255      * For other devices or environments where physical pixel sizes are not known, then an algorithm similar to the CSS2
       
   256      * definition of a "pixel" can be used instead. Note that <code>null</code> is returned if this element is not hooked into the
       
   257      * document tree.
       
   258      * </p>
       
   259      *
       
   260      * @return the transformation matrix from current user units to the parent user agent's notion of a "pixel".
       
   261      */
       
   262     public SVGMatrix getScreenCTM();
       
   263 
       
   264     /**
       
   265      * <p>
       
   266      * Returns the tight bounding box in screen coordinate space. Tight bounding box is the smallest
       
   267      * possible rectangle that includes the geometry of all contained graphics elements excluding stroke.
       
   268      * The box coordinates are in the screen coordinate space, which is connected to the current user
       
   269      * coordinate space by the matrix returned by {@link org.w3c.dom.svg.SVGLocatableElement#getScreenCTM getScreenCTM} method.
       
   270      * Note that <code>null</code> is returned if this element is not hooked into the
       
   271      * document tree.
       
   272      * </p>
       
   273      *
       
   274      * @return the tight bounding box in screen coordinate space.
       
   275      */
       
   276     public SVGRect getScreenBBox();
       
   277 }