xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Roger Critchlow" <...@elf.org>
Subject when does getBBox() become valid?
Date Tue, 02 May 2006 14:28:35 GMT
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);
		return node;

Then I insert the node into the document:


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 =
		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

View raw message