mustang2247 / svgweb

Automatically exported from code.google.com/p/svgweb
Other
0 stars 0 forks source link

Implement getTransformToElement in SVGLocatable interface #434

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
JessyInk (Issue 391) uses getTransformToElement, which seems to zoom and
translate the entire viewport to fit a given element onto the SVG elements
view area. The SVG 1.1 spec doesn't have much to say about this, with only
the following IDL inside of SVGLocatable:

interface SVGLocatable { 
    readonly attribute SVGElement              nearestViewportElement;
    readonly attribute SVGElement              farthestViewportElement;
    SVGRect   getBBox (  );
    SVGMatrix getCTM (  );
    SVGMatrix getScreenCTM (  );
    SVGMatrix getTransformToElement ( in SVGElement element )
                    raises( SVGException );
  };

Documentation is really sparse on this method.

The SVG 1.1 test suite does have a test file for this method (and similar
other ones) named full-types-basicDOM-01-b.html. Inside that file is the
following testing line:

var matr =
getElementById('rotatedText').getTransformToElement(document.getElementById("par
entGroup"));

Where rotText is the #rotatedText element below:

<g font-family="sans-serif" font-size="12">
            <g id="parentGroup" transform="translate(70,-60)">
                <text id="rotatedText" transform="scale(0.6),rotate(45)" font-size="20"
x="30" y="150">Rotated Text for testing SVGLocatable</text>
            </g>

I found a Webkit bug that is now closed around implementing it there:
https://bugs.webkit.org/show_bug.cgi?id=11667 ; I've emailed the folks
listed there to see if they have any more info.

Original issue reported on code.google.com by bradneub...@gmail.com on 1 Dec 2009 at 6:16

GoogleCodeExporter commented 8 years ago
Attaching test case that comes from Batik originally and is now used by Webkit 
for
getTransformToElement.

Original comment by bradneub...@gmail.com on 1 Dec 2009 at 6:26

Attachments:

GoogleCodeExporter commented 8 years ago
The way I understand it, the method serves to obtain the transformation matrix 
that
converts the coordinate system of one object into the system of the other. In 
other
words it can be used to answer the question what are the coordinates of one 
object in
the coordinate system of the other.

It can be implemented using getScreenCTM (although there might be a more 
efficient
way to do it):

elem1.getTransformToElement(elem2)

is equivalent to:

function myGetTransformToElement(elem1, elem2)
{
    return elem2.getScreenCTM().inverse().multiply(elem1.getScreenCTM());
}

In the attached file there is a quick demonstration of the function (tested in 
Firefox).

Original comment by hannes.h...@gmail.com on 12 Dec 2009 at 12:01

Attachments: