Hi Nazar,

"Nazar Stasiv (Lohika, Inc)" <[EMAIL PROTECTED]> wrote on 08/14/2006 
11:54:58 AM:

> the only difference is that I need SVGRect from different element, not 
> the rootGN. Like next:

   This should not be a problem.  The only thing I can comment on
is that you are dropping references to a lot of objects that
need to be alive for the SVG DOM to work (in particular the
BridgeContext and the rootGN).  I would think that until you
called BridgeContext.dispose() the DOM tree would be sufficient 
to keep everything alive but in particular you may need to
hold a reference to the rootGN.

   I would do three things:
        1) try calling getBBox on the root SVG element in the
           parseSVG method (to see if this is working at all 
         for you).
        2) If #1 works try getBBox in the parseSVG method for
           one (or more) of the Element's you want.
        3) If #2 works then hold the reference and see if it
           works later.

   Also it's worth noting that if an element isn't rendered
(in a defs, has "display" set to "none", etc) then it won't 
have a bbox.

>     public static SVGDocument parseSvg(String uri) {
>         UserAgent userAgent = new UserAgentAdapter();
>         DocumentLoader loader = new DocumentLoader(userAgent);
>         SVGDocument doc;
>         try {
>             doc = (SVGDocument) loader.loadDocument(uri);
>         } catch (Exception e) {
>             e.printStackTrace();
>             throw new RuntimeException(e);
>         }
>         BridgeContext ctx = new BridgeContext(userAgent, loader);
>         ctx.setDynamicState(BridgeContext.DYNAMIC);
>         GVTBuilder builder = new GVTBuilder();
>         GraphicsNode rootGN = builder.build(ctx, doc);
>         loader.dispose();
>         return doc;
>     }
> 
> //this will return null.
>     public static SVGRect getSVGRect(SVGLocatable e) {
>         return e.getBBox();
>     }
> 
> [EMAIL PROTECTED] wrote:
> > Hi Nazar,
> >
> > "Nazar Stasiv (Lohika, Inc)" <[EMAIL PROTECTED]> wrote on 08/14/2006 
> > 09:55:27 AM:
> >
> > 
> >> No I don't use JSVGCanvas. My application is using servlets. 
Basically I 
> >> 
> >
> > 
> >> construct SVGDocument from file and while visiting elements of its 
DOM 
> >> tree I need a coordinate of the element for later use
> >>
> >> To boot SVG DOM you mean a code like this ?
> >> 
> >
> >    Close but for correct results you need to build it from the root
> > of the SVG tree (just like the Wiki page).  You should also only do 
> > this once for the whole document right after loading it (not for 
> > each element).
> >
> > 
> >>     public static Rectangle2D getBounds2D(Element e) {
> >>         UserAgent userAgent = new UserAgentAdapter();
> >>         DocumentLoader loader = new DocumentLoader(userAgent);
> >>         BridgeContext ctx = new BridgeContext(userAgent, loader);
> >>         ctx.setDynamicState(BridgeContext.DYNAMIC);
> >>         GVTBuilder builder = new GVTBuilder();
> >>         GraphicsNode rootGN = builder.build(ctx, e);
> >>         return rootGN.getBounds();
> >>
> >>     }
> >> Note: when visiting an element it is already of type SVGOMGElement, 
> >> hence there no need to boot SVG DOM or am I wrong?
> >> 
> >
> >    You need to boot the SVG DOM in all cases, if you want to use it.
> >
> > 
> >> If you look at my code at line last but one, rootGN = 
builder.build(ctx, 
> >> 
> >
> > 
> >> e); it assigns null to rootGN.
> >> 
> >
> >    Right you need to build from root of Document.
> >
> > 
> >>
> >> [EMAIL PROTECTED] wrote:
> >> 
> >>> Hi Nazar,
> >>>
> >>> "Nazar Stasiv (Lohika, Inc)" <[EMAIL PROTECTED]> wrote on 
08/14/2006 
> >>> 09:16:01 AM:
> >>>
> >>>
> >>> 
> >>>> SVGLocatable.getBBox(elem) returns null No javadoc comments are 
there 
> >>>> 
> > to 
> > 
> >>> 
> >>>> unveil the reason of such behaviour
> >>>>
> >>>> Is there the other way to get coordinates of SVGOMGElement ?
> >>>>
> >>>> 
> >>>     How are you using the Document?  Is it in the JSVGCanvas?
> >>> Are you trying to call this method before loading the document?
> >>>
> >>>     For these methods to work you need to boot the SVG DOM.
> >>> This normally happens when you load the document in the Canvas
> >>> (you may need to set document state to ALWAYS_DYNAMIC on the
> >>> canvas before loading the document if there are no obvious dynamic 
> >>> features of the document).
> >>>
> >>>     If you are trying to use these features outside of the
> >>> JSVGCanvas check the Batik wiki for how to bring up the SVG DOM:
> >>>
> >>> http://wiki.apache.org/xmlgraphics-batik/BootSvgAndCssDom
> >>>
> >>>
> >>> 
> >>>> [EMAIL PROTECTED] wrote:
> >>>>
> >>>> 
> >>>>> Hi Nazer,
> >>>>>
> >>>>> "Nazar Stasiv (Lohika, Inc)" <[EMAIL PROTECTED]> wrote on 
> >>>>> 
> > 08/14/2006 
> > 
> >>>>> 07:29:19 AM:
> >>>>>
> >>>>>
> >>>>>
> >>>>> 
> >>>>>> I use batik to operate SVG at runtime. 
> >>>>>>
> >>>>>> The question is how can I get SVGOMGElement coordinates when 
> >>>>>> 
> > walking 
> > 
> >>> DOM
> >>>
> >>> 
> >>>>>> tree of the SVG document?
> >>>>>>
> >>>>>>
> >>>>>> 
> >>>>>    You should look at the SVG DOM.  In particular the 'getBBox' 
> >>>>>
> >>>>> 
> >>> method.
> >>>
> >>> 
> >>>>> There are also methods get 'getIntersectionList' that could be 
> >>>>> 
> > useful.
> > 
> >>>>>
> >>>>>
> >>>>> 
> >>>>>> The reason I'm asking such a thing it that requirements are to 
> >>>>>>
> >>>>>> 
> >>> display
> >>>
> >>> 
> >>>>>> info popup near named elements of SVG. If I had coordinates of 
such 
> >>>>>> 
> >
> > 
> >>> an
> >>>
> >>> 
> >>>>>> element I could use DOM to add new element to the tree with 
> >>>>>> 
> > computed
> > 
> >>>>>> coordinates for correct positioning of the info popup.
> >>>>>>
> >>>>>>
> >>>>>> 
> >>>>>    This is typically done with mouse over/out event handlers. This 

> >>>>> allows you to receive a DOM event when the mouse enters/exits a 
> >>>>>
> >>>>> 
> >>> particular
> >>>
> >>> 
> >>>>> element or group in the SVG document.  If you need the sensitive 
> >>>>> 
> > area 
> > 
> >>> to
> >>>
> >>> 
> >>>>> be larger than the rendered area you can add a hidden element
> >>>>> (visibility="hidden" pointer-events="fill") that can cover the 
> >>>>>
> >>>>> 
> >>> expanded
> >>>
> >>> 
> >>>>> area and tie your event handler to that.
> >>>>>
> >>>>>
> >>>>>
> >>>>> 
> > ---------------------------------------------------------------------
> > 
> >>>>> 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]
> > 
> >>>> 
> >>> 
---------------------------------------------------------------------
> >>> 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]
> >>
> >> 
> >
> >
> > ---------------------------------------------------------------------
> > 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]
> 


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

Reply via email to