[PATCH 3/5] gdi32: Try to read the dpi from the user key first.

Huw Davies huw at codeweavers.com
Thu Apr 27 05:02:35 CDT 2017


Signed-off-by: Huw Davies <huw at codeweavers.com>
---
 dlls/gdi32/freetype.c    | 11 +++------
 dlls/gdi32/gdi_private.h |  1 +
 dlls/gdi32/gdiobj.c      | 61 +++++++++++++++++++++++++++++++-----------------
 3 files changed, 44 insertions(+), 29 deletions(-)

diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c
index 8956720645..13edef6601 100644
--- a/dlls/gdi32/freetype.c
+++ b/dlls/gdi32/freetype.c
@@ -3993,16 +3993,11 @@ static void update_font_info(void)
     DWORD len, type;
     HKEY hkey = 0;
     UINT i, ansi_cp = 0, oem_cp = 0;
-    DWORD screen_dpi = 96, font_dpi = 0;
+    DWORD screen_dpi, font_dpi = 0;
     BOOL done = FALSE;
 
-    if (RegOpenKeyA(HKEY_LOCAL_MACHINE,
-                    "System\\CurrentControlSet\\Hardware Profiles\\Current\\Software\\Fonts",
-                    &hkey) == ERROR_SUCCESS)
-    {
-        reg_load_dword(hkey, logpixels, &screen_dpi);
-        RegCloseKey(hkey);
-    }
+    screen_dpi = get_dpi();
+    if (!screen_dpi) screen_dpi = 96;
 
     if (RegCreateKeyExA(HKEY_CURRENT_USER, "Software\\Wine\\Fonts", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey, NULL) != ERROR_SUCCESS)
         return;
diff --git a/dlls/gdi32/gdi_private.h b/dlls/gdi32/gdi_private.h
index 1eba290968..4236aa3690 100644
--- a/dlls/gdi32/gdi_private.h
+++ b/dlls/gdi32/gdi_private.h
@@ -303,6 +303,7 @@ extern HGDIOBJ GDI_inc_ref_count( HGDIOBJ handle ) DECLSPEC_HIDDEN;
 extern BOOL GDI_dec_ref_count( HGDIOBJ handle ) DECLSPEC_HIDDEN;
 extern void GDI_hdc_using_object(HGDIOBJ obj, HDC hdc) DECLSPEC_HIDDEN;
 extern void GDI_hdc_not_using_object(HGDIOBJ obj, HDC hdc) DECLSPEC_HIDDEN;
+extern DWORD get_dpi(void) DECLSPEC_HIDDEN;
 
 /* mapping.c */
 extern BOOL dp_to_lp( DC *dc, POINT *points, INT count ) DECLSPEC_HIDDEN;
diff --git a/dlls/gdi32/gdiobj.c b/dlls/gdi32/gdiobj.c
index 46b2241945..16b82a3af6 100644
--- a/dlls/gdi32/gdiobj.c
+++ b/dlls/gdi32/gdiobj.c
@@ -597,45 +597,64 @@ BOOL GDI_dec_ref_count( HGDIOBJ handle )
     return entry != NULL;
 }
 
+static const WCHAR dpi_key_name[] = {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p','\0'};
+static const WCHAR def_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'};
+
 /******************************************************************************
- *      get_dpi   (internal)
+ *              get_reg_dword
  *
- * get the dpi from the registry
+ * Read a DWORD value from the registry
  */
-static int get_dpi( void )
+static BOOL get_reg_dword(HKEY base, const WCHAR *key_name, const WCHAR *value_name, DWORD *value)
 {
-    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;
+    HKEY key;
+    DWORD type, data, size = sizeof(data);
+    BOOL ret = FALSE;
 
-    if (RegOpenKeyW(HKEY_CURRENT_CONFIG, dpi_key_name, &hkey) == ERROR_SUCCESS)
+    if (RegOpenKeyW(base, key_name, &key) == 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 (RegQueryValueExW(key, value_name, NULL, &type, (void *)&data, &size) == ERROR_SUCCESS &&
+            type == REG_DWORD)
         {
-            if (type == REG_DWORD && new_dpi != 0)
-                dpi = new_dpi;
+            *value = data;
+            ret = TRUE;
         }
-        RegCloseKey(hkey);
+        RegCloseKey(key);
     }
-    if (dpi <= 0) dpi = 96;
-    return dpi;
+    return ret;
 }
 
+/******************************************************************************
+ *              get_dpi
+ *
+ * get the dpi from the registry
+ */
+DWORD get_dpi(void)
+{
+    DWORD dpi;
+
+    if (get_reg_dword(HKEY_CURRENT_USER, dpi_key_name, dpi_value_name, &dpi))
+        return dpi;
+    if (get_reg_dword(HKEY_CURRENT_CONFIG, def_dpi_key_name, dpi_value_name, &dpi))
+        return dpi;
+    return 0;
+}
 
 static HFONT create_scaled_font( const LOGFONTW *deffont )
 {
     LOGFONTW lf;
     LONG height;
+    static DWORD dpi;
+
+    if (!dpi)
+    {
+        dpi = get_dpi();
+        if (!dpi) dpi = 96;
+    }
 
     lf = *deffont;
-    height = abs(lf.lfHeight) * get_dpi() / 96;
+    height = abs(lf.lfHeight) * dpi / 96;
     lf.lfHeight = deffont->lfHeight < 0 ? -height : height;
 
     return CreateFontIndirectW( &lf );
-- 
2.12.0




More information about the wine-patches mailing list