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

height/baseline look different depends on how it gets rendered

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 1.2.0
    • 1.2.0
    • client-libs
    • 2d
    • 1.2fcs
    • generic
    • generic
    • Not verified

    Description

      height and baseline of font rendered using 2D font capability look very different if rendered differently.

      Run the following program and see difference between Graphics2D.drawString
      and Graphics2D.draw(Shape) using same Font object.

      The difference gets obvious if MS font(Win32) is used than HG font(Soalris).
      And Win32 result is worse than Solaris. Height of M is half of following S.

      I assume that this is drawString implementation problem rather than rasterlizer
      problem. And not related if glyph is complex or not like Kanji glyph.

      I haven't studied in detail but looks like AffineTransform is a cause?

      import java.applet.*;
      import java.awt.*;
      import java.awt.font.*;
      import java.awt.geom.*;
      import java.text.*;

      public class Small extends Applet{
              public void init() {
                      GraphicsEnvironment ge =
                              GraphicsEnvironment.getLocalGraphicsEnvironment();
                      Font[] fonts = ge.getAllFonts();
                      for (int i=0; i<fonts.length; i++) {
                              System.out.println(fonts[i].getName());
                      }
              }
              public void paint(Graphics g) {

                      int w = getSize().width;;
                      int h = getSize().height;;
                      Graphics2D g2 = (Graphics2D)g;

                      /*
                      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                              RenderingHints.VALUE_ANTIALIAS_ON);
                      */

                      Font f = new Font("MS Mincho", Font.PLAIN, 12);
                      String str = new String("MS-DOS Windows 1234567890");
                      TextLayout tl = new TextLayout(str, f, g2.getFontRenderContext());

                      float sw = (float) tl.getBounds().getWidth();
                      float sh = (float) tl.getAscent();

                      Shape sha = tl.getOutline(null,w/2-sw/2,h/2);

                      g2.setColor(Color.black);
                      g2.draw(sha);

                      g2.setColor(Color.blue);
                      tl.draw(g2,w/2-sw/2,h/2-25);

                      g2.setFont(f);
                      g2.setColor(Color.red);
                      g2.drawString(str,w/2-sw/2,h/2+25);
              }
      }

      Attachments

        Activity

          People

            pcharltosunw Paul Charlton (Inactive)
            sishidasunw Shoji Ishida (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: