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 Javid Alimohideen <ja...@gmail.com> on 2006/03/04 02:28:03 UTC

Batik offscreen rendering howto?

H
I have a dynamic renderer in my application to render the svg content
(offscreen). The rendering works fine but if I make some changes to the
document the renderer.repaint method doesn't reflect the changes made to the
dom. I am pasting the source code of my render method:
The root variable was built using the GVT builder.
Thanks for your help,

Javid

public synchronized BufferedImage getRenderedImage(GraphicsNode root,
AffineTransform transform, int width, int height) {


		BufferedImage dest = new BufferedImage(width, height,
BufferedImage.TYPE_INT_ARGB);

		renderer.updateOffScreen(width, height);
		renderer.setTree(root);
		renderer.setTransform(transform);


		java.awt.Rectangle r = new java.awt.Rectangle( 0, 0, width, height);
		try {
			renderer.repaint( transform.createInverse().createTransformedShape(r) );
		}
		catch (Exception e) { e.printStackTrace(); }

		BufferedImage rend = renderer.getOffScreen();
		//renderer = null;

		Graphics2D g2d = GraphicsUtil.createGraphics(dest);
		g2d.setComposite(AlphaComposite.SrcOver);
		g2d.setColor(java.awt.Color.black);
		g2d.fillRect(0, 0, width, height);
		if (rend != null) {
			g2d.drawRenderedImage(rend, new AffineTransform());
		}
		renderer = null;
		g2d.dispose();
		rend = null;
		return dest;
}


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


RE: Batik offscreen rendering howto?

Posted by Javid Alimohideen <ja...@gmail.com>.
Hi,
It works fine now. I disabled the double buffering on the renderer and
called a repaint. Previously, the offscreen buffer had parts of previous
offscreen image even though I called clearOffscreen and flush. Thomas, may
be you can update the wiki page to disable the doublebuffering on the
renderer. This was happening when I change the transforms of the renderer.
Please, correct me if I sound wrong.

Thanks,
Javid

-----Original Message-----
From: Tonny Kohar [mailto:tonny@kiyut.com]
Sent: Monday, March 06, 2006 7:39 PM
To: batik-users@xmlgraphics.apache.org
Subject: RE: Batik offscreen rendering howto?


Hi,

On Sun, 2006-03-05 at 23:39 -0600, Javid Alimohideen wrote:
> Hi Thomas,
> Now my offscreen renderer works, I have started to implement the soom and
> pan functionality for my display canvas. I think it would be very
difficult
> to achienve the zoom/pan functionality of JSVGCanvas but I am trying to do
> something little close. So, I calculate a scale from the mouse start to
end
> positions and perform a Scale AffineTransform and update it to the
renderer
> transform. This is what my code look like:

I am not sure if this will works. Did you call the
renderer.updateOffScreen(int width, int height) after setting the
transform

Regards
Tonny Kohar
--
Sketsa
SVG Graphics Editor
http://www.kiyut.com


---------------------------------------------------------------------
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


RE: Batik offscreen rendering howto?

Posted by Tonny Kohar <to...@kiyut.com>.
Hi,

On Sun, 2006-03-05 at 23:39 -0600, Javid Alimohideen wrote:
> Hi Thomas,
> Now my offscreen renderer works, I have started to implement the soom and
> pan functionality for my display canvas. I think it would be very difficult
> to achienve the zoom/pan functionality of JSVGCanvas but I am trying to do
> something little close. So, I calculate a scale from the mouse start to end
> positions and perform a Scale AffineTransform and update it to the renderer
> transform. This is what my code look like:

I am not sure if this will works. Did you call the
renderer.updateOffScreen(int width, int height) after setting the
transform

Regards
Tonny Kohar
-- 
Sketsa 
SVG Graphics Editor
http://www.kiyut.com


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


RE: Batik offscreen rendering howto?

Posted by Javid Alimohideen <ja...@gmail.com>.
Hi Thomas,
Now my offscreen renderer works, I have started to implement the soom and
pan functionality for my display canvas. I think it would be very difficult
to achienve the zoom/pan functionality of JSVGCanvas but I am trying to do
something little close. So, I calculate a scale from the mouse start to end
positions and perform a Scale AffineTransform and update it to the renderer
transform. This is what my code look like:

