Thanks Phil! You were of course, completely right. I rebuilt FreeType with the bytecode interpreter enabled and now both the AWT FontMetrics string width and the TextLayout.getBounds() width match the Sun JDK exactly (and I really mean EXACTLY). The leading is still -1 though. In fact, if I get a LineMetrics from the Font, in the Sun JDK I get these: Height: 13.277344 Ascent: 11.005371 Descent: 2.2719727 Leading: -0.0
But in OpenJDK I get: Height: 13.0 Ascent: 11.0 Descent: 3.0 Leading: -1.0 I had a go at looking in to it myself but didnt get very far. I stuck a breakpoint in the StrikeMetrics constructor and could see that it was indeed getting those values. I also looked at the native code for FreetypeFontScaler.getFontMetricsNative(), and it seems correct as best as I can tell, but I havent yet figured out how to debug native JDK code. Still, its clear that the -1 is just the result of 13+(-11)-3, which is the right way to calculate it. The problem is that for some reason we're getting whole numbers for these metrics, and not even correctly rounded numbers (2.27 vs 3.0 for the descent). I'm stumped as to why. Also there an issue with the TextLayout bounds, in the Sun JDK, my TextLayout test gives the string the bounds: [x=0.0,y=-8.359375,w=238.29688,h=10.625] but in OpenJDK I get: [x=0.0,y=0.0,w=238.29688,h=18.453125] Notice that OpenJDK has given y=0, but it should be relative to the baseline. The height is also very wrong, although its suspicously close to h-y (taking the expected values from the Sun JDK). I'll keep digging and see if I can trace how thats calculated. ________________________________ From: Phil Race [mailto:[EMAIL PROTECTED] Sent: Thu 12/06/2008 23:49 To: Ben Loud Cc: [email protected] Subject: Re: [OpenJDK 2D-Dev] Font Metrics in OpenJDK vs Sun JDK The -1 for leading is probably a bug somewhere. Maybe you can look into it The difference in advance may be due to the absence of byte code hinting in the freetype found by OpenJDK. Since you have Tahoma I have to assume you are running on windows and built your own freetype, rather than using the one on the O/S. If you build freetype with hinting for testing purposes then the difference may be much less. -phil. Ben Loud wrote: > 2D Folk, > > Since working with OpenJDK, I've notice that text just doesnt look > right. I made a simple comparison between Sun's JDK6 and OpenJDK see: > http://benloud.com/fonts.png You can see there are clearly significant > differences in the horizontal character spacing, particularly > noticable in "Beagle" and "Spirit", and also the heights are > different. I also compared the font metrics of a string: > > For Tahoma, plain, 11pt, "The Quick Brown Fox Jumped Over The Lazy Dog." > AWT FontMetrics: > Ascent Descent Leading Height String Width > Sun JDK: 11 3 0 14 241 > OpenJDK: 11 3 -1 13 265 > > TextLayout: > Ascent Descent Leading Advance Bounds > Sun JDK: 11.005371 2.2719727 0.0 240.0 > [x=0.0,y=-8.359375,w=238.29688,h=10.625] > OpenJDK: 11.0 3.0 -1.0 264.0 > [x=0.0,y=0.0,w=263.29688,h=18.453125] > > Again you can see there are significant differences, particularly in > the advances and bounds, and the -1 for leading is a bit odd. > > Will it be possible to get metrics that are consistent with Suns JDK? > Because right now, Swing apps on OpenJDK look quite wrong to me. > > Thanks. > >
