Module: wine Branch: master Commit: 8e40e56b79c39356a981bbc25100daa9635b29f3 URL: https://source.winehq.org/git/wine.git/?a=commit;h=8e40e56b79c39356a981bbc25...
Author: Jacek Caban jacek@codeweavers.com Date: Mon Sep 27 13:05:38 2021 +0200
gdi32: Read screen DPI config in init_font_options.
Signed-off-by: Jacek Caban jacek@codeweavers.com Signed-off-by: Huw Davies huw@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/gdi32/font.c | 39 ++++++++++++++++++---------- dlls/gdi32/gdiobj.c | 65 +++++++--------------------------------------- dlls/gdi32/ntgdi_private.h | 3 +-- 3 files changed, 36 insertions(+), 71 deletions(-)
diff --git a/dlls/gdi32/font.c b/dlls/gdi32/font.c index b85f11b14a6..189405c2ba1 100644 --- a/dlls/gdi32/font.c +++ b/dlls/gdi32/font.c @@ -2682,7 +2682,7 @@ static void update_font_system_link_info(UINT current_ansi_codepage) } }
-static void update_codepage(void) +static void update_codepage( UINT screen_dpi ) { char value_buffer[FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data[40 * sizeof(WCHAR)])]; KEY_VALUE_PARTIAL_INFORMATION *info = (void *)value_buffer; @@ -2691,14 +2691,11 @@ static void update_codepage(void) HKEY hkey; DWORD size; UINT i, ansi_cp, oem_cp; - DWORD screen_dpi, font_dpi = 0; + DWORD font_dpi = 0; BOOL done = FALSE, cp_match = FALSE;
static const WCHAR log_pixelsW[] = {'L','o','g','P','i','x','e','l','s',0};
- screen_dpi = get_dpi(); - if (!screen_dpi) screen_dpi = 96; - size = query_reg_value( wine_fonts_key, log_pixelsW, info, sizeof(value_buffer) ); if (size == sizeof(DWORD) && info->Type == REG_DWORD) font_dpi = *(DWORD *)info->Data; @@ -4177,12 +4174,13 @@ static BOOL get_key_value( HKEY key, const char *name, DWORD *value ) return !!count; }
-static void init_font_options( HKEY hkcu ) +static UINT init_font_options( HKEY hkcu ) { char value_buffer[FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data[20 * sizeof(WCHAR)])]; KEY_VALUE_PARTIAL_INFORMATION *info = (void *)value_buffer; HKEY key; DWORD i, val, gamma = 1400; + UINT dpi = 0;
static const WCHAR desktop_keyW[] = { 'C','o','n','t','r','o','l',' ','P','a','n','e','l','\','D','e','s','k','t','o','p' }; @@ -4220,6 +4218,7 @@ static void init_font_options( HKEY hkcu ) { gamma = min( max( val, 1000 ), 2200 ); } + if (get_key_value( key, "LogPixels", &val )) dpi = val; NtClose( key ); }
@@ -4235,8 +4234,17 @@ static void init_font_options( HKEY hkcu ) font_gamma_ramp.decode[i] = pow( i / 255., gamma / 1000. ) * 255. + .5; } } + + if (!dpi && (key = reg_open_key( NULL, fonts_config_keyW, sizeof(fonts_config_keyW) ))) + { + if (get_key_value( key, "LogPixels", &val )) dpi = val; + NtClose( key ); + } + if (!dpi) dpi = 96; + font_gamma_ramp.gamma = gamma; - TRACE("gamma %d\n", font_gamma_ramp.gamma); + TRACE( "gamma %d screen dpi %u\n", font_gamma_ramp.gamma, dpi ); + return dpi; }
@@ -6123,12 +6131,13 @@ static const struct font_callback_funcs callback_funcs = { add_gdi_face }; /*********************************************************************** * font_init */ -void font_init(void) +UINT font_init(void) { OBJECT_ATTRIBUTES attr = { sizeof(attr) }; UNICODE_STRING name; HANDLE mutex, hkcu; DWORD disposition; + UINT dpi = 0;
static WCHAR wine_font_mutexW[] = {'\','B','a','s','e','N','a','m','e','d','O','b','j','e','c','t','s', @@ -6137,14 +6146,15 @@ void font_init(void) {'S','o','f','t','w','a','r','e','\','W','i','n','e','\','F','o','n','t','s'}; static const WCHAR cacheW[] = {'C','a','c','h','e'};
- if (RtlOpenCurrentUser( MAXIMUM_ALLOWED, &hkcu )) return; + if (RtlOpenCurrentUser( MAXIMUM_ALLOWED, &hkcu )) return 0; wine_fonts_key = reg_create_key( hkcu, wine_fonts_keyW, sizeof(wine_fonts_keyW), 0, NULL ); - if (wine_fonts_key) init_font_options( hkcu ); + if (wine_fonts_key) dpi = init_font_options( hkcu ); NtClose( hkcu ); - if (!wine_fonts_key) return; - update_codepage(); + if (!dpi) return 96; + update_codepage( dpi );
- if (__wine_init_unix_lib( gdi32_module, DLL_PROCESS_ATTACH, &callback_funcs, &font_funcs )) return; + if (__wine_init_unix_lib( gdi32_module, DLL_PROCESS_ATTACH, &callback_funcs, &font_funcs )) + return dpi;
load_system_bitmap_fonts(); load_file_system_fonts(); @@ -6155,7 +6165,7 @@ void font_init(void) name.Buffer = wine_font_mutexW; name.Length = name.MaximumLength = sizeof(wine_font_mutexW);
- if (NtCreateMutant( &mutex, MUTEX_ALL_ACCESS, &attr, FALSE ) < 0) return; + if (NtCreateMutant( &mutex, MUTEX_ALL_ACCESS, &attr, FALSE ) < 0) return dpi; NtWaitForSingleObject( mutex, FALSE, NULL );
wine_fonts_cache_key = reg_create_key( wine_fonts_key, cacheW, sizeof(cacheW), @@ -6181,6 +6191,7 @@ void font_init(void) load_system_links(); dump_gdi_font_list(); dump_gdi_font_subst(); + return dpi; }
/*********************************************************************** diff --git a/dlls/gdi32/gdiobj.c b/dlls/gdi32/gdiobj.c index 9c62e9e62d1..14cada9ee88 100644 --- a/dlls/gdi32/gdiobj.c +++ b/dlls/gdi32/gdiobj.c @@ -514,46 +514,6 @@ BOOL GDI_dec_ref_count( HGDIOBJ handle ) }
-/****************************************************************************** - * get_reg_dword - * - * Read a DWORD value from the registry - */ -static BOOL get_reg_dword(HKEY base, const WCHAR *key_name, const WCHAR *value_name, DWORD *value) -{ - HKEY key; - DWORD type, data, size = sizeof(data); - BOOL ret = FALSE; - - if (RegOpenKeyW(base, key_name, &key) == ERROR_SUCCESS) - { - if (RegQueryValueExW(key, value_name, NULL, &type, (void *)&data, &size) == ERROR_SUCCESS && - type == REG_DWORD) - { - *value = data; - ret = TRUE; - } - RegCloseKey(key); - } - return ret; -} - -/****************************************************************************** - * get_dpi - * - * get the dpi from the registry - */ -DWORD get_dpi(void) -{ - DWORD dpi; - - if (get_reg_dword(HKEY_CURRENT_USER, L"Control Panel\Desktop", L"LogPixels", &dpi)) - return dpi; - if (get_reg_dword(HKEY_CURRENT_CONFIG, L"Software\Fonts", L"LogPixels", &dpi)) - return dpi; - return 0; -} - /****************************************************************************** * get_system_dpi * @@ -580,16 +540,9 @@ static HFONT create_font( const LOGFONTW *deffont ) return NtGdiHfontCreate( &lf, sizeof(lf), 0, 0, NULL ); }
-static HFONT create_scaled_font( const LOGFONTW *deffont ) +static HFONT create_scaled_font( const LOGFONTW *deffont, unsigned int dpi ) { LOGFONTW lf; - static DWORD dpi; - - if (!dpi) - { - dpi = get_dpi(); - if (!dpi) dpi = 96; - }
lf = *deffont; lf.lfHeight = muldiv( lf.lfHeight, dpi, 96 ); @@ -634,7 +587,7 @@ HGDIOBJ get_stock_object( INT obj ) return entry_to_handle( handle_entry( ULongToHandle( obj + FIRST_GDI_HANDLE ))); }
-static void init_stock_objects(void) +static void init_stock_objects( unsigned int dpi ) { const struct DefaultFontInfo *deffonts; unsigned int i; @@ -655,7 +608,7 @@ static void init_stock_objects(void) create_pen( PS_NULL, 0, RGB(0,0,0) );
/* slot 9 is not used for non-scaled stock objects */ - create_scaled_font( &OEMFixedFont ); + create_scaled_font( &OEMFixedFont, dpi );
/* language-independent stock fonts */ create_font( &OEMFixedFont ); @@ -679,9 +632,9 @@ static void init_stock_objects(void)
assert( (HandleToULong( obj ) & 0xffff) == FIRST_GDI_HANDLE + DEFAULT_BITMAP );
- create_scaled_font( &deffonts->SystemFont ); - create_scaled_font( &deffonts->SystemFixedFont ); - create_scaled_font( &deffonts->DefaultGuiFont ); + create_scaled_font( &deffonts->SystemFont, dpi ); + create_scaled_font( &deffonts->SystemFixedFont, dpi ); + create_scaled_font( &deffonts->DefaultGuiFont, dpi );
/* clear the NOSYSTEM bit on all stock objects*/ for (i = 0; i < STOCK_LAST + 5; i++) @@ -699,14 +652,16 @@ static void init_stock_objects(void) */ BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved ) { + unsigned int dpi; + if (reason != DLL_PROCESS_ATTACH) return TRUE;
gdi32_module = inst; DisableThreadLibraryCalls( inst ); NtQuerySystemInformation( SystemBasicInformation, &system_info, sizeof(system_info), NULL ); set_gdi_shared(); - font_init(); - init_stock_objects(); + dpi = font_init(); + init_stock_objects( dpi ); return TRUE; }
diff --git a/dlls/gdi32/ntgdi_private.h b/dlls/gdi32/ntgdi_private.h index 595387e0aef..9f0f1d44240 100644 --- a/dlls/gdi32/ntgdi_private.h +++ b/dlls/gdi32/ntgdi_private.h @@ -338,7 +338,7 @@ struct font_callback_funcs const struct bitmap_font_size *size ); };
-extern void font_init(void) DECLSPEC_HIDDEN; +extern UINT font_init(void) DECLSPEC_HIDDEN;
/* opentype.c */
@@ -380,7 +380,6 @@ extern void GDI_CheckNotLock(void) DECLSPEC_HIDDEN; extern UINT GDI_get_ref_count( HGDIOBJ handle ) DECLSPEC_HIDDEN; extern HGDIOBJ GDI_inc_ref_count( HGDIOBJ handle ) DECLSPEC_HIDDEN; extern BOOL GDI_dec_ref_count( HGDIOBJ handle ) DECLSPEC_HIDDEN; -extern DWORD get_dpi(void) DECLSPEC_HIDDEN; extern DWORD get_system_dpi(void) DECLSPEC_HIDDEN; extern HGDIOBJ get_stock_object( INT obj ) DECLSPEC_HIDDEN; extern DWORD get_gdi_object_type( HGDIOBJ obj ) DECLSPEC_HIDDEN;