[3/3] gdi32: Scale default GUI fonts to match screen resolution changes.

Dmitry Timoshkov dmitry at baikal.ru
Mon Jun 17 05:02:25 CDT 2013


This patch is supposed to fix the regression reported in the bug 33212.

Patch uses same approach that was removed by e65b19cad34ed0c440e0d4ccb630a3cd497b1c23
but also scales other fonts besides DEFAULT_GUI_FONT.
---
 dlls/gdi32/gdiobj.c     | 49 ++++++++++++++++++++++++++++++++++++++++++++++---
 dlls/gdi32/tests/font.c |  7 ++++++-
 2 files changed, 52 insertions(+), 4 deletions(-)

diff --git a/dlls/gdi32/gdiobj.c b/dlls/gdi32/gdiobj.c
index 5375049..de64474 100644
--- a/dlls/gdi32/gdiobj.c
+++ b/dlls/gdi32/gdiobj.c
@@ -597,6 +597,49 @@ BOOL GDI_dec_ref_count( HGDIOBJ handle )
     return entry != NULL;
 }
 
+/******************************************************************************
+ *      get_dpi   (internal)
+ *
+ * get the dpi from the registry
+ */
+static int get_dpi( void )
+{
+    static const WCHAR dpi_key_name[] = {'S','o','f','t','w','a','r','e','\\','F','o','n','t','s','\0'};
+    static const WCHAR dpi_value_name[] = {'L','o','g','P','i','x','e','l','s','\0'};
+    static int dpi = -1;
+    HKEY hkey;
+
+    if (dpi != -1) return dpi;
+
+    if (RegOpenKeyW(HKEY_CURRENT_CONFIG, dpi_key_name, &hkey) == ERROR_SUCCESS)
+    {
+        DWORD type, size;
+        int new_dpi;
+
+        size = sizeof(new_dpi);
+        if (RegQueryValueExW(hkey, dpi_value_name, NULL, &type, (void *)&new_dpi, &size) == ERROR_SUCCESS)
+        {
+            if (type == REG_DWORD && new_dpi != 0)
+                dpi = new_dpi;
+        }
+        RegCloseKey(hkey);
+    }
+    if (dpi <= 0) dpi = 96;
+    return dpi;
+}
+
+
+static HFONT create_scaled_font( const LOGFONTW *deffont )
+{
+    LOGFONTW lf;
+    LONG height;
+
+    lf = *deffont;
+    height = abs(lf.lfHeight) * get_dpi() / 96;
+    lf.lfHeight = deffont->lfHeight < 0 ? -height : height;
+
+    return CreateFontIndirectW( &lf );
+}
 
 /***********************************************************************
  *           DllMain
@@ -636,10 +679,10 @@ BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
 
     /* language-dependent stock fonts */
     deffonts = get_default_fonts(get_default_charset());
-    stock_objects[SYSTEM_FONT]         = CreateFontIndirectW( &deffonts->SystemFont );
-    stock_objects[DEVICE_DEFAULT_FONT] = CreateFontIndirectW( &deffonts->DeviceDefaultFont );
+    stock_objects[SYSTEM_FONT]         = create_scaled_font( &deffonts->SystemFont );
+    stock_objects[DEVICE_DEFAULT_FONT] = create_scaled_font( &deffonts->DeviceDefaultFont );
     stock_objects[SYSTEM_FIXED_FONT]   = CreateFontIndirectW( &deffonts->SystemFixedFont );
-    stock_objects[DEFAULT_GUI_FONT]    = CreateFontIndirectW( &deffonts->DefaultGuiFont );
+    stock_objects[DEFAULT_GUI_FONT]    = create_scaled_font( &deffonts->DefaultGuiFont );
 
     stock_objects[DC_BRUSH]     = CreateBrushIndirect( &DCBrush );
     stock_objects[DC_PEN]       = CreatePenIndirect( &DCPen );
diff --git a/dlls/gdi32/tests/font.c b/dlls/gdi32/tests/font.c
index 2802f0e..9563da9 100644
--- a/dlls/gdi32/tests/font.c
+++ b/dlls/gdi32/tests/font.c
@@ -5012,7 +5012,12 @@ static void test_stock_fonts(void)
             }
 
             /* FIXME: Remove once Wine is fixed */
-            if (td[i][j].dpi != 96) todo_wine
+            if (td[i][j].dpi != 96 &&
+                /* MS Sans Serif for 120 dpi and higher should include 12 pixel bitmap set */
+                ((!strcmp(td[i][j].face_name, "MS Sans Serif") && td[i][j].height == 12) ||
+                /* System for 120 dpi and higher should include 20 pixel bitmap set */
+                (!strcmp(td[i][j].face_name, "System") && td[i][j].height > 16)))
+            todo_wine
             ok(height == td[i][j].height_pixels, "%d(%d): expected height %d, got %d\n", i, j, td[i][j].height_pixels, height);
             else
             ok(height == td[i][j].height_pixels, "%d(%d): expected height %d, got %d\n", i, j, td[i][j].height_pixels, height);
-- 
1.8.3.1




More information about the wine-patches mailing list