xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Xavid Pretzer <xa...@src.ricoh.co.jp>
Subject Problem Obtaining Dimensions of Text Regions
Date Thu, 08 Jun 2006 03:01:51 GMT

I've recently been trying to use Batik to do some batch processing on 
some SVG files.  Part of what I'm trying to do involves finding the 
positions of various text and path elements.  However, when I try to get 
the bounding box of elements, they always return null.  Looking online, 
I think I might need some sort of context, but I was unable to figure 
out how to generate it properly.  Thank you in advance for your help.

I'm using Java 5 on Japanese Windows XP with the latest standard Batik 
from the download page.

Here's some example code that has the problem I'm encountering.  It 
simply tries to load an SVG file and find out the bounding boxes of all 
the text elements in it.  When I try it with various SVG files, it only 
outputs nulls.

import static 

import java.io.File;
import java.io.IOException;

import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
import org.apache.batik.util.XMLResourceDescriptor;
import org.w3c.dom.NodeList;
import org.w3c.dom.svg.SVGDocument;
import org.w3c.dom.svg.SVGTextElement;

public class BatikTestCase {

	public static void main(String[] args) {
		SVGDocument doc;
		try {
		    String parser = XMLResourceDescriptor.getXMLParserClassName();
		    SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
		    doc = f.createSVGDocument(new File(args[0]).toURI().toString());

			NodeList nodes = doc.getElementsByTagNameNS(SVG_NAMESPACE_URI,
			for (int lcv = 0; lcv < nodes.getLength(); lcv++) {
				SVGTextElement ste = (SVGTextElement)nodes.item(lcv);
		} catch (IOException ex) {


Xavid Pretzer

To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org

View raw message