-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.2.0
-
generic
-
generic
Name: mf23781 Date: 07/01/99
--------------------------------------------------------------
IBM to Java Platform TOP TEN Sustaining Escalation Process
--------------------------------------------------------------
(1) SUN Bug ID: 4098456
(2) Workarounds:
Description of workaround:
NONE
(3) Test Case and Failure Data:
import java.awt.*;
public class TestFonts extends Frame {
Font font;
TestFonts(int pt) {
font = new Font("Monospaced", Font.PLAIN, pt);
MyCanvas can = new MyCanvas(font);
add(can);
can.repaint();
setBounds(0, 0, 300, 200);
show();
repaint();
}
public static void main(String[] args) {
new TestFonts(8);
new TestFonts(10);
new TestFonts(12);
new TestFonts(15);
new TestFonts(25);
new TestFonts(72);
}
}
class MyCanvas extends Canvas {
Font font;
MyCanvas(Font f) {
this.font = f;
}
public void paint(Graphics g) {
g.setFont(font);
g.drawString("Font tests ", 10, 72);
FontMetrics fm = g.getFontMetrics();
System.out.println("Font = " + g.getFont());
System.out.println("FontMet = " + fm);
System.out.println("Size = " + font.getSize());
System.out.println("Ascent = " + fm.getAscent());
System.out.println("Descent = " + fm.getDescent());
System.out.println("Height = " + fm.getHeight());
}
}
Description of Problem:
FontMetrics have changed in Java2.
This is problematic when, for example, a print job uses
FontMetrics.getHeight() to format it's output (the text now
appears one-and-a-half spaced).
e.g. for a 10pt Monospaced Java font:
JDK 1.1.8 JDK 1.2.1/1.2.2
Size 10 10
Ascent 9 11
Descent 3 4
Height 12 15
Problem Analysis:
A FontDesignMetrics object (extends FontMetrics) is instantiated
by SunGraphics2D.makeFontMetrics which calls
NativeFontWrapper.getFontMetrics(font, matrix, isAA, isFract, metrics)
NativeFontWrapper.getFontMetrics calls
Strike::GetLineHeight(ascent, descent,
baseline, leading, maxAdvance);
which calls (FontWrapper.cpp)
Looking at Strike.cpp, this is what appears to be going on...
The Monospaced font is a "composite font", comprised of three
"slots". For each slot, an 'hsGGlyphStrike' object is
instantiated. The 'GetLineHeight' function is called for each
hsGGlyphStrike, assigning values to the metric variables: ascent,
descent, baseline, leading and maxAdvance. For our test case, using
various point sizes for a Java Monospaced font, the number
of slots for the font is 3. For each font, the first call to
GetLineHeight assigns metric values approx equal to those in
1.1.8. On, the subsequent calls to GetLineHeight these metric
variables are increased.
(4) Targeted FCS Release:
1.2.2 (fix must be portable to 1.2.1)
(5) Operational/Business Justification:
Impact of bug on affected product:
Severe problem for printing capabilty of IBM VisualAge product.
Timefactors and deadlines involved:
Product is ready to ship.
(6) Suggested Fix:
Suggested Fix:
To "fix" the problem, I removed the loop that cycles through the
slots, such that only the first slot is considered when calculating
the font metrics. This is clearly an unsatisfactory hack and we
are looking to Sun for a proper fix.
diff for src\share\native\sun\awt\font\Strike.cpp
293c293,294
< for (int i=0; i < numSlots; i++) {
---
> // for (int i=0; i < numSlots; i++) {
> if (numSlots) {
300c301,302
< hsGGlyphStrike *currentStrike = compositeStrikeForSlot(i);
---
> // hsGGlyphStrike *currentStrike = compositeStrikeForSlot(i);
> hsGGlyphStrike *currentStrike = compositeStrikeForSlot(0);
Documentation of how root cause was found:
A basic trawling and 'printf' aspproach.
Alternative Fixes (advantages/disadvntages):
Results of IBM Testing in application/customer environment:
Regression Test Run Status/Results:
JCK Test run status:
No applicable JCK tests.
(Review ID: 85086)
======================================================================
- duplicates
-
JDK-4169941 JDK 1.1.7/JDK 1.2 forms font is inconsistency
-
- Closed
-