United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4711444 Font Metrics information of 1.4 is different from that of 1.3
JDK-4711444 : Font Metrics information of 1.4 is different from that of 1.3

Details
Type:
Bug
Submit Date:
2002-07-08
Status:
Closed
Updated Date:
2013-10-10
Project Name:
JDK
Resolved Date:
2013-10-10
Component:
client-libs
OS:
windows_2000
Sub-Component:
2d
CPU:
x86
Priority:
P4
Resolution:
Won't Fix
Affected Versions:
1.4.1
Fixed Versions:

Related Reports
Relates:

Sub Tasks

Description
Some of font information (1.4.X) is different from that of 1.3.1_0X.
The diff. is small, but on the frame or canvas which have a lot of
components, such small diff. are piled up and finally, the looking
becomes different.

The attached program does not represent the seriousness which happens
to the customer, but prints each value of Font attributes.

1. Reproduce 

  Compile the attached program and invoke "java MetricTest".

===>
import java.awt.*;
//import javax.swing.*;

public class MetricsTest extends Canvas{

        public MetricsTest(int size, int style){
                //super(title);
                Font f = new Font("Dialog", style, size);
              FontMetrics fm =  getFontMetrics( f ) ;

              System.out.println("Font Height  : " + fm.getHeight() ) ;
              System.out.println("Font Max Advance : " + fm.getMaxAdvance()) ;
                System.out.println("Font Ascent  : " + fm.getAscent());
                System.out.println("Font Descent : " + fm.getDescent());
                System.out.println("Font Leading : " + fm.getLeading());

        }

        public static void main(String args[]){
                System.out.println("Test Start");
                MetricsTest gtp = new MetricsTest(20, Font.PLAIN);
                System.out.println("Test End") ;

        }
}
<===

2. configration
  
  MPU : Pentium IV 1.4 [GHz]
  MEM : 384 [MB]
  OS  : windows 2000 (SP2, japanese)
  Graphic Card : WinFast GeForce2 MX SH Pro
                (driver: 3.11.0130 )

3. Note

  The followings are the results.
  As for the leading and height are different between 1.4.X and 1.3.1_0X.

=========================================================
K:\sample3>java -version
java version "1.3.1_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_04-b02)
Java HotSpot(TM) Client VM (build 1.3.1_04-b02, mixed mode)

K:\sample3>java MetricsTest

Test Start
Font Height  : 27
Font Max Advance : 40
Font Ascent  : 21
Font Descent : 5
Font Leading : 1
Test End

=======================================================

K:\sample3>java -version
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

K:\sample3>java MetricsTest

Test Start
Font Height  : 26
Font Max Advance : 40
Font Ascent  : 21
Font Descent : 5
Font Leading : 0
Test End

======================================================

K:\sample3>java -version
java version "1.4.1-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-rc-b16)
Java HotSpot(TM) Client VM (build 1.4.1-rc-b16, mixed mode)

K:\sample3>java MetricsTest

Test Start
Font Height  : 26
Font Max Advance : 40
Font Ascent  : 21
Font Descent : 5
Font Leading : 0
Test End

======================================================


2002-07-08
=============================================================================

                                    

Comments
EVALUATION

The 1.4 figures are correct. In 1.3 and 1.3.1 there was excessive "rounding up"
of the values, such that a font which had an ascent=9.1 descent=2.1,
leading=0.1 would be summed as 10+3+1=14 when in facts its true height is 11.3
In 1.4 this was corrected, so JDK will report sizes that better correspond
to the font's true size, but still as integers for the APIs that report
only integers.

First in t2kScalerContext a macro  ROUNDAWAYFROMZERO(x) was
rounding up the individual components at native level, thus preventing
even the Java 2D APIs that worked with floating point values from actually
being able to usefuly retrieve the font metrics as floating point.

Secondly in FontDesignMetrics.java each of the components returned
by FontMetrics methoods getAscent(), getDescent(), getLeading() were
again rounded up to the next integer. (This did nothing for the already
rounded up integers, but means that fixing the first problem in
t2kScalerContext.cpp was not sufficient, as rounding would happen anyway
in Java). Finally, the getHeight() method summed these rounded-up values
for ascent/descent/leading. Together these resulted in the scenario above
where a font could easily be reported as being almost 2 pts larger than
its true height. The new code in 1.4 is as accurate as we can make it when
reporting something that is intrinsically of higher precision as integer
points.
This was fixed under bug ids 4455492 and 4467709 (the latter was a revision
to the previous fix).

In 1.4 you can get a truer sense of the fonts dimensions by adding these
lines to the test program :-
       BufferedImage bi = 
          new BufferedImage(BufferedImage.TYPE_INT_RGB, 10,10);
      Graphics g = bi.getGraphics();
      System.out.println("FM Max Bounds : " + fm.getMaxCharBounds(g));

This prints :-
FM Max Bounds : java.awt.geom.Rectangle2D$Float[x=0.0,y=-20.107422,w=40.0,h=25.1
5625]

"h" corresponds to the font height. As you can see the true height it 25.1
so the 1.3 figure of "27" was excessive. The 1.4 figure of "26" rounds up
only as much as necessary to ensure that an application client will
be able to calculate sufficient space to display the font.

###@###.### 2002-07-12
============================
                                     
2002-07-12



Hardware and Software, Engineered to Work Together