Hi, this solution is ok.
But i have a question
in my code if I generated a TextElement
.
.
.
UserAgent userAgent;
DocumentLoader loader;
BridgeContext ctx;
GVTBuilder builder;
userAgent = new UserAgentAdapter();
loader = new DocumentLoader(userAgent);
ctx = new BridgeContext(userAgent, loader);
ctx.setDynamicState(BridgeContext.DYNAMIC);
builder = new GVTBuilder();
builder.build(ctx, svgDoc);
.
.
.
SVGOMTextElement t1 = (SVGOMTextElement)svgDoc.createElementNS(svgNS,
SVGConstants.SVG_TEXT_TAG);
t1.setAttribute(SVGConstants.SVG_X_ATTRIBUTE, "80");
t1.setAttribute(SVGConstants.SVG_Y_ATTRIBUTE, "100");
t1.setAttribute(SVGConstants.CSS_FONT_SIZE_PROPERTY, "12");
t1.setAttribute(SVGConstants.CSS_FONT_FAMILY_PROPERTY, "times");
t1.setAttribute(SVGConstants.CSS_FILL_PROPERTY, "yellow");
Text text1 = svgDoc.createTextNode("hello world");
t1.appendChild(text1);
root.appendChild(t1);
.
.
.
now when i calculate for example... width
with this code:
Rectangle rect = ctx.getGraphicsNode(t1).getBounds().getBounds();
int width = (int)(ctx.getGraphicsNode(t1).getBounds().getWidth());
I have a different result
rect.width no equals to width
Why?
How is the correct width of t1 textElement ?
Thanks from Alessandro
--- In [email protected], Thomas DeWeese
<[EMAIL PROTECTED]> wrote:
> Hi Peruzzi,
>
> Peruzzi Alessandro wrote:
>
> > Thanks but my program generated same errors.
>
> You need to boot the 'graphics' part of the
> SVG Document. Without this the extended SVG DOM
> mostly won't work.
>
> UserAgent userAgent;
> DocumentLoader loader;
> BridgeContext ctx;
> GVTBuilder builder;
>
> userAgent = new UserAgentAdapter();
> loader = new DocumentLoader(userAgent);
> ctx = new BridgeContext(userAgent, loader);
> ctx.setDynamicState(BridgeContext.DYNAMIC);
> builder = new GVTBuilder();
> builder.build(ctx, svgDoc);
>
> After this the extended SVG DOM and the CSS
> interfaces will be 'live'. If you are just
> 'reading' the SVG tree and not modifying it
> you can use 'STATIC' instead of 'DYNAMIC' which
> will use slightly less memory.
>
> >
> > example:
> >
> > in a main program
> >
> > import org.w3c.dom.*;
> > import org.w3c.dom.svg.*;
> > import java.io.*;
> > import org.apache.batik.dom.*;
> > import org.apache.batik.dom.util.*;
> > import org.apache.batik.dom.svg.*;
> > import org.apache.batik.util.*;
> >
> > public class TestSVG
> > {
> > public static void main(String[] args)
> > {
> > DOMImplementation impl = (SVGDOMImplementation)
> > SVGDOMImplementation.getDOMImplementation();
> > String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
> > SVGDocument svgDoc = (SVGDocument)(impl.createDocument
> > (svgNS, "svg", null));
> >
> > SVGSVGElement root = svgDoc.getRootElement();
> >
> > SVGOMTextElement t1 = (SVGOMTextElement)svgDoc.createElementNS
> > (svgNS, SVGConstants.SVG_TEXT_TAG);
> > t1.setAttribute(SVGConstants.SVG_X_ATTRIBUTE, "80");
> > t1.setAttribute(SVGConstants.SVG_Y_ATTRIBUTE, "100");
> > t1.setAttribute(SVGConstants.CSS_FONT_SIZE_PROPERTY, "12");
> > t1.setAttribute
(SVGConstants.CSS_FONT_FAMILY_PROPERTY, "times");
> > t1.setAttribute(SVGConstants.CSS_FILL_PROPERTY, "yellow");
> >
> > Text text1 = svgDoc.createTextNode("hello world");
> > t1.appendChild(text1);
> > root.appendChild(t1);
> >
> >
> > // now I want t1 width/height in pixel
> > // but follow row of my code generate error
> >
> > System.out.println("t1="+((SVGOMTextElement)t1).getBBox
().gettWidth
> > ());
> >
> >
> > // the error is
> > java.lang.NullPointerException
> >
> > at org.apache.batik.dom.svg.SVGLocatableSupport$1.getWidth
> > (Unknown Source)
> >
> > at sisvg2.TestSVG.main(TestSVG.java:31)
> >
> > Exception in thread "main"
> >
> > // but if i use
> >
> > System.out.println("t1="+((SVGOMTextElement)t1).getBBox());
> >
> > runtime print
[EMAIL PROTECTED]
> >
> >
> > What is my errors.
> > Thanks a lot from Alessandro (italy)
> >
> >
> >
> >
> >
> >
> > --- In [email protected], Holger Will <[EMAIL PROTECTED]>
> > wrote:
> >
> >>Peruzzi Alessandro wrote:
> >>
> >>
> >>>Hi.
> >>>I've a problem.
> >>>I'd like to know how many pixel have a <text> element in a
> >
> > specific
> >
> >>>font-family and font-width
> >>>
> >>>example:
> >>><text font-family="verdana" font-width="10">Hello world</text>
> >>>
> >>>Hello world how many pixel in width or in height effectly ?
> >>>
> >>>Thanks a lot.
> >>>
> >>>Alessandro Peruzzi
> >>
> >>Hi Alessandro
> >>you could use getBBox() or getComputedTextLength()
> >>id say use getBBox().
> >>cheers
> >>Holger
> >
> >
> >
> >
> >
> >
> > -----
> > To unsubscribe send a message to: svg-developers-
[EMAIL PROTECTED]
> > -or-
> > visit http://groups.yahoo.com/group/svg-developers and
click "edit my membership"
> > ----
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
-----
To unsubscribe send a message to: [EMAIL PROTECTED]
-or-
visit http://groups.yahoo.com/group/svg-developers and click "edit my
membership"
----
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/svg-developers/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/