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

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) {
		transformImage(-1,-1);
        }
      });
  }

	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,
y);
                t.scale( scaleX , scaleY );
                t.translate(-x, -y);
      t.concatenate(at);
      setRenderingTransform(t);
    }
  }

thanks
Ricardo

-----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;
		  try{
				_imageSize = getSVGDocumentSize();
				_paneSize = this.getBounds();
				x = _paneSize.getWidth() /
_imageSize.getWidth();
				y = _paneSize.getHeight() /
_imageSize.getHeight();
				//If the image is too big in either
direction,
				//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();
		  initialTransform.setToScale(x,y);
        setRenderingTransform(initialTransform);
    }
Be careful though, as jsvgcomponent will set the preferred size of
jsvgcanvas.  This will cause a problem if you have you canvas inside a
jscrollpane
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());
		  super.setPreferredSize(d);
	 };

Hope this helps,
Jon

Jonathan Burgin
OnBoard Software Inc.
12621 Silicon Dr., Ste. 113
San Antonio, TX 78249
www.onboard-software.com
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


Mime
View raw message