xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ricardo Trindade" <Ricardo.Trind...@myrealbox.com>
Subject RE: Resizing the view port (cont'd)
Date Fri, 12 Apr 2002 09:47:19 GMT

are you by any chance using an IDE ? I can't get the canvas to display in
development mode using JBuilder, just when I run the project...

about the rendering I looked a bit at it yesterday and understood that my
problem was trying to insert a AffineTransform before I could obtain the
transform. so now I have something like this :

 private void addListeners()
    addGVTTreeBuilderListener(new GVTTreeBuilderAdapter() {
          public void gvtBuildCompleted(GVTTreeBuilderEvent evt) {

	I add the listener in the constructor of my canvas (sublcass of batik
canvas), and it gets called when the image is loaded. don't know if it's any
help to you.

  private void transformImage(int scaleX, int scaleY)
    // apply scale factor
    AffineTransform at = getRenderingTransform();
    if (at != null) {
      Dimension dim = getSize();
      int x = dim.width / 2;
      int y = dim.height / 2;
                AffineTransform t = AffineTransform.getTranslateInstance(x,
                t.scale( scaleX , scaleY );
                t.translate(-x, -y);


-----Original Message-----
From: Jon Burgin [mailto:jburgin@onboard-software.com]
Sent: quinta-feira, 11 de Abril de 2002 22:51
To: 'batik-users@xml.apache.org'
Subject: Resizing the view port (cont'd)

I'm not sure what you are after, but If you want to scale the svg to the
size of your svg canvas, you can extend jsvgcanvas and overload the
following function:

     * Computes the initial value of the transform used for rendering
	  * this scales the image (preserving aspect ratio)
	  * so that it fits the size of the canvas.
    protected void computeRenderingTransform() {
				Dimension2D _imageSize;
				Rectangle _paneSize;
				double x, y;
				_imageSize = getSVGDocumentSize();
				_paneSize = this.getBounds();
				x = _paneSize.getWidth() /
				y = _paneSize.getHeight() /
				//If the image is too big in either
				//shrink so larger dimension will fit. (i.e
apply the smaller ratio)
				if(x < 1.0 || y < 1.0){
					 x = Math.min(x,y);
					 y = Math.min(x,y);
				}else{//if smaller (or same in both) apply
the larger ratio
					 x = Math.max(x,y);
					 y = Math.max(x,y);
		  }catch(NullPointerException npe){
				x = y = 1;
        initialTransform = new AffineTransform();
Be careful though, as jsvgcomponent will set the preferred size of
jsvgcanvas.  This will cause a problem if you have you canvas inside a
To fix this I added the following function and set the min max size:

	 * We have to overwrite this function so that the loading of a new
	 * document does not change the preferred size beyond the min/max
	 * JSVGComponent.buildComplete(..) calls this.
	 * @param d
	 public void setPreferredSize(Dimension d){
		  Dimension dmin, dmax;

		  dmin = getMinimumSize();
		  d.width = (int)Math.max(d.getWidth(),dmin.getWidth());
		  d.height = (int)Math.max(d.getHeight(),dmin.getHeight());

		  dmax = getMaximumSize();
		  d.width = (int)Math.min(d.getWidth(),dmax.getWidth());
		  d.height = (int)Math.min(d.getHeight(),dmax.getHeight());

Hope this helps,

Jonathan Burgin
OnBoard Software Inc.
12621 Silicon Dr., Ste. 113
San Antonio, TX 78249
Phone: 210.932.1683
Direct Line: 210.477.5390
Fax: 210.932.1280

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

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

View raw message