Hi Charles,
I'm not sure if this helps you, but I've found bbox to be flakey in some
situations when the element you're using is text. Of course, it might've been
how I was doing things (likely), but if you're not after the bbox per se and
just need some width measurement you could try getComputedTextLength().
Cheers,
Andrew
On 21/02/2012, at 9:16 AM, Charles Seelig wrote:
Hello, all.
I'm wondering if anyone could point me in the right direction re: coaxing an
SVGTextElement to return a correct bounding box when the text contains ISO
encoded characters.
SVGDocument doc = makeSvgDocument(svgString);
SVGTextElement svgTextElement = (SVGTextElement) doc.getElementById("textID");
svgTextElement.getFirstChild().setNodeValue("ΑΩ");
float width = svgTextElement.getBBox().getWidth();
My document is created as follows -
protected SVGDocument makeSvgDocument(String svgString) {
SVGDocument svgDoc = null;
@SuppressWarnings("unused")
GraphicsNode rootGN;
UserAgent userAgent = new UserAgentAdapter();
DocumentLoader loader = new DocumentLoader(userAgent);
BridgeContext ctx = new BridgeContext(userAgent, loader);
GVTBuilder builder = new GVTBuilder();
SAXSVGDocumentFactory factory = new
SAXSVGDocumentFactory(SAXParser.class.getCanonicalName(), true);
try {
svgDoc = (SVGDocument) factory.createDocument("file:///dummy/dummy/file.svg",
new StringReader(svgString));
ctx.setDynamicState(BridgeContext.DYNAMIC);
rootGN = builder.build(ctx, svgDoc);
} catch (IOException e) {
e.printStackTrace();
}
return svgDoc;
}
It appears to me that the result (especially evident for width) is calculated
as if the 1 character is actually 6 characters.
Thank you.
Best regards,
Charles Seelig