manager.getUpdateRunnableQueue().invokeAndWait(new Runnable() {
				public void run() {
					System.out.println("chaning transform");
					AffineTransform af = AffineTransform.getScaleInstance(scale, scale);
					af.concatenate(curTxf);
					renderer.clearOffScreen();
					renderer.setTransform(af);
					renderer.repaint(new java.awt.Rectangle (0, 0, clientDisplaySize.width,
clientDisplaySize.height));
					render(renderer.getOffScreen());
					curTxf = af;
				}
			});
But it doesn't seem to work well. Just FYI, my client is a simple PDA that
has a AWT Canvas to display the image rendered at the server. All the
rendering and transformations happen at the server side.

Thanks,
Javid

-----Original Message-----
From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com]
Sent: Sunday, March 05, 2006 2:42 PM
To: batik-users@xmlgraphics.apache.org
Cc: batik-users@xmlgraphics.apache.org
Subject: RE: Batik offscreen rendering howto?


Hi Javid,

"Javid Alimohideen" <ja...@gmail.com> wrote on 03/05/2006 03:24:58 PM:

> I had a small bug when I was doing my updates which is fixed now and
works
> great. If I need the offscreen image once the document is fully loaded
and
> rendererd which listeners should I use.

   Note that in my update I call:
                renderer.repaint(new Rectangle(0, 0, DISPLAY_WIDTH,
DISPLAY_HEIGHT));

   After this you can call renderer.getOffscreen() to get the image
before updates.

>  Now, I get offscreen images after
> every updates but I would also need the image before I do any updates.
>
> Thanks,
> Javid
>
> -----Original Message-----
> From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com]
> Sent: Sunday, March 05, 2006 8:49 AM
> To: batik-users@xmlgraphics.apache.org
> Cc: batik-users@xmlgraphics.apache.org
> Subject: RE: Batik offscreen rendering howto?
>
>
> Hi Javid,
>
>    I've created a Wiki page with an example that Works For Me(TM).
>
>         http://wiki.apache.org/xmlgraphics-batik/DynamicSvgOffscreen
>
> "Javid Alimohideen" <ja...@gmail.com> wrote on 03/05/2006 12:38:48
AM:
>
> > I managed to write a simple standalone version of the offscreen
renderer
> > with the updatemanagerlistener. But for some reason, the
updateCompleted
> > method is never called.
>
>   I actually don't think there are any really significant changes from
> your original code
> so I am surprised that your stuff didn't work.  You might want to look
at
> the main I provided
> as that is where I modify the document.  I suspect that you weren't do
> this correctly.
>
>
> > Kindly, excuse me for pasting the entire code as I am not sure
> > if attachments are aloowed.
>
>    Generally attachements aren't allowed, you could add the code
> to a Wiki-Page as well.
>
>
> ---------------------------------------------------------------------
> 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
>


---------------------------------------------------------------------
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


RE: Batik offscreen rendering howto?

Posted by th...@kodak.com.
Hi Javid,

"Javid Alimohideen" <ja...@gmail.com> wrote on 03/05/2006 03:24:58 PM:

> I had a small bug when I was doing my updates which is fixed now and 
works
> great. If I need the offscreen image once the document is fully loaded 
and
> rendererd which listeners should I use.

   Note that in my update I call:
                renderer.repaint(new Rectangle(0, 0, DISPLAY_WIDTH, 
DISPLAY_HEIGHT));

   After this you can call renderer.getOffscreen() to get the image
before updates.

