Commit 2dfb0989 authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

gdi32: Try to read the dpi from the user key first.

parent d74348f9
......@@ -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;
......
......@@ -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;
......
......@@ -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 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment