Let me reformulate my question, the to be shown svg files have several
shapes and I used the viewbox attribute in order to display all of them.
But I only want to show part of the whole as I start the program, now my
window is set to display all of the elements because I used the viewbox
attribute. How can I scale the whole so that only part of the whole will
be displayed. The translating isn't quite important, because I have
another thread setting the scaled map to my desired position, the only
thing is how I can scale...
It's just like an adventure-game with a big map, now I only want to show
part of it so I need to scale the map...
my test program is below, could someone please help me???
Hi Michael,
tried this but it didn't work, because I've already used a viewbox
attribute in the roote element, if I use the scale attribute on a
certain child-element (like ballE in my example), I won't be able to
see the whole ball again if the viewbox isn't set big enough...
What I want is that I set the viewbox so that it could contain all
elements (more than one, another arguments why I can't use your
suggestion). As I scale the whole, I should still see all of them.
That's why I tried to set the rendering transform, 'cause I saw the
original zoom of jsvgcanvas was implemented in this way...
maybe other suggestions?
best,
Cui
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]
------------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
--
Dipl. Inform. Cui(Ken) Jian
German Research Center for Artificial Intelligence
Safe and Secure Cognitive Systems
DFKI-Labor Bremen Universitaet Bremen, FB3
Sichere Kognitive Systeme Cartesium 0.051
Robert-Hooke-Str. 5 Enrique-Schmidt-Str. 5
28359 Bremen 28359 Bremen
http://www.dfki.de www.informatik.uni-bremen.de/~ken
Tel.: +49 (421) 218-64204
Telefax: +49 (421) 218-98-64204
E-Mail:
[email protected] [email protected]
-------------------------------------------------------------
Deutsches Forschungszentrum fuer Kuenstliche Intelligenz GmbH
Firmensitz: Trippstadter Strasse 122, D-67663 Kaiserslautern
Geschaeftsfuehrung:
Prof. Dr. Dr. h.c. mult. Wolfgang Wahlster (Vorsitzender)
Dr. Walter Olthoff
Vorsitzender des Aufsichtsrats:
Prof. Dr. h.c. Hans A. Aukes
Amtsgericht Kaiserslautern, HRB 2313
-------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]