>  Now, I get offscreen images after
> every updates but I would also need the image before I do any updates.
> 
> Thanks,
> Javid
> 
> -----Original Message-----
> From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com]
> Sent: Sunday, March 05, 2006 8:49 AM
> To: batik-users@xmlgraphics.apache.org
> Cc: batik-users@xmlgraphics.apache.org
> Subject: RE: Batik offscreen rendering howto?
> 
> 
> Hi Javid,
> 
>    I've created a Wiki page with an example that Works For Me(TM).
> 
>         http://wiki.apache.org/xmlgraphics-batik/DynamicSvgOffscreen
> 
> "Javid Alimohideen" <ja...@gmail.com> wrote on 03/05/2006 12:38:48 
AM:
> 
> > I managed to write a simple standalone version of the offscreen 
renderer
> > with the updatemanagerlistener. But for some reason, the 
updateCompleted
> > method is never called.
> 
>   I actually don't think there are any really significant changes from
> your original code
> so I am surprised that your stuff didn't work.  You might want to look 
at
> the main I provided
> as that is where I modify the document.  I suspect that you weren't do
> this correctly.
> 
> 
> > Kindly, excuse me for pasting the entire code as I am not sure
> > if attachments are aloowed.
> 
>    Generally attachements aren't allowed, you could add the code
> to a Wiki-Page as well.
> 
> 
> ---------------------------------------------------------------------
> 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
> 


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


RE: Batik offscreen rendering howto?

Posted by Javid Alimohideen <ja...@gmail.com>.
Thanks Thomas,
I had a small bug when I was doing my updates which is fixed now and works
great. If I need the offscreen image once the document is fully loaded and
rendererd which listeners should I use. Now, I get offscreen images after
every updates but I would also need the image before I do any updates.

Thanks,
Javid

-----Original Message-----
From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com]
Sent: Sunday, March 05, 2006 8:49 AM
To: batik-users@xmlgraphics.apache.org
Cc: batik-users@xmlgraphics.apache.org
Subject: RE: Batik offscreen rendering howto?


Hi Javid,

   I've created a Wiki page with an example that Works For Me(TM).

        http://wiki.apache.org/xmlgraphics-batik/DynamicSvgOffscreen

"Javid Alimohideen" <ja...@gmail.com> wrote on 03/05/2006 12:38:48 AM:

> I managed to write a simple standalone version of the offscreen renderer
> with the updatemanagerlistener. But for some reason, the updateCompleted
> method is never called.

  I actually don't think there are any really significant changes from
your original code
so I am surprised that your stuff didn't work.  You might want to look at
the main I provided
as that is where I modify the document.  I suspect that you weren't do
this correctly.


> Kindly, excuse me for pasting the entire code as I am not sure
> if attachments are aloowed.

   Generally attachements aren't allowed, you could add the code
to a Wiki-Page as well.


---------------------------------------------------------------------
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


RE: Batik offscreen rendering howto?

Posted by th...@kodak.com.
Hi Javid,

   I've created a Wiki page with an example that Works For Me(TM).

        http://wiki.apache.org/xmlgraphics-batik/DynamicSvgOffscreen

"Javid Alimohideen" <ja...@gmail.com> wrote on 03/05/2006 12:38:48 AM:

> I managed to write a simple standalone version of the offscreen renderer
> with the updatemanagerlistener. But for some reason, the updateCompleted
> method is never called.

  I actually don't think there are any really significant changes from 
your original code
so I am surprised that your stuff didn't work.  You might want to look at 
the main I provided
as that is where I modify the document.  I suspect that you weren't do 
this correctly.


> Kindly, excuse me for pasting the entire code as I am not sure 
> if attachments are aloowed.

   Generally attachements aren't allowed, you could add the code 
to a Wiki-Page as well.


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


RE: Batik offscreen rendering howto?

Posted by Javid Alimohideen <ja...@gmail.com>.
Hi Thomas,
I managed to write a simple standalone version of the offscreen renderer
with the updatemanagerlistener. But for some reason, the updateCompleted
method is never called. Kindly, excuse me for pasting the entire code as I
am not sure if attachments are aloowed.

Javid


import java.awt.geom.AffineTransform;
import java.util.List;

