xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Laurent Caron <laurent.ca...@gmail.com>
Subject Re: Initial Rendering
Date Sun, 04 Dec 2005 14:12:06 GMT
Hi,

First of all, I'm using AWT instead of Swing because my application is based
on SWT, so my JSVGCanvas
is embedded inside a AWT Frame (embedded in a SWT Composite).

Thanks to Thomas, I found a solution adding a GVTTreeBuildListener :
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.geom.AffineTransform;
import java.io.File;

import org.apache.batik.swing.JSVGCanvas;
import org.apache.batik.swing.svg.GVTTreeBuilderAdapter;
import org.apache.batik.swing.svg.GVTTreeBuilderEvent;

public class Test {
    public static void main(String[] args) {
        Frame f = new Frame("Batik");
        final JSVGCanvas canvas = new JSVGCanvas();
        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        f.add(canvas);
        f.setSize(800, 600);

        canvas.addGVTTreeBuilderListener(new GVTTreeBuilderAdapter() {
            public void gvtBuildCompleted(GVTTreeBuilderEvent arg0) {
                AffineTransform at = AffineTransform.getScaleInstance(2, 2);
                canvas.setRenderingTransform(at, true);
            }
        });

        f.setVisible(true);
        canvas.setURI(new File("test.svg").toURI().toString());
    }
}


It is working perfectly !

Thanks

Laurent

On 12/3/05, thomas.deweese@kodak.com <thomas.deweese@kodak.com> wrote:
>
> Hi Laurent,
>
>     The problem is that you are setting the scale _way_ before the Canvas
> calculates the
> scale factor it will use for the rendering.  The easiest way to adjust the
> initial rendering
> transform is to create a small subclass of Canvas where you override
> 'calculateViewingTransform'.  You could also register a
> GVTTreeBuildListener
> with the Canvas and set the rendering transform in the 'gvtBuildCompleted'
> I'm fairly certain this will be called after the canvas calculates it's
> viewing transform.
>
>     Also for dynamic documents you can register an 'onload' DOM event
> handler
> and you can set the scale in that callback as well.
>
> Anthony Cavalliotis <anthony.cavalliotis@googlemail.com> wrote on
> 12/02/2005 08:19:38 PM:
>
> > Is there a reason you are using awt over swing?
> >
> > Anyhow, reason it doesn't work is that you've not added a panel.  Try:
> >
> >         Panel panel = new Panel();
> >         f.add(panel); // f & canvas are your components below
> >         panel.add(canvas);
> >
> > in swing you'd go a JPanel and f.getContentPane().add() instead.
> >
> > Cheers,
> >
> > Anthony
> >
> >
> > On 02/12/05, Laurent Caron <laurent.caron@gmail.com> wrote:
> > > Hi,
> > >
> > > I've got an image and I want to display it magnified (Zoom 2x) :
> > >
> > > import java.awt.Frame;
> > > import java.awt.event.WindowAdapter;
> > > import java.awt.event.WindowEvent;
> > > import java.awt.geom.AffineTransform ;
> > > import java.io.File;
> > >
> > > import org.apache.batik.swing.JSVGCanvas;
> > > import org.apache.batik.swing.gvt.GVTTreeRendererAdapter;
> > > import org.apache.batik.swing.gvt.GVTTreeRendererEvent;
> > > import org.apache.batik.swing.svg.GVTTreeBuilderEvent ;
> > > import org.apache.batik.swing.svg.GVTTreeBuilderListener;
> > >
> > > public class SVGApplication {
> > >
> > >     public static void main(String[] args) {
> > >         Frame f = new Frame("Batik");
> > >
> > >         JSVGCanvas svgCanvas = new JSVGCanvas();
> > >
> > >         JSVGCanvas canvas = new JSVGCanvas();
> > >         f.addWindowListener(new WindowAdapter() {
> > >             public void windowClosing(WindowEvent e) {
> > >                 System.exit(0);
> > >             }
> > >         });
> > >
> > >         f.add(canvas);
> > >         f.setSize(800, 600);
> > >         f.setVisible(true);
> > >         canvas.setURI(new File("test.svg").toURI().toString());
> > >         AffineTransform at =
> > > AffineTransform.getScaleInstance(2, 2);
> > >         canvas.setRenderingTransform(at,true);
> > >
> > >
> > >     }
> > > }
> > >
> > > But unfortunately, when the image is diplayed, the size is orginal. Is
> it
> > > possible to apply a renderingTransform before the image is displayed ?
> > >
> > > Thanks,
> > >
> > > Laurent
> > >
> >
> > ---------------------------------------------------------------------
> > 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
>
>

Mime
View raw message