Hi Thomas,

thanks very much!
although I need some time to understand the whole, but it works :-)

best regards,
Cui

Hi Cui,

> > Dear Batik-Experts,
> >
> > weeks ago I asked the question about how I can center a certain point
> > in a given svg-file, it worked very well with the answer provided by
> > Michael.
> > But after I added the viewbox attribute to the svg-file today, I
> > suddenly found the centering not working properly again (at least
> > after I resize the gui with maximize for instance)...
> > I couldn't understand why it's not working, so could someone please
> > take a look at the codes below and tell me why or how I can fix this?

>>    private void center(){
>>        try{
>>        AffineTransform at = this.canvas.getRenderingTransform();

    The major problem is that you want the ViewBox transform not
just the rendering transform, they are the same... unless you have
a viewBox.

>>        Point2D circleTemp = new Point2D.Double(circleX, circleY);
>>
>>        at.transform(circleTemp, circleTemp);
>>        double offsetX = this.canvas.getWidth()/2-circleTemp.getX();
>>        double offsetY = this.canvas.getHeight()/2-circleTemp.getY();

    At this point you need to get the RenderingTransform for at since
that is what you want to update.  The stuff with the rotation is done to
map the delta to the rendering transform.  This will work unless there
is non-uniform scaling/shearing (which is unusual).  My version at the
end doesn't have this small limitation.

>>        double angle = getRotationAngle(at);
>>        at.rotate(-angle);
>>        at.translate(offsetX/at.getScaleX(), offsetY/at.getScaleY());
>>        at.rotate(angle);
>>        this.canvas.setRenderingTransform(at);
>>        }catch(Exception e){
> >            e.printStackTrace();
> >        }
> >    }

     private void center(){
       try{
        AffineTransform at = this.canvas.getViewBoxTransform();

        Point2D circleTemp = new Point2D.Double(circleX, circleY);

        at.transform(circleTemp, circleTemp);
double offsetX = this.canvas.getWidth()/2-circleTemp.getX();
        double offsetY = this.canvas.getHeight()/2-circleTemp.getY();

        at = this.canvas.getRenderingTransform();
        AffineTransform iat = at.createInverse();

        Point2D delta = new Point2D.Double(offsetX, offsetY);
        iat.transform(delta, delta);
at.translate(delta.getX()-iat.getTranslateX(),
                     delta.getY()-iat.getTranslateY());
this.canvas.setRenderingTransform(at);
        }catch(Exception e){
           e.printStackTrace();
       }
   }


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

Reply via email to