import org.apache.batik.bridge.BridgeContext;
import org.apache.batik.bridge.BridgeException;
import org.apache.batik.bridge.GVTBuilder;
import org.apache.batik.bridge.UpdateManager;
import org.apache.batik.bridge.UpdateManagerAdapter;
import org.apache.batik.bridge.UpdateManagerEvent;
import org.apache.batik.bridge.UserAgentAdapter;
import org.apache.batik.gvt.CanvasGraphicsNode;
import org.apache.batik.gvt.CompositeGraphicsNode;
import org.apache.batik.gvt.GraphicsNode;
import org.apache.batik.gvt.renderer.ConcreteImageRendererFactory;
import org.apache.batik.gvt.renderer.ImageRenderer;
import org.apache.batik.gvt.renderer.ImageRendererFactory;
import org.w3c.dom.Document;


public class TestOffScreenRender {

	Document document;
	UserAgentAdapter userAgent;
	GVTBuilder builder;
	BridgeContext ctx;
	ImageRenderer renderer;
	AffineTransform curTxf;
	UpdateManager manager;
	GraphicsNode gvtRoot;
	int DISPLAY_WIDTH = 1280;
	int DISPLAY_HEIGHT = 1024;


	public TestOffScreenRender (Document doc) {
		userAgent = new UserAgentAdapter();
		ctx = new BridgeContext(userAgent);
		builder = new GVTBuilder();
		document = doc;
	}

	public void init() {
		GraphicsNode gvtRoot = null ;

		try {
			ctx.setDynamicState(BridgeContext.DYNAMIC);
			gvtRoot = builder.build(ctx, document);
		}
		catch (BridgeException e) { e.printStackTrace(); }

		ImageRendererFactory rendererFactory = new ConcreteImageRendererFactory();
		renderer = rendererFactory.createDynamicImageRenderer();
		renderer.setDoubleBuffered(true);

		float docWidth = (float) ctx.getDocumentSize().getWidth();
		float docHeight = (float) ctx.getDocumentSize().getHeight();

		float xscale = DISPLAY_WIDTH/docWidth;
		float yscale = DISPLAY_HEIGHT/docHeight;
		float scale = Math.min(xscale, yscale);

		AffineTransform px  = AffineTransform.getScaleInstance(scale, scale);

		double tx = -0 + (DISPLAY_WIDTH/scale - docWidth)/2;
		double ty = -0 + (DISPLAY_WIDTH/scale - docHeight)/2;
		px.translate(tx, ty);
		CanvasGraphicsNode cgn = getGraphicsNode(gvtRoot);
        if (cgn != null) {
            cgn.setViewingTransform(px);
            curTxf = new AffineTransform();
        } else {
            curTxf = px;
        }
		manager = new UpdateManager(ctx, gvtRoot, document);

		renderer.updateOffScreen(DISPLAY_WIDTH, DISPLAY_WIDTH);
		renderer.setTree(gvtRoot);
		renderer.setTransform(curTxf);
		renderer.clearOffScreen();
		manager.manageUpdates(renderer);
		manager.addUpdateManagerListener(new UpdateManagerAdapter() {
			public void updateCompleted(UpdateManagerEvent e) {
				render(e.getImage());
			}
		});
		this.gvtRoot = gvtRoot;
	}

	private CanvasGraphicsNode getGraphicsNode(GraphicsNode gn) {
		if (!(gn instanceof CompositeGraphicsNode))
			return null;
		CompositeGraphicsNode cgn = (CompositeGraphicsNode) gn;
		List children = cgn.getChildren();
		if(children.size() == 0)
			return null;
		gn = (GraphicsNode) children.get(0);
		if (!(gn instanceof CanvasGraphicsNode))
			return null;
		return (CanvasGraphicsNode) gn;

	}

	public void render(java.awt.image.BufferedImage img) {
		// paint the image or stream the image to the client display
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}

-----Original Message-----
From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com]
Sent: Saturday, March 04, 2006 6:19 PM
To: batik-users@xmlgraphics.apache.org
Cc: batik-users@xmlgraphics.apache.org
Subject: RE: Batik offscreen rendering howto?


Hi Javid,

"Javid Alimohideen" <ja...@gmail.com> wrote on 03/04/2006 04:31:04 PM:

> I added the UpdateManager as you had suggested but I still don't get the
> updates. I am sure about doing something wrong but couldn't figure out
what.
> So, here is the initialization code:

        The basic code looks ok to me.

