changeset 454:9216ec4e4c14

6979979: Rounding error in font sizes selected by the GTK Look and Feel Summary: Use floating point font sizes Reviewed-by: prr
author omajid
date Tue, 14 Sep 2010 10:45:38 -0400
parents f4ad6e24e75d
children 826806a193c8 547ec9b43edd
files src/share/classes/com/sun/java/swing/plaf/gtk/PangoFonts.java src/share/classes/sun/font/FontManager.java
diffstat 2 files changed, 9 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/java/swing/plaf/gtk/PangoFonts.java	Tue Oct 19 16:51:14 2010 -0700
+++ b/src/share/classes/com/sun/java/swing/plaf/gtk/PangoFonts.java	Tue Sep 14 10:45:38 2010 -0400
@@ -148,11 +148,6 @@
          * case for it to be a problem the values would have to be different.
          * It also seems unlikely to arise except when a user explicitly
          * deletes the X resource database entry.
-         * 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.
          * There also some other issues to be aware of for the future:
          * GTK specifies the Xft.dpi value as server-wide which when used
          * on systems with 2 distinct X screens with different physical DPI
@@ -195,11 +190,16 @@
         String fcFamilyLC = family.toLowerCase();
         if (FontManager.mapFcName(fcFamilyLC) != null) {
             /* family is a Fc/Pango logical font which we need to expand. */
-           return FontManager.getFontConfigFUIR(fcFamilyLC, style, size);
+            Font font =  FontManager.getFontConfigFUIR(fcFamilyLC, style, size);
+            font = font.deriveFont(style, (float)dsize);
+            return new FontUIResource(font);
         } else {
             /* It's a physical font which we will create with a fallback */
-            Font font = new FontUIResource(family, style, size);
-            return FontManager.getCompositeFontUIResource(font);
+            Font font = new Font(family, style, size);
+            /* a roundabout way to set the font size in floating points */
+            font = font.deriveFont(style, (float)dsize);
+            FontUIResource fuir = new FontUIResource(font);
+            return FontManager.getCompositeFontUIResource(fuir);
         }
     }
 
--- a/src/share/classes/sun/font/FontManager.java	Tue Oct 19 16:51:14 2010 -0700
+++ b/src/share/classes/sun/font/FontManager.java	Tue Sep 14 10:45:38 2010 -0400
@@ -431,8 +431,7 @@
      */
     public static FontUIResource getCompositeFontUIResource(Font font) {
 
-        FontUIResource fuir =
-            new FontUIResource(font.getName(),font.getStyle(),font.getSize());
+        FontUIResource fuir = new FontUIResource(font);
         Font2D font2D = getFont2D(font);
 
         if (!(font2D instanceof PhysicalFont)) {