JDK-4271502 : FontMetrics.getHeight() method doesn't return correct height.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.2.3
  • Priority: P1
  • Status: Closed
  • Resolution: Not an Issue
  • OS: generic
  • CPU: x86
  • Submitted: 1999-09-14
  • Updated: 2001-02-09
  • Resolved: 2001-02-09
Related Reports
Relates :  
Description

Name: clC74495			Date: 09/14/99

=20
The applet made by using JDK1.1.2 dosen't work properly when=20
using Java plug-in(ver1.2.2), in the following case;
The height of cell which is obtained by FontMetrics.getHeight()=20
method is not correct.
Also FontMetrics.getDescent(),FontMetrics.getAscent() is not
correct.

Here are examples of behavior of getXXX() method.

                               NetcapeJDK1.1  JavaPlug-in1.2.2
         schemeFM.getHeight()       14(true)        20=81ifalse=81j
         schemeFM.getDescent()     =81@2(true)         5=81ifalse=81j
         schemeFM.getAscent()        2(true)         5=81ifalse=81j

Sample source code which includes getHeight() method is below;

public class getHeightApplet extends Applet {

  public static final Font LIST_FONT =3D new Font("monospaced", Font.PLAIN,=
 14);
  private final Font SCHEMEFONT =3D LIST_FONT;  // font for cell
  // metrics of font for cell
  private FontMetrics schemeFM =3D this.getFontMetrics(SCHEMEFONT);
  private Label label1 =3D new Label( "Font Size =3D 14" );
  private Label lblHeight =3D new Label();

  //architect of applet
  public getHeightApplet() {
        add( label1 );
        add( lblHeight );

        lblHeight.setText( "getHeight()=3D" + schemeFM.getHeight() );

  }

  //initialize applet
  public void init() {
  }

}
(Review ID: 95227)=20
======================================================================

Comments
EVALUATION I do not belive this is a bug. Can not make any comparison between JDK1.1 and JDK1.2 since it uses native Font and 2D Font respectively. It should return different height since it is using different font and different architecture. shoji.ishida@Japan 1999-09-22 In fact - 2d looks at the heights of all the components of the logical font and computes the maximum heights of the component fonts- which is the height. To get more accurate results use individual string and getStringBounds(). In retrospect, 1.1 should also have done this. parry.kejriwal@eng 1999-09-23 I had a meeting with this licensee. They expect getHeight() returns the value which equals to fontsize1, if they specify the following line in their source code: Font font1 = new Font("monospaced", Font.PLAIN, fontsize1); ... (Please refer their source code in the description.) If fontsize1 is 14, Netscape returns 14, and Java Plug-in returns 20. They want to use that value as the font size at the other place. (I don't know the detail.) As a result, their applet doesn't work correctly with Java Plug-in. Font is bigger than they expect. So they are bewildered and looking for the solution. Note: NTT has over fifteen products which uses Java technology. For one of them, they gave up using Java 1.2 because of some problems. (BugID 4271502, 4271498, 4271499) They are planning to use Java 1.3 or later version. So this bugreport isn't so urgent now. yuka.kamiya@japan 1999-09-29 I correct the above explanation. NTTcomware intended to migrate from Java 1.1.4 to Java2 for their product. However, they decide to use Java 1.1.X at this shipment because of these bugs. They don't fix the time to migrade to Java2 and don't fix the version of Java2 yet. So this bug isn't so urgent, however, its fix should be complated when NTTcomware plans to use Java2. yuka.kamiya@japan 1999-09-30 As stated earlier this is not a bug - the correct metrics for a logical font are the metrics of the fonts that compose it together. Depending on the context you are drawing you do not want the metrics of a single font or one that matches the point size. I believe the maximum of the logical fonts is the right thing to do. If the licensee wants other metrics they may instantiate that particular component of the logical font and get it metrics individually for laying out etc. parry.kejriwal@eng 1999-10-01
01-10-1999