> I do the updates in the updatemenager runnable thread
        Good.

> and later call the updatemanager.updateRendering method.

     You shouldn't have to do this, when a runnable completes it should
normally kick off an update of the canvas by calling
UpdateManager.repaint().

> and I get the offscreen buffer by the getRepaintManager().getOffscreen
> method.

   I would suggest you register an 'updateCompleted' event listener with
the UpdateManager.  This will be called with an UpdateManagerEvent that
will have the offscreen that you should be using.

> It would be also helpful if you could point me to the batik source files
> that I must look at.

   Well the method that kicks off the update is the
'UpdateManager.repaint()'
method (which is automatically called when a runnable completes in the
UpdateManager's runnable queue.

> public void initialize() {
>       GraphicsNode gvtRoot = null ;
>
>       try {
>          ctx.setDynamicState(BridgeContext.DYNAMIC);
>          gvtRoot = builder.build(ctx, svgDocument);
>       }
>       catch (BridgeException e) { e.printStackTrace(); }
>       renderer = PavisRenderer.getPavisRenderer();
>
>       float docWidth = (float) ctx.getDocumentSize().getWidth();
>       float docHeight = (float) ctx.getDocumentSize().getHeight();
>
>       float xscale = clientDisplaySize.width/docWidth;
>       float yscale = clientDisplaySize.height/docHeight;
>       float scale = Math.min(xscale, yscale);
>
>       AffineTransform px  = AffineTransform.getScaleInstance(scale,
scale);
>
>       double tx = -0 + (clientDisplaySize.width/scale - docWidth)/2;
>       double ty = -0 + (clientDisplaySize.height/scale - docHeight)/2;
>       px.translate(tx, ty);
>       CanvasGraphicsNode cgn = getGraphicsNode(gvtRoot);
>         if (cgn != null) {
>             cgn.setViewingTransform(px);
>             curTxf = new AffineTransform();
>         } else {
>             curTxf = px;
>         }
>       manager = new UpdateManager(ctx, gvtRoot, svgDocument);
>       ImageRenderer ren = renderer.getImageRenderer();
>       ren.updateOffScreen(clientDisplaySize.width,
clientDisplaySize.height);
>       ren.setTree(gvtRoot);
>       ren.setTransform(curTxf);
>       manager.manageUpdates(renderer.getImageRenderer());
>       manager.getUpdateRunnableQueue().invokeLater(new Runnable() {
>          public void run() {
>             java.awt.Rectangle r = new java.awt.Rectangle( 0, 0,
> clientDisplaySize.width, clientDisplaySize.height);
>             manager.updateRendering(curTxf, true, r,
clientDisplaySize.width,
> clientDisplaySize.height);
>             render();
>          }
>       });
>       this.gvtRoot = gvtRoot;
>    }
>
>
> -----Original Message-----
> From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com]
> Sent: Saturday, March 04, 2006 7:36 AM
> To: batik-users@xmlgraphics.apache.org
> Cc: batik
> Subject: Re: Batik offscreen rendering howto?
>
>
> Hi Javid,
>
> "Javid Alimohideen" <ja...@gmail.com> wrote on 03/03/2006 08:28:03
PM:
>
> > I have a dynamic renderer in my application to render the svg content
> > (offscreen). The rendering works fine but if I make some changes to
the
> > document the renderer.repaint method doesn't reflect the changes made
to
> the
> > dom.
>
>     It sounds like you didn't build the Rendering trying with the
> Bridge set to DYNAMIC.  In this case it won't register listeners
> with the Dom tree to keep the GVT tree in sync with the DOM.
>
>     Also the dynamic renderer alone is not sufficient to handle
> the 'updates' you need to give it the 'dirty' regions.  Which
> is part of what the UpdateManager normally does for you.
>
>
> ---------------------------------------------------------------------
> 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
>


---------------------------------------------------------------------
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


RE: Batik offscreen rendering howto?

Posted by th...@kodak.com.
Hi Javid,

