Looked through the code you suggested and also JSVGComponent.java. Just want
to clarify my understanding of the bridge workaround to get a text string
pixel width. Tell me where I am right and wrong in my assumptions. I am
currently assuming the following:

1.   that I need to use the constructor BridgeContext(UserAgent userAgent)

2.   that I therefore need to write a UserAgent, which I will try to cobble
together by studying JSVGComponent.java and ImageTranscoder.java UserAgent
inner classes.

3.   that I need to put in something along the lines of the following:

  DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
  Document doc = impl.createDocument(SVGDOMImplementation.SVG_NAMESPACE_URI,
"svg", null);
  // do I need a Document to use the bridge for the specific purpose of
getting
  // the pixel width for a text node?
  org.w3c.dom.Element textEl = doc.createElementNS(svgNS, "text");
  org.w3c.dom.Text someText = doc.createTextNode("Hello world");
  GVTBuilder builder = new GVTBuilder();
  BridgeContext ctx = new BridgeContext(new MyUserAgent());
  GraphicsNode gvtRoot = builder.build(ctx, textEl);
  // or GraphicsNode gvtRoot builder.build(ctx, SVGDocument(doc));
  int stringWidth = gvtRoot.getBounds().getWidth();
  // or traverse to TextNode from gvtRoot (how?) and apply
getBounds().getWidth from there

Any reality check for my assumptions will be most appreciated!

Another workaround that occurred to me is just to use a monospaced font for
now. However I was wondering if I was anywhere close to being on the right
track.

Thanks in advance.

Dave


-----Original Message-----
From: Thierry Kormann [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 21, 2002 3:39 AM
To: Batik Users
Subject: RE: createElementNS and <text> and getComputedTextLength()


As a workaround, you can try to build the <text> element, using the bridge
module (see GVTBuilder and the ImageTranscoder for example to see how it
works) - then get the gvt.TextNode (the graphic representation of your
<text> node) and you will have access to its bounds...

I will try to implement getComputedTextLength ASAP when we will work on the
SVG DOM.

Thierry.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to