xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jon Burgin <jbur...@onboard-software.com>
Subject RE: BATIK TUTORIAL
Date Tue, 11 Jun 2002 16:15:37 GMT
JSVGCanvas has a setRenderingTransform(..) function that will help
facilitate this.
Here is a little snippet of code that makes the svg document resize to the
container

    /**
     * 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();
				//we want all the documents to squish the
same amount,
				//that is, allow scrolling for the
larger-than-normal screen items
				_imageSize = new Dimension(600,600);
				_paneSize = this.getBounds();

				//if either of the following values is
greater than 1 then
				// the image is smaller than the space
availabe (in that dimension)
				x = _paneSize.getWidth() /
_imageSize.getWidth();
				y = _paneSize.getHeight() /
_imageSize.getHeight();

				//shrink so largest dimension will fit.
				// (i.e apply the smaller ratio)
				x = Math.min(x,y);
				y = Math.min(x,y);

		  }catch(NullPointerException npe){
				x = y = 1;
		  }
        initialTransform = new AffineTransform();
        initialTransform.setToScale(x,y);
        setRenderingTransform(initialTransform);
    }
The only (potential )problem is that the JSVGCanvas will attempt to set it's
preferred size to the size of the svg, which if causes you grief can be
fixed with the following code.

	/**
	 * 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);
	 };

-----Original Message-----
From: Xavier Ferret Yngl├Ęs [mailto:xferret@htmc-planet.net]
Sent: Tuesday, June 11, 2002 11:09 AM
To: batik-users@xml.apache.org
Subject: BATIK TUTORIAL


Hi

I'm trying to begin working with batik. 

I need to resize a SVG document when I resize its container, wich is a
JSVGCanvas. I think that what I nedd to make is a zoom and that this is
done with  Iterators but I'm not sure.


Could anybody give me any idea, any tutorial on that matter????


Tanks.

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