"Javid Alimohideen" <ja...@gmail.com> wrote on 03/04/2006 04:31:04 PM:

> I added the UpdateManager as you had suggested but I still don't get the
> updates. I am sure about doing something wrong but couldn't figure out 
what.
> So, here is the initialization code:

        The basic code looks ok to me.

> I do the updates in the updatemenager runnable thread 
        Good.

> and later call the updatemanager.updateRendering method.

     You shouldn't have to do this, when a runnable completes it should
normally kick off an update of the canvas by calling 
UpdateManager.repaint().

> and I get the offscreen buffer by the getRepaintManager().getOffscreen
> method.

   I would suggest you register an 'updateCompleted' event listener with
the UpdateManager.  This will be called with an UpdateManagerEvent that
will have the offscreen that you should be using.

> It would be also helpful if you could point me to the batik source files
> that I must look at.

   Well the method that kicks off the update is the 
'UpdateManager.repaint()'
method (which is automatically called when a runnable completes in the
UpdateManager's runnable queue. 

> public void initialize() {
>       GraphicsNode gvtRoot = null ;
> 
>       try {
>          ctx.setDynamicState(BridgeContext.DYNAMIC);
>          gvtRoot = builder.build(ctx, svgDocument);
>       }
>       catch (BridgeException e) { e.printStackTrace(); }
>       renderer = PavisRenderer.getPavisRenderer();
> 
>       float docWidth = (float) ctx.getDocumentSize().getWidth();
>       float docHeight = (float) ctx.getDocumentSize().getHeight();
> 
>       float xscale = clientDisplaySize.width/docWidth;
>       float yscale = clientDisplaySize.height/docHeight;
>       float scale = Math.min(xscale, yscale);
> 
>       AffineTransform px  = AffineTransform.getScaleInstance(scale, 
scale);
> 
>       double tx = -0 + (clientDisplaySize.width/scale - docWidth)/2;
>       double ty = -0 + (clientDisplaySize.height/scale - docHeight)/2;
>       px.translate(tx, ty);
>       CanvasGraphicsNode cgn = getGraphicsNode(gvtRoot);
>         if (cgn != null) {
>             cgn.setViewingTransform(px);
>             curTxf = new AffineTransform();
>         } else {
>             curTxf = px;
>         }
>       manager = new UpdateManager(ctx, gvtRoot, svgDocument);
>       ImageRenderer ren = renderer.getImageRenderer();
>       ren.updateOffScreen(clientDisplaySize.width, 
clientDisplaySize.height);
>       ren.setTree(gvtRoot);
>       ren.setTransform(curTxf);
>       manager.manageUpdates(renderer.getImageRenderer());
>       manager.getUpdateRunnableQueue().invokeLater(new Runnable() {
>          public void run() {
>             java.awt.Rectangle r = new java.awt.Rectangle( 0, 0,
> clientDisplaySize.width, clientDisplaySize.height);
>             manager.updateRendering(curTxf, true, r, 
clientDisplaySize.width,
> clientDisplaySize.height);
>             render();
>          }
>       });
>       this.gvtRoot = gvtRoot;
>    }
> 
> 
> -----Original Message-----
> From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com]
> Sent: Saturday, March 04, 2006 7:36 AM
> To: batik-users@xmlgraphics.apache.org
> Cc: batik
> Subject: Re: Batik offscreen rendering howto?
> 
> 
> Hi Javid,
> 
> "Javid Alimohideen" <ja...@gmail.com> wrote on 03/03/2006 08:28:03 
PM:
> 
> > I have a dynamic renderer in my application to render the svg content
> > (offscreen). The rendering works fine but if I make some changes to 
the
> > document the renderer.repaint method doesn't reflect the changes made 
to
> the
> > dom.
> 
>     It sounds like you didn't build the Rendering trying with the
> Bridge set to DYNAMIC.  In this case it won't register listeners
> with the Dom tree to keep the GVT tree in sync with the DOM.
> 
>     Also the dynamic renderer alone is not sufficient to handle
> the 'updates' you need to give it the 'dirty' regions.  Which
> is part of what the UpdateManager normally does for you.
> 
> 
> ---------------------------------------------------------------------
> 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
> 


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


