JDK-6182443 : Rotated antialiased text is too light gray
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 6
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2004-10-21
  • Updated: 2010-04-04
  • Resolved: 2006-03-22
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b77Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.4.2_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_05-b04)
Java HotSpot(TM) Client VM (build 1.4.2_05-b04, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
With antialiasing turned on, rotated fonts at 0,90,180,270 degrees are drawn much darker than all other angles, including angles close to 90 degree multiples, like 0.01, 90.01 etc.

I suspect some code treats 90-degree rotation multiples as "special"


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
With antialiasing turned on, derive a font from an existing font using
an AffineTransform.getRotateInstance() using an angle that is
very close to a multiple of 90 degrees (90.01 for example) and the resulting text is drawn far lighter that if the angle was a multiple of 90 degrees.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expected rotated derived fonts to be drawn as dark as each other regardless of rotation angle.
ACTUAL -
Rotated derived fonts were drawn much darker if the rotation angle was a multiple of 90 degrees.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.geom.AffineTransform;
import javax.swing.*;

public class AATest extends JComponent
{
  static final double RADIANS_PER_DEGREE = 0.01745329251994;
private Font font;
  public AATest()
{
font = new Font("Serif",Font.PLAIN,10);
  }

  protected void paintComponent(Graphics g)
{
Graphics2D g2 = (Graphics2D)g;
Dimension dim = getSize();
paintComponent(g2,dim.width,dim.height);
}

protected void paintComponent(Graphics2D g,int width,int height)
{
g.setColor(Color.white);
g.fillRect(0,0,width,height);
g.setColor(Color.black);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
//g.drawLine(0,0,width,height);
g.setFont(font);
int y=20;
g.drawString("Horizontal",10,y);y+=20;

Font rotatedfont=getRotatedFont(0.01);
g.setFont(rotatedfont);
g.drawString("Rotated 0.01 degrees",10,y);y+=20;

rotatedfont=getRotatedFont(0.0);
g.setFont(rotatedfont);
g.drawString("Rotated 0.0 degrees",10,y);y+=20;

rotatedfont=getRotatedFont(-90.0);
g.setFont(rotatedfont);
g.drawString("Rotated 90 degrees",10,y);

rotatedfont=getRotatedFont(-90.01);
g.setFont(rotatedfont);
g.drawString("Rotated 90.01 degrees",30,y);
}

Font getRotatedFont(double angleDegrees)
{
double angle=angleDegrees*RADIANS_PER_DEGREE;
  AffineTransform xf=AffineTransform.getRotateInstance(-angle);
  return font.deriveFont(xf);
}

public static void main(String[] args) throws Exception
{
JFrame f = new JFrame("Antialias test");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().setLayout(new BorderLayout());
f.getContentPane().add(new AATest(),BorderLayout.CENTER);
f.setBounds(50,50,100,210);
f.setVisible(true);
}
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Turn off antialiasing (too bad since things look so nice with it turned on)
###@###.### 10/21/04 10:08 GMT

Comments
EVALUATION This problem was fixed as part of fix for 4654540. Now we enable hinting for much wider set of transformations. In particular for rotations hinting is either enabled or disabled depending on the size of unrotated text (scaling factor) and font flags (most of truetype fonts request to disable grid-fitting (aka hinting) for sizes below some given size). Note that this decision does NOT depend on rotation angle. While in some cases rotated hinted outline are not always superior for small rotations improvement is very noticeable. One other noticeable improvement is that results of varying rotation angle looks more consistent now (both appearance of glyphs and text line metrics). Also note that these changes affect and B&W mode. In particular in many cases slightly rotated text is more readable now. See attachment for before/after example.
14-03-2006

EVALUATION This is esentially sideeffect of turning off hinting for non-quadrant transforms (reported as 4654540) and is not AA issue per se. In case of quadrant transform glyph shape is hinted before scan convertion and at smaller sizes this often results in wider stems. If transform is non quadrant then we simply apply it to unhinted glyph outline and perform scan convertion. It is not surprise that wider stems looks darker. To make it more consistent we may want to apply transforms to hinted outlines.
27-01-2006