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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Saturday, March 04, 2006 6:19 PM
To: [email protected]
Cc: [email protected]
Subject: RE: Batik offscreen rendering howto?


Hi Javid,

"Javid Alimohideen" <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Sent: Saturday, March 04, 2006 7:36 AM
> To: [email protected]
> Cc: batik
> Subject: Re: Batik offscreen rendering howto?
>
>
> Hi Javid,
>
> "Javid Alimohideen" <[EMAIL PROTECTED]> 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: [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