RE: Batik offscreen rendering howto?

Posted by Javid Alimohideen <ja...@gmail.com>.
Hi Thomas,
I added the UpdateManager as you had suggested but I still don't get the
updates. I am sure about doing something wrong but couldn't figure out what.
So, here is the initialization code:
I do the updates in the updatemenager runnable thread and later call the
updatemanager.updateRendering method.
and I get the offscreen buffer by the getRepaintManager().getOffscreen
method.
It would be also helpful if you could point me to the batik source files
that I must look at.

Thanks for your help,
Javid

public void initialize() {
		GraphicsNode gvtRoot = null ;

		try {
			ctx.setDynamicState(BridgeContext.DYNAMIC);
			gvtRoot = builder.build(ctx, svgDocument);
		}
		catch (BridgeException e) { e.printStackTrace(); }
		renderer = PavisRenderer.getPavisRenderer();

		float docWidth = (float) ctx.getDocumentSize().getWidth();
		float docHeight = (float) ctx.getDocumentSize().getHeight();

		float xscale = clientDisplaySize.width/docWidth;
		float yscale = clientDisplaySize.height/docHeight;
		float scale = Math.min(xscale, yscale);

		AffineTransform px  = AffineTransform.getScaleInstance(scale, scale);

		double tx = -0 + (clientDisplaySize.width/scale - docWidth)/2;
		double ty = -0 + (clientDisplaySize.height/scale - docHeight)/2;
		px.translate(tx, ty);
		CanvasGraphicsNode cgn = getGraphicsNode(gvtRoot);
        if (cgn != null) {
            cgn.setViewingTransform(px);
            curTxf = new AffineTransform();
        } else {
            curTxf = px;
        }
		manager = new UpdateManager(ctx, gvtRoot, svgDocument);
		ImageRenderer ren = renderer.getImageRenderer();
		ren.updateOffScreen(clientDisplaySize.width, clientDisplaySize.height);
		ren.setTree(gvtRoot);
		ren.setTransform(curTxf);
		manager.manageUpdates(renderer.getImageRenderer());
		manager.getUpdateRunnableQueue().invokeLater(new Runnable() {
			public void run() {
				java.awt.Rectangle r = new java.awt.Rectangle( 0, 0,
clientDisplaySize.width, clientDisplaySize.height);
				manager.updateRendering(curTxf, true, r, clientDisplaySize.width,
clientDisplaySize.height);
				render();
			}
		});
		this.gvtRoot = gvtRoot;
	}


-----Original Message-----
From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com]
Sent: Saturday, March 04, 2006 7:36 AM
To: batik-users@xmlgraphics.apache.org
Cc: batik
Subject: Re: Batik offscreen rendering howto?


Hi Javid,

"Javid Alimohideen" <ja...@gmail.com> wrote on 03/03/2006 08:28:03 PM:

> I have a dynamic renderer in my application to render the svg content
> (offscreen). The rendering works fine but if I make some changes to the
> document the renderer.repaint method doesn't reflect the changes made to
the
> dom.

    It sounds like you didn't build the Rendering trying with the
Bridge set to DYNAMIC.  In this case it won't register listeners
with the Dom tree to keep the GVT tree in sync with the DOM.

    Also the dynamic renderer alone is not sufficient to handle
the 'updates' you need to give it the 'dirty' regions.  Which
is part of what the UpdateManager normally does for you.


---------------------------------------------------------------------
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


RE: Batik offscreen rendering howto?

Posted by th...@kodak.com.
Hi Javid,

"Javid Alimohideen" <ja...@gmail.com> wrote on 03/04/2006 06:35:10 PM:

> I was looking through the JSVGCanvas, JSVGComponent source and I figured
> it's complicated for me to understand. All I want to able to do is 
Offscreen
> rendering and manipulate the document. Can someone suggest the batik 
classes
> that I should look into to accomplish my requirements. The 
Imagetranscoder
> is a good solution and I have been using it for a while, but the problem
> with that is everytime I called the transcode method it builds up a new 
tree
> and I would like to avoid it as the document is going to be the same 
except
> it's dynamic.

   Much of the complexity comes from the need to manage when repaints
