Don't transform the canvas, transform the ellipse itself if you want to scale 
the ellipse.  Check the SVG spec for the "transform" attribute.  It'll be 
something like:
 
ballE.setAttributeNS(null, SVGConstants.SVG_TRANSFORM_ATTRIBUTE, "scale(5, 5)");
 
Michael Bishop

________________________________

From: Cui Jian [mailto:[email protected]]
Sent: Tue 2/3/2009 12:20 PM
To: [email protected]
Subject: Re: [Scale by constructing???]



Sorry, to make it more understandable, I changed some codes and here
again is the test program...

package resizeText;

import java.awt.Dimension;
import java.awt.geom.AffineTransform;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.apache.batik.swing.JSVGCanvas;
import org.apache.batik.util.SVGConstants;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class Resizer extends JFrame{

   /**
    *
    */
   private static final long serialVersionUID = 1L;

   private JSVGCanvas canvas;
      private Document svgDoc;
      private static final int ellipseX = 1500;
   private static final int ellipseY = 1000;
      private static final int canvasFixedWidth = 900;
   private static final int canvasFixedHeight = 600;
      public Resizer(){
              this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                  this.canvas = new JSVGCanvas();
       this.canvas.setDocumentState (JSVGCanvas.ALWAYS_DYNAMIC);
              DOMImplementation dom =
SVGDOMImplementation.getDOMImplementation ();
       svgDoc =
           dom.createDocument(SVGConstants.SVG_NAMESPACE_URI,
SVGConstants.SVG_SVG_TAG, null);
              this.initBall();
                      this.canvas.setDocument(svgDoc);
                     this.getContentPane().add(this.canvas, "Center");
              /**
        * here I tried to scale it by setting a new renderingtransform...
        */
       AffineTransform at = canvas.getRenderingTransform();
       at.scale(5, 5);
       canvas.setRenderingTransform(at);
              this.canvas.setMySize(new Dimension(canvasFixedWidth,
canvasFixedHeight));
              this.pack();
              this.setVisible(true);
          }
      private void initBall(){
       Element rootE = svgDoc.getDocumentElement();
       rootE.setAttributeNS(null, SVGConstants.SVG_VIEW_BOX_ATTRIBUTE,
"0 0 "+ellipseX*2+" "+ellipseY*2);
              Element ballE =
svgDoc.createElementNS(SVGConstants.SVG_NAMESPACE_URI,
SVGConstants.SVG_ELLIPSE_TAG);
       rootE.appendChild(ballE);
       ballE.setAttributeNS(null, SVGConstants.SVG_CX_ATTRIBUTE,
""+ellipseX);
       ballE.setAttributeNS(null, SVGConstants.SVG_CY_ATTRIBUTE,
""+ellipseY);
       ballE.setAttributeNS(null, SVGConstants.SVG_RX_ATTRIBUTE,
""+ellipseX);
       ballE.setAttributeNS(null, SVGConstants.SVG_RY_ATTRIBUTE,
""+ellipseY);
   }
      public static void main(String[] args){
       SwingUtilities.invokeLater(new Runnable() {
           public void run() {
               new Resizer();
           }
       });
   }
   }



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



<<winmail.dat>>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to