You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Jens von Pilgrim <j....@4flow.de> on 2001/11/15 13:23:02 UTC

Problems with rotated fonts and generator

Hello,

I've got a little question concering affine transformations such as
rotation.

There are (at least) two possibilities for performing an affine
transformation on a text: 1) Creating a rotated font or 2) "rotate" the
graphics.

The following code snippet illustrates both possiblities:

----------------8X--------------------8X-------------------
public void paint(Graphics io_Graphics) {
    java.awt.Graphics2D g2d = (java.awt.Graphics2D) io_Graphics;

    AffineTransform origAT = g2d.getTransform();
    Font origFont = g2d.getFont();
    g2d.setColor(Color.blue);

// 1) create rotated font
    AffineTransform at = new AffineTransform();
    at.rotate(Math.toRadians((double) 45d));
    Font rotatedFont = origFont.deriveFont(at);
    g2d.setFont(rotatedFont);
    g2d.drawString("Hello World by font.rotate", 40, 60);
    g2d.setFont(origFont);

    // restore
    g2d.setTransform(origAT);
    g2d.setFont(origFont);
    g2d.setColor(Color.red);

// 2) rotate graphics
    g2d.rotate(Math.toRadians((double) 45d), 40, 60);
    g2d.drawString("Hello World by graphics.rotate", 40, 60);

    g2d.setTransform(origAT);
}
----------------8X--------------------8X-------------------

Using an AWT graphics object (java.awt.Graphics) both fragments produce
the same rotation - the results are printed overlapped.

Using a SVGGraphics2D object, only the 2nd way performs the rotation,
the 1st way does _not_ rotate the font! OK, I can use the 2nd variant in
my code, but not if I use third party code...

This means, the AWT and SVG results differ! Is this a bug (or missing
feature) of the Batik (1.0 and 1.1RC3) generator?

jens

____________________________________________________________
Jens von Pilgrim
4flow AG
Berlin, Germany

Re: Problems with rotated fonts and generator

Posted by Vincent Hardy <vi...@sun.com>.
Jens,

Thanks for your detailed email. I need to investigate this but it
looks like a bug.

Vincent.

> Jens von Pilgrim wrote:
> 
> Hello,
> 
> I've got a little question concering affine transformations such as
> rotation.
> 
> There are (at least) two possibilities for performing an affine
> transformation on a text: 1) Creating a rotated font or 2) "rotate"
> the graphics.
> 
> The following code snippet illustrates both possiblities:
> 
> ----------------8X--------------------8X-------------------
> public void paint(Graphics io_Graphics) {
>     java.awt.Graphics2D g2d = (java.awt.Graphics2D) io_Graphics;
> 
>     AffineTransform origAT = g2d.getTransform();
>     Font origFont = g2d.getFont();
>     g2d.setColor(Color.blue);
> 
> // 1) create rotated font
>     AffineTransform at = new AffineTransform();
>     at.rotate(Math.toRadians((double) 45d));
>     Font rotatedFont = origFont.deriveFont(at);
>     g2d.setFont(rotatedFont);
>     g2d.drawString("Hello World by font.rotate", 40, 60);
>     g2d.setFont(origFont);
> 
>     // restore
>     g2d.setTransform(origAT);
>     g2d.setFont(origFont);
>     g2d.setColor(Color.red);
> 
> // 2) rotate graphics
>     g2d.rotate(Math.toRadians((double) 45d), 40, 60);
>     g2d.drawString("Hello World by graphics.rotate", 40, 60);
> 
>     g2d.setTransform(origAT);
> }
> ----------------8X--------------------8X-------------------
> 
> Using an AWT graphics object (java.awt.Graphics) both fragments
> produce the same rotation - the results are printed overlapped.
> 
> Using a SVGGraphics2D object, only the 2nd way performs the rotation,
> the 1st way does _not_ rotate the font! OK, I can use the 2nd variant
> in my code, but not if I use third party code...
> 
> This means, the AWT and SVG results differ! Is this a bug (or missing
> feature) of the Batik (1.0 and 1.1RC3) generator?
> 
> jens
> 
> ____________________________________________________________
> Jens von Pilgrim
> 4flow AG
> Berlin, Germany

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org