-
Bug
-
Resolution: Fixed
-
P4
-
1.2.0
-
None
-
merlin
-
generic
-
generic
The following test case draws different colors of text on a TYPE_BYTE_GRAY
buffered image. While the color of the normal text is the appropriate
gray value that is indicated at the top, the color of the antialiased text
is a fixed color. Examination of the source shows that the color for the
antialiased text is determined from an uninitialized variable.
-------- GrayTextTest.java --------
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
public class GrayTextTest extends Canvas {
public static final int WIDTH = 600;
public static final int HEIGHT = 200;
public void paint(Graphics g) {
BufferedImage bi = new BufferedImage(WIDTH, HEIGHT,
BufferedImage.TYPE_BYTE_GRAY);
Graphics2D g2d = bi.createGraphics();
g2d.setFont(new Font("Helvetica", Font.PLAIN, 24));
g2d.setColor(Color.white);
g2d.fillRect(0, 0, WIDTH / 2, HEIGHT);
drawText(g2d, Color.black, "Black", 25);
drawText(g2d, Color.lightGray, "Light Gray", 175);
g2d.setColor(Color.black);
g2d.fillRect(WIDTH / 2, 0, WIDTH / 2, HEIGHT);
drawText(g2d, Color.white, "White", 325);
drawText(g2d, Color.lightGray, "Light Gray", 475);
g2d.dispose();
g.drawImage(bi, 0, 0, null);
}
public void drawText(Graphics2D g2d, Color c, String colorname, int x) {
g2d.setColor(c);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_OFF);
g2d.drawString(colorname, x, 50);
g2d.drawString("Aliased", x, 100);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2d.drawString("Antialiased", x, 150);
}
public Dimension getPreferredSize() {
return new Dimension(WIDTH, HEIGHT);
}
public static void main(String argv[]) {
Frame f = new Frame();
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
f.add(new GrayTextTest());
f.pack();
f.show();
}
}
buffered image. While the color of the normal text is the appropriate
gray value that is indicated at the top, the color of the antialiased text
is a fixed color. Examination of the source shows that the color for the
antialiased text is determined from an uninitialized variable.
-------- GrayTextTest.java --------
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
public class GrayTextTest extends Canvas {
public static final int WIDTH = 600;
public static final int HEIGHT = 200;
public void paint(Graphics g) {
BufferedImage bi = new BufferedImage(WIDTH, HEIGHT,
BufferedImage.TYPE_BYTE_GRAY);
Graphics2D g2d = bi.createGraphics();
g2d.setFont(new Font("Helvetica", Font.PLAIN, 24));
g2d.setColor(Color.white);
g2d.fillRect(0, 0, WIDTH / 2, HEIGHT);
drawText(g2d, Color.black, "Black", 25);
drawText(g2d, Color.lightGray, "Light Gray", 175);
g2d.setColor(Color.black);
g2d.fillRect(WIDTH / 2, 0, WIDTH / 2, HEIGHT);
drawText(g2d, Color.white, "White", 325);
drawText(g2d, Color.lightGray, "Light Gray", 475);
g2d.dispose();
g.drawImage(bi, 0, 0, null);
}
public void drawText(Graphics2D g2d, Color c, String colorname, int x) {
g2d.setColor(c);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_OFF);
g2d.drawString(colorname, x, 50);
g2d.drawString("Aliased", x, 100);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2d.drawString("Antialiased", x, 150);
}
public Dimension getPreferredSize() {
return new Dimension(WIDTH, HEIGHT);
}
public static void main(String argv[]) {
Frame f = new Frame();
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
f.add(new GrayTextTest());
f.pack();
f.show();
}
}