You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Thomas Charbonnel <th...@undata.org> on 2005/07/21 11:35:01 UTC

Dynamic document and rendering passes

Hi, 

I'm writing an application where I have to display and print schematic
views of rooms whose dimensions and characteristics are user-defined. I
can make no assumption about the values the user will provide, and must
update the views dynamically. Based on those values I have to draw a
grid with ticks and distance labels and draw text labels inside rects
and polygons.

So far here's what I came up to : my document is an A4 sheet, divided in
two equal zones, each having a text label and inlined svg element
representing a view. As views have their own units and coordinate
systems, my idea is to use the svg elements' viewBox to make the views
fit in their dedicated space on the sheet. The thing is that to compute
the viewBox, I need the document to already have been rendered to take
into account the space used by tick marks' labels. The problem is
similar for text labels inside the rects and polygons. I need the text's
bounding box to position and scale it in the rects and polygons.

I'm wondering where the best place would be to do this.
I can think of a two passes rendering, registering an UpdateManager
listener and executing the remaining steps in the updateCompleted()
callback when needed, but it looks ugly and inefficient to me. My
feeling is that there must be a way to do this in one pass, but I
couldn't figure it out so far.
What's the recommended or commonly used way to do this ?

Regards,
Thomas



---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: Dynamic document and rendering passes

Posted by Thomas Charbonnel <th...@undata.org>.
I wrote :

> The 'onload' event handler is not enough, because the user actions can
> dynamically change the size and position of elements in the inlined svg.
> I need to recompute the viewBox every time this happens.
> What I do now is that I register an UpdateManagerListener, and when I
> detect that the viewBox needs to be recomputed, I trigger the
> computation from the updateCompleted() callback. As everything in the
> inlined svg is under a <g> element, I just take its bounding box and set
> the viewBox to match it. The problem is that is a two passes rendering.
> It's suboptimal, and the UI doesn't feel responsive (the intermediary
> state can be seen). Is there a way to do this in just one pass ?

Ooops, I totally missed the fact that the bounding box information was
directly available after my calls modifying the DOM. It's indeed trivial
to do it in one pass.

Thanks Thomas, and sorry for the noise,
Thomas



---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: Dynamic document and rendering passes

Posted by Thomas Charbonnel <th...@undata.org>.
Thanks Thomas for the quick answer.

Thomas DeWeese wrote :
> Hi Thomas,
> 
> 
> 
> Thomas Charbonnel wrote:
> > As views have their own units and coordinate
> > systems, my idea is to use the svg elements' viewBox to make the views
> > fit in their dedicated space on the sheet. 
> 
>     Yes, this is the correct thing to do.
> 
> > The thing is that to compute the viewBox, I need the document to
> > already have been rendered to take into account the space used by 
> > tick marks' labels. The problem is similar for text labels inside 
> > the rects and polygons. I need the text's bounding box to position 
> > and scale it in the rects and polygons.
> > 
> > I'm wondering where the best place would be to do this.
> 
>     The best thing to do is to register an 'onload' event handler
> with the root SVG element (do this before passing the document to
> the Canvas).  Your handler will be called after the document
> has been loaded but before any display has taken place.  You will
> have access to the full SVG DOM at this point so you can use
> methods like 'getBBox()' to calculate the extent of your document.
> 

The 'onload' event handler is not enough, because the user actions can
dynamically change the size and position of elements in the inlined svg.
I need to recompute the viewBox every time this happens.
What I do now is that I register an UpdateManagerListener, and when I
detect that the viewBox needs to be recomputed, I trigger the
computation from the updateCompleted() callback. As everything in the
inlined svg is under a <g> element, I just take its bounding box and set
the viewBox to match it. The problem is that is a two passes rendering.
It's suboptimal, and the UI doesn't feel responsive (the intermediary
state can be seen). Is there a way to do this in just one pass ?

> > I can think of a two passes rendering, registering an UpdateManager
> > listener and executing the remaining steps in the updateCompleted()
> > callback when needed, but it looks ugly and inefficient to me. My
> > feeling is that there must be a way to do this in one pass, but I
> > couldn't figure it out so far.
> > What's the recommended or commonly used way to do this ?
> > 
> > Regards,
> > Thomas
> > 



---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: Dynamic document and rendering passes

Posted by Thomas DeWeese <Th...@Kodak.com>.
Hi Thomas,



Thomas Charbonnel wrote:
> As views have their own units and coordinate
> systems, my idea is to use the svg elements' viewBox to make the views
> fit in their dedicated space on the sheet. 

    Yes, this is the correct thing to do.

> The thing is that to compute the viewBox, I need the document to
> already have been rendered to take into account the space used by 
> tick marks' labels. The problem is similar for text labels inside 
> the rects and polygons. I need the text's bounding box to position 
> and scale it in the rects and polygons.
> 
> I'm wondering where the best place would be to do this.

    The best thing to do is to register an 'onload' event handler
with the root SVG element (do this before passing the document to
the Canvas).  Your handler will be called after the document
has been loaded but before any display has taken place.  You will
have access to the full SVG DOM at this point so you can use
methods like 'getBBox()' to calculate the extent of your document.

> I can think of a two passes rendering, registering an UpdateManager
> listener and executing the remaining steps in the updateCompleted()
> callback when needed, but it looks ugly and inefficient to me. My
> feeling is that there must be a way to do this in one pass, but I
> couldn't figure it out so far.
> What's the recommended or commonly used way to do this ?
> 
> Regards,
> Thomas
> 
> 
> 
> ---------------------------------------------------------------------
> 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