Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Graphics.setTransform and TextLayout problems


  • From: Marc Palmer" <marc@xxxxxxxxxxxxx (Marc Palmer)
  • Subject: Graphics.setTransform and TextLayout problems
  • Date: Thu, 30 Dec 1999 17:55:05 -0000

Hi,

I've got some code that uses the java.awt.font.TextLayout class to render
text to a Graphics2D.

This is all working fine. However, I am now applying an AffineTransform to
the Graphics2D and it's stopped working. It appears to calculate the bounds
of the text correctly, but it does not draw the text - it just draws a
square where each font glyph should be.

There are bugs on the JDC bug database relating to this but they all say it
is related to the Printing API and that it is fixed in JDK 1.2.2 - this is
not true!

Here is code that reproduces it reliably on my machine. I would be grateful
if someone else could run this and back me up or point out if it's my fault.
If someone can back me up I will add it to the JDC bug database:

/*
 This application demonstrates a bug in TextLayout when a SCALING
AffineTransform
 is applied to the GRAPHICS (not the FontRenderContext).
 Contrary to the JDC bug database, this issue does not seem to be closed in
 JDK 1.2.2 running on Win95

 This application draws "Buggy" onto two separate BufferedImage(s) and
renders
 one above the other in the frame. The top bitmap is not scaled, the second
is scaled by
 a factor of 2. You can see in the second scaled bitmap that the letters of
the word
 "Buggy" are not rendered, but little rectangles are rendered instead of
each glyph.

 The getBounds() implementation seems to be correct - it's just the Glyph
 rendering that is failing as far as I can tell.

 marc@xxxxxxxxxxxxx 30 Dec 1999
*/

import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.awt.font.*;

public class TextLayoutBug extends Frame {

  public TextLayoutBug()
  {
    super();

    resize( 240, 240);

    bi_1 = new BufferedImage( 200, 100, BufferedImage.TYPE_INT_RGB);
    bi_2 = new BufferedImage( 200, 100, BufferedImage.TYPE_INT_RGB);

    // Draw the top bitmap, with scaling 1 (i.e. none)
    doBugText( bi_1, 1);
    // Draw the bottom bitmap, with scaling 2 - does not work
    doBugText( bi_2, 2);

    show();
  }

  public void doBugText( BufferedImage b, int scale)
  {
    int x = 20;
    int y = 20;

    Graphics2D g = (Graphics2D)b.getGraphics();
    g.setTransform( AffineTransform.getScaleInstance( scale, scale) );

    Font f = new Font( "SansSerif", Font.PLAIN, 10);
    FontRenderContext frc = g.getFontRenderContext();

    TextLayout tl = new TextLayout( "Buggy", f, frc);
    tl.draw( g, x, y);

    Rectangle2D bounds = tl.getBounds();
    bounds.setFrame( x + bounds.getX(), y + bounds.getY(),
      bounds.getWidth(), bounds.getHeight() );
    g.draw( bounds);
  }

  public void paint( Graphics g)
  {
    super.paint( g);
    g.drawImage( bi_1, getInsets().left, getInsets().top, 200, 100, null);
    g.drawImage( bi_2, getInsets().left, getInsets().top+110, 200, 100,
null);
  }

  public static void main(String[] args) {
    TextLayoutBug textLayoutBug = new TextLayoutBug();
  }

  private BufferedImage bi_1;
  private BufferedImage bi_2;
}



---
To unsubscribe, mail advanced-java-unsubscribe@xxxxxxxxxxxxxxxx
To get help, mail advanced-java-help@xxxxxxxxxxxxxxxx