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:[EMAIL PROTECTED] Sent: Wednesday, July 12, 2006 10:50 PM To: [email protected] 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 <[EMAIL PROTECTED] > 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:[EMAIL PROTECTED] Sent: Tuesday, July 11, 2006 6:13 AM To: [email protected] 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 <[EMAIL PROTECTED] > wrote: Hi, How I obtain a GraphicsNode from an Element object? Thanks, Charles --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
