Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6182443

Rotated antialiased text is too light gray

XMLWordPrintable

    • 2d
    • b77
    • generic
    • generic

      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

            igor Igor Nekrestyanov (Inactive)
            igor Igor Nekrestyanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: