xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thomas.dewe...@kodak.com
Subject Re: when does getBBox() become valid?
Date Tue, 02 May 2006 16:49:23 GMT
Hi Roger,

   A 'g' element can't be a child of a 'rect'.  I would suggest moving the 
creation of the g before
the creation of the 'rect' and append the rect to the g rather than the 
other way around...

   As it is the 'text' isn't part of the rendering tree since it is under 
the 'rect' element,
since it isn't rendered it has no bounds.

rogercritchlow@gmail.com wrote on 05/02/2006 10:28:35 AM:

> I have an existing document which has already been rendered.  Now I
> want to add another label to the document framed by a rectangle.
> 
> I construct the new node like this:
> 
>    protected Element nodeRectangularVertexIdentifier(String name, String 
rx) {
>       String[] parts = name.split(" to ");
>       Element node = getSVGDocument().createElementNS(svg, "rect");
>       node.setAttributeNS(null, "id", "f"+getIdNumber());
>       node.setAttributeNS(null, "width", "1");
>       node.setAttributeNS(null, "height", "1");
>       node.setAttributeNS(null, "rx", rx);
>       Element gNode = getSVGDocument().createElementNS(svg, "g");
>       gNode.setAttributeNS(null, "id", "t"+getIdNumber());
>       for (int i = 0; i < parts.length; i += 1) {
>          Element tNode = getSVGDocument().createElementNS(svg, "text");
>          tNode.setAttributeNS(null, "id", "t"+getIdNumber()+"-"+i);
>          tNode.setNodeValue(parts[i]);
>          gNode.appendChild(tNode);
>       }
>       node.appendChild(gNode);
>       return node;
>    }
> 
> Then I insert the node into the document:
> 
>       getSVGDocument().getElementById("labels").appendChild(gNode);
> 
> Then I want to center the text and adjust the rectangle size so it
> frames the text:
> 
>    protected void bindRectangularVertexIdentifierSize() {
>       // System.out.println("bind sizes for "+object);
>       SVGTextElement textNode =
> (SVGTextElement)getElementById("t"+getIdNumber()+"-0");
>       SVGRectElement rectNode = 
(SVGRectElement)getElementById("f"+getIdNumber());
>       SVGRect box = textNode.getBBox();
>       float dx = box.getX()+box.getWidth()/2;
>       float dy = box.getY()+box.getHeight()/2;
>       textNode.setAttributeNS(null, "x", Float.toString(-dx));
>       textNode.setAttributeNS(null, "y", Float.toString(-dy));
>       box = textNode.getBBox();
>       rectNode.setAttributeNS(null, "x", Float.toString(box.getX()-5));
>       rectNode.setAttributeNS(null, "y", Float.toString(box.getY()-5));
>       rectNode.setAttributeNS(null, "width", 
Float.toString(box.getWidth()+10));
>       rectNode.setAttributeNS(null, "height", 
Float.toString(box.getHeight()+10));
>    }
> 
> But textNode.getBBox() returns null, because the text hasn't been 
rendered yet.
> 
> Is there any way to prompt the rendering to happen or to be notified
> that the rendering is completed?
> 
> -- rec --
> 
> ---------------------------------------------------------------------
> 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


Mime
View raw message