should occur in a dynamic context, avoiding locking up the swing thread,
and managing 'dirty regions'.

   If you don't want any of these you could just get a graphics from
any old BufferedImage and call 'paint' on the root of the GVT tree.
If you want to try and manage dirty regions (not trivial) you can
try adding the 'updateTracker' to the mix (possibly with the 
DynamicRenderer) but this makes things quite a bit more complex really.

   I think your earlier code is pretty close to working.  I would
encourage you to produce a 'stand alone' version that could be
posted to the list.  Once it is working it could be added to the
Wiki.

> 
> Thanks for any help,
> Javid
> 
> -----Original Message-----
> From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com]
> Sent: Saturday, March 04, 2006 7:36 AM
> To: batik-users@xmlgraphics.apache.org
> Cc: batik
> Subject: Re: Batik offscreen rendering howto?
> 
> 
> Hi Javid,
> 
> "Javid Alimohideen" <ja...@gmail.com> wrote on 03/03/2006 08:28:03 
PM:
> 
> > I have a dynamic renderer in my application to render the svg content
> > (offscreen). The rendering works fine but if I make some changes to 
the
> > document the renderer.repaint method doesn't reflect the changes made 
to
> the
> > dom.
> 
>     It sounds like you didn't build the Rendering trying with the
> Bridge set to DYNAMIC.  In this case it won't register listeners
> with the Dom tree to keep the GVT tree in sync with the DOM.
> 
>     Also the dynamic renderer alone is not sufficient to handle
> the 'updates' you need to give it the 'dirty' regions.  Which
> is part of what the UpdateManager normally does for you.
> 
> 
> ---------------------------------------------------------------------
> 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
> 


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


RE: Batik offscreen rendering howto?

Posted by Javid Alimohideen <ja...@gmail.com>.
Hi,
I was looking through the JSVGCanvas, JSVGComponent source and I figured
it's complicated for me to understand. All I want to able to do is Offscreen
rendering and manipulate the document. Can someone suggest the batik classes
that I should look into to accomplish my requirements. The Imagetranscoder
is a good solution and I have been using it for a while, but the problem
with that is everytime I called the transcode method it builds up a new tree
and I would like to avoid it as the document is going to be the same except
it's dynamic.

Thanks for any help,
Javid

-----Original Message-----
From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com]
Sent: Saturday, March 04, 2006 7:36 AM
To: batik-users@xmlgraphics.apache.org
Cc: batik
Subject: Re: Batik offscreen rendering howto?


Hi Javid,

"Javid Alimohideen" <ja...@gmail.com> wrote on 03/03/2006 08:28:03 PM:

> I have a dynamic renderer in my application to render the svg content
> (offscreen). The rendering works fine but if I make some changes to the
> document the renderer.repaint method doesn't reflect the changes made to
the
> dom.

    It sounds like you didn't build the Rendering trying with the
Bridge set to DYNAMIC.  In this case it won't register listeners
with the Dom tree to keep the GVT tree in sync with the DOM.

    Also the dynamic renderer alone is not sufficient to handle
the 'updates' you need to give it the 'dirty' regions.  Which
is part of what the UpdateManager normally does for you.


---------------------------------------------------------------------
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


Re: Batik offscreen rendering howto?

Posted by th...@kodak.com.
Hi Javid,

"Javid Alimohideen" <ja...@gmail.com> wrote on 03/03/2006 08:28:03 PM:

> I have a dynamic renderer in my application to render the svg content
> (offscreen). The rendering works fine but if I make some changes to the
> document the renderer.repaint method doesn't reflect the changes made to 
the
> dom.

    It sounds like you didn't build the Rendering trying with the
Bridge set to DYNAMIC.  In this case it won't register listeners
with the Dom tree to keep the GVT tree in sync with the DOM.

    Also the dynamic renderer alone is not sufficient to handle
the 'updates' you need to give it the 'dirty' regions.  Which
is part of what the UpdateManager normally does for you.


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