<Swing Dev> Fixing font sizes in GTKLookAndFeel
Omair Majid
omajid at redhat.com
Thu Aug 5 21:20:42 UTC 2010
Hi,
A while ago a user pointed out the issue that font sizes between GTK
programs and Swing programs using the GTKLookAndFeel can be
inconsistent. Digging through the code, here is a comment I found in
com.sun.java.swing.plaf.gtk.PangoFonts:
[snip]
* Finally this DPI is used to calculate the nearest Java 2D font
* 72 dpi font size.
* There are cases in which JDK behaviour may not exactly mimic
* GTK native app behaviour :
[snip]
* 3) Because of rounding errors sizes may differ very slightly
* between JDK and GTK. To fix that would at the very least require
* Swing to specify floating pt font sizes.
* Eg "10 pts" for GTK at 96 dpi to get the same size at Java 2D's
* 72 dpi you'd need to specify exactly 13.33.
[snip]
As it turns out, Swing is fine with floating point font sizes: I can use
affine transforms to scale the font. I also noticed that the Font class
supports setting floating point font sizes (through a private
constructor). I have created a patch that makes PangoFont avoid
converting the size to integer units. The webrev is available at:
http://cr.openjdk.java.net/~omajid/webrevs/gtk-floating-point-font-size-support/webrev.00/
Any comments and ideas are appreciated.
Thanks,
Omair
More information about the swing-dev
mailing list