You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Charles Abreu <ch...@gmail.com> on 2006/07/10 21:25:21 UTC
GraphicsNode from an Element
Hi,
How I obtain a GraphicsNode from an Element object?
Thanks,
Charles
RE: GraphicsNode from an Element
Posted by sugawara <su...@humane-systems.co.jp>.
Hi Charles,
As Thomas suggested, getBBox() is a way to overcome arbitrary user units.
You can always get right coordinates by following code;
// get center coord. of the element
SVGRect bbox = ((SVGGraphicsElement)element).getBBox();
float eCX = bbox.getX() + bbox.getWidth() / 2;
float eCY = bbox.getY() + bbox.getHeight() / 2;
Good luck,
Shin
-----Original Message-----
From: Charles Abreu [mailto:charlesabreu@gmail.com]
Sent: Wednesday, July 12, 2006 10:50 PM
To: batik-users@xmlgraphics.apache.org
Subject: Re: GraphicsNode from an Element
sugawara,
It works very well. However, the drawback I found is that it gets a little
complicated to parse and calculate the coordinate attributes of the element
if they were specified with arbitrary user units (cm, em). I was thinking
Batik already provided built in mechanisms to map the two coordinate
systems, so that I dont't have to involve myself with the boring details ;-)
I hope I'm only not seeing the way to make it to work.
Thanks for your help!
On 7/10/06, sugawara <sugawara@humane-systems.co.jp > wrote:
Hi Charles,
Following code could be an answer for your case.
Note that the code is assuming the target element has x, y, width and height
attributes.
public void highlight(Element element) {
// get center coord. of the element
float ex = Float.parseFloat(element.getAttribute ("x"));
float ey = Float.parseFloat(element.getAttribute("y"));
float ew = Float.parseFloat(element.getAttribute("width"));
float eh = Float.parseFloat(element.getAttribute("height"));
float eCX = ex + ew / 2;
float eCY = ey + eh / 2;
// zoom in (x2)
double scaleRate = 2d; // scale by x2
AffineTransform sat = AffineTransform.getScaleInstance(scaleRate,
scaleRate);
canvas.setRenderingTransform ( sat );
// get center coord. of the canvas
float canvasCX = canvas.getWidth() / 2;
float canvasCY = canvas.getHeight() / 2;
Point p = new Point((int)canvasCX, (int)canvasCY);
p = invert(canvas, p);
// centering the element
double dx = p.x - eCX;
double dy = p.y - eCY;
AffineTransform at =
(AffineTransform)canvas.getRenderingTransform().clone();
AffineTransform at1 = AffineTransform.getTranslateInstance (dx, dy);
at.concatenate( at1 ); // centering
canvas.setRenderingTransform( at );
}
public static Point invert(JSVGCanvas canvas, Point p) {
float[] xy1 = { p.x, p.y };
float[] xy2 = new float[2];
try {
AffineTransform rat = canvas.getRenderingTransform();
AffineTransform iat = rat.createInverse();
iat.transform( xy1, 0, xy2, 0, 1 );
} catch (NoninvertibleTransformException ex) {}
return new Point((int)xy2[0], (int)xy2[1]);
}
Hope this helps...
Shin
-----Original Message-----
From: Charles Abreu [mailto:charlesabreu@gmail.com]
Sent: Tuesday, July 11, 2006 6:13 AM
To: batik-users@xmlgraphics.apache.org
Subject: Re: GraphicsNode from an Element
What I want to do is to zoom in and to center the SVGCanvas on to an
arbitrary graphics element. Looking at the svg browser code, I saw a code
fragment where the zooming and centering task is done for text search, but
it works begining from a selected GraphicsNode object. In that case, a
GVTTreeWalker was used to walk down the tree looking for TextNode's whose
text property match the user entered string. In my case, the use will not
provide any input. An internal event in my system will trigger a search for
an specific element in the DOM tree and I need to highlight it when it is
found.
Can somebody help?
Thanks in advance.
Charles
On 7/10/06, Charles Abreu <charlesabreu@gmail.com > wrote:
Hi,
How I obtain a GraphicsNode from an Element object?
Thanks,
Charles
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: GraphicsNode from an Element
Posted by Charles Abreu <ch...@gmail.com>.
sugawara,
It works very well. However, the drawback I found is that it gets a little
complicated to parse and calculate the coordinate attributes of the element
if they were specified with arbitrary user units (cm, em). I was thinking
Batik already provided built in mechanisms to map the two coordinate
systems, so that I dont't have to involve myself with the boring details ;-)
I hope I'm only not seeing the way to make it to work.
Thanks for your help!
On 7/10/06, sugawara <su...@humane-systems.co.jp> wrote:
>
> Hi Charles,
>
> Following code could be an answer for your case.
> Note that the code is assuming the target element has x, y, width and
> height
> attributes.
>
> public void highlight(Element element) {
>
> // get center coord. of the element
> float ex = Float.parseFloat(element.getAttribute("x"));
> float ey = Float.parseFloat(element.getAttribute("y"));
> float ew = Float.parseFloat(element.getAttribute("width"));
> float eh = Float.parseFloat(element.getAttribute("height"));
> float eCX = ex + ew / 2;
> float eCY = ey + eh / 2;
>
> // zoom in (x2)
> double scaleRate = 2d; // scale by x2
> AffineTransform sat = AffineTransform.getScaleInstance(scaleRate,
> scaleRate);
> canvas.setRenderingTransform( sat );
>
> // get center coord. of the canvas
> float canvasCX = canvas.getWidth() / 2;
> float canvasCY = canvas.getHeight() / 2;
> Point p = new Point((int)canvasCX, (int)canvasCY);
> p = invert(canvas, p);
>
> // centering the element
> double dx = p.x - eCX;
> double dy = p.y - eCY;
> AffineTransform at =
> (AffineTransform)canvas.getRenderingTransform().clone();
> AffineTransform at1 = AffineTransform.getTranslateInstance(dx, dy);
> at.concatenate( at1 ); // centering
> canvas.setRenderingTransform( at );
> }
> public static Point invert(JSVGCanvas canvas, Point p) {
> float[] xy1 = { p.x, p.y };
> float[] xy2 = new float[2];
> try {
> AffineTransform rat = canvas.getRenderingTransform();
> AffineTransform iat = rat.createInverse();
> iat.transform( xy1, 0, xy2, 0, 1 );
> } catch (NoninvertibleTransformException ex) {}
> return new Point((int)xy2[0], (int)xy2[1]);
> }
>
> Hope this helps...
>
> Shin
> -----Original Message-----
> From: Charles Abreu [mailto:charlesabreu@gmail.com]
> Sent: Tuesday, July 11, 2006 6:13 AM
> To: batik-users@xmlgraphics.apache.org
> Subject: Re: GraphicsNode from an Element
>
>
> What I want to do is to zoom in and to center the SVGCanvas on to an
> arbitrary graphics element. Looking at the svg browser code, I saw a code
> fragment where the zooming and centering task is done for text search, but
> it works begining from a selected GraphicsNode object. In that case, a
> GVTTreeWalker was used to walk down the tree looking for TextNode's whose
> text property match the user entered string. In my case, the use will not
> provide any input. An internal event in my system will trigger a search
> for
> an specific element in the DOM tree and I need to highlight it when it is
> found.
>
> Can somebody help?
>
> Thanks in advance.
>
> Charles
>
>
> On 7/10/06, Charles Abreu <charlesabreu@gmail.com > wrote:
> Hi,
>
> How I obtain a GraphicsNode from an Element object?
>
> Thanks,
>
>
> Charles
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>
Re: GraphicsNode from an Element
Posted by th...@kodak.com.
Hi Abreu,
"Charles Abreu" <ch...@gmail.com> wrote on 07/12/2006 09:29:22 AM:
> Element rectElement =
svgCanvas.getSVGDocument().getElementById("myRectElement");
> SVGRect bbox = SVGLocatableSupport.getBBox(rectElement);
>
> The first line returns the expected element, but I have no idea why the
second
> line is aways returning null, no matter if I try several types of
elements.
> Are there any especial ways or situations where the getBBox() will not
work correctly?
It sounds like you need to boot the SVG DOM:
http://wiki.apache.org/xmlgraphics-batik/BootSvgAndCssDom
> Anyway, do you have one piece of code to illustrate your suggestion of
> combining getBBox() with getScreenCMT() to get the screen location of
the element?
Unfortunately nothing really handy. Suffice it to say you just need
to map the corner points of the BBox through the matrix returned
by getScreenCTM to get the corner's location in screen pixels.
> On 7/11/06, thomas.deweese@kodak.com <th...@kodak.com> wrote:
> Hi Charles,
>
> You might also want to look at the standard SVG DOM.
> Which includes a method 'getBBox()' that returns the bounding
> box of the element in the element's user coordinate system.
> If this is paired with 'getScreenCTM()' you can fairly easily calculate
> the location on the screen of any element in the DOM (and these
> are standard SVG as opposed to Batik specific).
>
> "Charles Abreu" <charlesabreu@gmail.com > wrote on 07/10/2006 05:13:27
PM:
>
> > What I want to do is to zoom in and to center the SVGCanvas on to an
> arbitrary
> > graphics element. Looking at the svg browser code, I saw a code
fragment
> where
> > the zooming and centering task is done for text search, but it works
> begining
> > from a selected GraphicsNode object. In that case, a GVTTreeWalker was
> used to
> > walk down the tree looking for TextNode's whose text property match
the
> user
> > entered string. In my case, the use will not provide any input. An
> internal
> > event in my system will trigger a search for an specific element in
the
> DOM
> > tree and I need to highlight it when it is found.
> >
> > Can somebody help?
> >
> > Thanks in advance.
> >
> > Charles
>
> > On 7/10/06, Charles Abreu <charlesabreu@gmail.com > wrote:
> > Hi,
> >
> > How I obtain a GraphicsNode from an Element object?
> >
> > Thanks,
> >
> > Charles
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: GraphicsNode from an Element
Posted by Charles Abreu <ch...@gmail.com>.
Hi, Thomas
Element rectElement = svgCanvas.getSVGDocument
().getElementById("myRectElement");
SVGRect bbox = SVGLocatableSupport.getBBox(rectElement);
The first line returns the expected element, but I have no idea why the
second line is aways returning null, no matter if I try several types of
elements. Are there any especial ways or situations where the getBBox() will
not work correctly?
Anyway, do you have one piece of code to illustrate your suggestion of
combining getBBox() with getScreenCMT() to get the screen location of the
element?
Thanks.
Charles
On 7/11/06, thomas.deweese@kodak.com <th...@kodak.com> wrote:
>
> Hi Charles,
>
> You might also want to look at the standard SVG DOM.
> Which includes a method 'getBBox()' that returns the bounding
> box of the element in the element's user coordinate system.
> If this is paired with 'getScreenCTM()' you can fairly easily calculate
> the location on the screen of any element in the DOM (and these
> are standard SVG as opposed to Batik specific).
>
> "Charles Abreu" <ch...@gmail.com> wrote on 07/10/2006 05:13:27 PM:
>
> > What I want to do is to zoom in and to center the SVGCanvas on to an
> arbitrary
> > graphics element. Looking at the svg browser code, I saw a code fragment
> where
> > the zooming and centering task is done for text search, but it works
> begining
> > from a selected GraphicsNode object. In that case, a GVTTreeWalker was
> used to
> > walk down the tree looking for TextNode's whose text property match the
> user
> > entered string. In my case, the use will not provide any input. An
> internal
> > event in my system will trigger a search for an specific element in the
> DOM
> > tree and I need to highlight it when it is found.
> >
> > Can somebody help?
> >
> > Thanks in advance.
> >
> > Charles
>
> > On 7/10/06, Charles Abreu <charlesabreu@gmail.com > wrote:
> > Hi,
> >
> > How I obtain a GraphicsNode from an Element object?
> >
> > Thanks,
> >
> > Charles
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>
RE: GraphicsNode from an Element
Posted by sugawara <su...@humane-systems.co.jp>.
Hi Charles,
Following code could be an answer for your case.
Note that the code is assuming the target element has x, y, width and height
attributes.
public void highlight(Element element) {
// get center coord. of the element
float ex = Float.parseFloat(element.getAttribute("x"));
float ey = Float.parseFloat(element.getAttribute("y"));
float ew = Float.parseFloat(element.getAttribute("width"));
float eh = Float.parseFloat(element.getAttribute("height"));
float eCX = ex + ew / 2;
float eCY = ey + eh / 2;
// zoom in (x2)
double scaleRate = 2d; // scale by x2
AffineTransform sat = AffineTransform.getScaleInstance(scaleRate,
scaleRate);
canvas.setRenderingTransform( sat );
// get center coord. of the canvas
float canvasCX = canvas.getWidth() / 2;
float canvasCY = canvas.getHeight() / 2;
Point p = new Point((int)canvasCX, (int)canvasCY);
p = invert(canvas, p);
// centering the element
double dx = p.x - eCX;
double dy = p.y - eCY;
AffineTransform at =
(AffineTransform)canvas.getRenderingTransform().clone();
AffineTransform at1 = AffineTransform.getTranslateInstance(dx, dy);
at.concatenate( at1 ); // centering
canvas.setRenderingTransform( at );
}
public static Point invert(JSVGCanvas canvas, Point p) {
float[] xy1 = { p.x, p.y };
float[] xy2 = new float[2];
try {
AffineTransform rat = canvas.getRenderingTransform();
AffineTransform iat = rat.createInverse();
iat.transform( xy1, 0, xy2, 0, 1 );
} catch (NoninvertibleTransformException ex) {}
return new Point((int)xy2[0], (int)xy2[1]);
}
Hope this helps...
Shin
-----Original Message-----
From: Charles Abreu [mailto:charlesabreu@gmail.com]
Sent: Tuesday, July 11, 2006 6:13 AM
To: batik-users@xmlgraphics.apache.org
Subject: Re: GraphicsNode from an Element
What I want to do is to zoom in and to center the SVGCanvas on to an
arbitrary graphics element. Looking at the svg browser code, I saw a code
fragment where the zooming and centering task is done for text search, but
it works begining from a selected GraphicsNode object. In that case, a
GVTTreeWalker was used to walk down the tree looking for TextNode's whose
text property match the user entered string. In my case, the use will not
provide any input. An internal event in my system will trigger a search for
an specific element in the DOM tree and I need to highlight it when it is
found.
Can somebody help?
Thanks in advance.
Charles
On 7/10/06, Charles Abreu <charlesabreu@gmail.com > wrote:
Hi,
How I obtain a GraphicsNode from an Element object?
Thanks,
Charles
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: GraphicsNode from an Element
Posted by th...@kodak.com.
Hi Charles,
You might also want to look at the standard SVG DOM.
Which includes a method 'getBBox()' that returns the bounding
box of the element in the element's user coordinate system.
If this is paired with 'getScreenCTM()' you can fairly easily calculate
the location on the screen of any element in the DOM (and these
are standard SVG as opposed to Batik specific).
"Charles Abreu" <ch...@gmail.com> wrote on 07/10/2006 05:13:27 PM:
> What I want to do is to zoom in and to center the SVGCanvas on to an
arbitrary
> graphics element. Looking at the svg browser code, I saw a code fragment
where
> the zooming and centering task is done for text search, but it works
begining
> from a selected GraphicsNode object. In that case, a GVTTreeWalker was
used to
> walk down the tree looking for TextNode's whose text property match the
user
> entered string. In my case, the use will not provide any input. An
internal
> event in my system will trigger a search for an specific element in the
DOM
> tree and I need to highlight it when it is found.
>
> Can somebody help?
>
> Thanks in advance.
>
> Charles
> On 7/10/06, Charles Abreu <charlesabreu@gmail.com > wrote:
> Hi,
>
> How I obtain a GraphicsNode from an Element object?
>
> Thanks,
>
> Charles
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: GraphicsNode from an Element
Posted by Charles Abreu <ch...@gmail.com>.
What I want to do is to zoom in and to center the SVGCanvas on to an
arbitrary graphics element. Looking at the svg browser code, I saw a code
fragment where the zooming and centering task is done for text search, but
it works begining from a selected GraphicsNode object. In that case, a
GVTTreeWalker was used to walk down the tree looking for TextNode's whose
text property match the user entered string. In my case, the use will not
provide any input. An internal event in my system will trigger a search for
an specific element in the DOM tree and I need to highlight it when it is
found.
Can somebody help?
Thanks in advance.
Charles
On 7/10/06, Charles Abreu <ch...@gmail.com> wrote:
>
> Hi,
>
> How I obtain a GraphicsNode from an Element object?
>
> Thanks,
>
> Charles
>
Re: GraphicsNode from an Element
Posted by André Ávila <as...@nextech.com.br>.
Hi Charles,
You can build it:
UserAgentAdapter userAgentAdapter = new UserAgentAdapter();
BridgeContext bridgeContext = new BridgeContext(userAgentAdapter);
GVTBuilder gvtBuilder = new GVTBuilder();
GraphicsNode graphicsNode = gvtBuilder.build(bridgeContext, svgDocument);
Hope this helps,
André
----- Original Message -----
From: Charles Abreu
To: batik-users@xmlgraphics.apache.org
Sent: Wednesday, July 12, 2006 11:36 AM
Subject: Re: GraphicsNode from an Element
And from where I get the bridgeContex? I tried to use the bridgeContext field inside the svgCanvas, but its getGraphicsNode() only retuns null.
On 7/10/06, Tonny Kohar <to...@kiyut.com> wrote:
Hi,
On Mon, 2006-07-10 at 16:25 -0300, Charles Abreu wrote:
> Hi,
>
> How I obtain a GraphicsNode from an Element object?
>
GraphicsNode gn = bridgeContext.getGraphicsNode(svgElement);
Regards
Tonny Kohar
--
Sketsa
SVG Graphics Editor
http://www.kiyut.com
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: GraphicsNode from an Element
Posted by th...@kodak.com.
Hi Charles,
"Charles Abreu" <ch...@gmail.com> wrote on 07/12/2006 10:36:46 AM:
> And from where I get the bridgeContex? I tried to use the bridgeContext
field
> inside the svgCanvas, but its getGraphicsNode() only retuns null.
It sounds like you have a static document, if you want to
use the SVN DOM on a static SVG document in the Canvas you need
to tell the canvas ahead of time:
http://xmlgraphics.apache.org/batik/faqs.html#faq-21
> On 7/10/06, Tonny Kohar <to...@kiyut.com> wrote:
> Hi,
>
> On Mon, 2006-07-10 at 16:25 -0300, Charles Abreu wrote:
> > Hi,
> >
> > How I obtain a GraphicsNode from an Element object?
> >
>
> GraphicsNode gn = bridgeContext.getGraphicsNode(svgElement);
>
> Regards
> Tonny Kohar
> --
> Sketsa
> SVG Graphics Editor
> http://www.kiyut.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: GraphicsNode from an Element
Posted by Charles Abreu <ch...@gmail.com>.
And from where I get the bridgeContex? I tried to use the bridgeContext
field inside the svgCanvas, but its getGraphicsNode() only retuns null.
On 7/10/06, Tonny Kohar <to...@kiyut.com> wrote:
>
> Hi,
>
> On Mon, 2006-07-10 at 16:25 -0300, Charles Abreu wrote:
> > Hi,
> >
> > How I obtain a GraphicsNode from an Element object?
> >
>
> GraphicsNode gn = bridgeContext.getGraphicsNode(svgElement);
>
> Regards
> Tonny Kohar
> --
> Sketsa
> SVG Graphics Editor
> http://www.kiyut.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>
Re: GraphicsNode from an Element
Posted by Tonny Kohar <to...@kiyut.com>.
Hi,
On Mon, 2006-07-10 at 16:25 -0300, Charles Abreu wrote:
> Hi,
>
> How I obtain a GraphicsNode from an Element object?
>
GraphicsNode gn = bridgeContext.getGraphicsNode(svgElement);
Regards
Tonny Kohar
--
Sketsa
SVG Graphics Editor
http://www.kiyut.com
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org