xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sugaw...@humane-systems.co.jp (sugawara)
Subject RE: Problem Obtaining Dimensions of Text Regions
Date Thu, 08 Jun 2006 07:24:07 GMT
Hi Xavid,

You need to construct the GVT in advance of calling getBBox().
Try to add following lines immediately after doc.normalize();

  UserAgentAdapter ua = new UserAgentAdapter();
  DocumentLoader loader = new DocumentLoader(ua);
  BridgeContext ctx  = new BridgeContext(ua, loader);
  ctx.setDynamicState(BridgeContext.DYNAMIC);
  GVTBuilder builder = new GVTBuilder();
  GraphicsNode gvt = builder.build(ctx, doc);

Hope it helps.

Shin


> -----Original Message-----
> From: Xavid Pretzer [mailto:xavid@src.ricoh.co.jp]
> Sent: Thursday, June 08, 2006 12:02 PM
> To: batik-users@xmlgraphics.apache.org
> Subject: Problem Obtaining Dimensions of Text Regions
> 
> 
> Hello,
> 
> 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 
> org.apache.batik.dom.svg.SVGDOMImplementation.SVG_NAMESPACE_URI;
> 
> 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());
> 		
> 		    doc.normalize();
> 
> 			NodeList nodes = 
> doc.getElementsByTagNameNS(SVG_NAMESPACE_URI,
> 					"text");
> 			
> 			for (int lcv = 0; lcv < nodes.getLength(); lcv++) {
> 				SVGTextElement ste = 
> (SVGTextElement)nodes.item(lcv);
> 				
> 				System.out.println(ste.getBBox());
> 			}
> 		} catch (IOException ex) {
> 		     System.exit(1);
> 		}
> 	}
> 
> }
> 
> Thanks,
> Xavid Pretzer
> 
> ---------------------------------------------------------------------
> 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