Commit c1f8a0bf authored by Alexandre Julliard's avatar Alexandre Julliard

gdi32: Avoid some redundant registry calls while loading the font cache.

parent 3d013afe
......@@ -1298,11 +1298,15 @@ static Family *create_family( WCHAR *name, WCHAR *english_name )
static LONG reg_load_dword(HKEY hkey, const WCHAR *value, DWORD *data)
{
DWORD type, needed;
LONG r = RegQueryValueExW(hkey, value, NULL, &type, NULL, &needed);
if(r != ERROR_SUCCESS) return r;
if(type != REG_DWORD || needed != sizeof(DWORD)) return ERROR_BAD_CONFIGURATION;
return RegQueryValueExW(hkey, value, NULL, &type, (BYTE*)data, &needed);
DWORD type, size = sizeof(DWORD);
if (RegQueryValueExW(hkey, value, NULL, &type, (BYTE *)data, &size) ||
type != REG_DWORD || size != sizeof(DWORD))
{
*data = 0;
return ERROR_BAD_CONFIGURATION;
}
return ERROR_SUCCESS;
}
static inline LONG reg_save_dword(HKEY hkey, const WCHAR *value, DWORD data)
......@@ -1310,30 +1314,26 @@ static inline LONG reg_save_dword(HKEY hkey, const WCHAR *value, DWORD data)
return RegSetValueExW(hkey, value, 0, REG_DWORD, (BYTE*)&data, sizeof(DWORD));
}
static void load_face(HKEY hkey_face, WCHAR *face_name, Family *family)
static void load_face(HKEY hkey_face, WCHAR *face_name, Family *family, void *buffer, DWORD buffer_size)
{
DWORD needed;
DWORD num_strikes, max_strike_key_len;
DWORD needed, strike_index = 0;
HKEY hkey_strike;
/* If we have a File Name key then this is a real font, not just the parent
key of a bunch of non-scalable strikes */
if(RegQueryValueExA(hkey_face, "File Name", NULL, NULL, NULL, &needed) == ERROR_SUCCESS)
needed = buffer_size;
if(RegQueryValueExA(hkey_face, "File Name", NULL, NULL, buffer, &needed) == ERROR_SUCCESS)
{
Face *face;
face = HeapAlloc(GetProcessHeap(), 0, sizeof(*face));
face->cached_enum_data = NULL;
face->file = HeapAlloc(GetProcessHeap(), 0, needed);
RegQueryValueExA(hkey_face, "File Name", NULL, NULL, (BYTE*)face->file, &needed);
face->file = strdupA( buffer );
face->StyleName = strdupW(face_name);
if(RegQueryValueExW(hkey_face, face_full_name_value, NULL, NULL, NULL, &needed) == ERROR_SUCCESS)
{
WCHAR *fullName = HeapAlloc(GetProcessHeap(), 0, needed);
RegQueryValueExW(hkey_face, face_full_name_value, NULL, NULL, (BYTE*)fullName, &needed);
face->FullName = fullName;
}
needed = buffer_size;
if(RegQueryValueExW(hkey_face, face_full_name_value, NULL, NULL, buffer, &needed) == ERROR_SUCCESS)
face->FullName = strdupW( buffer );
else
face->FullName = NULL;
......@@ -1374,57 +1374,41 @@ static void load_face(HKEY hkey_face, WCHAR *face_name, Family *family)
TRACE("Added font %s %s\n", debugstr_w(family->FamilyName), debugstr_w(face->StyleName));
}
/* do we have any bitmap strikes? */
RegQueryInfoKeyW(hkey_face, NULL, NULL, NULL, &num_strikes, &max_strike_key_len, NULL, NULL,
NULL, NULL, NULL, NULL);
if(num_strikes != 0)
{
WCHAR strike_name[10];
DWORD strike_index = 0;
/* load bitmap strikes */
needed = sizeof(strike_name) / sizeof(WCHAR);
while(RegEnumKeyExW(hkey_face, strike_index++, strike_name, &needed,
NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
needed = buffer_size;
while (!RegEnumKeyExW(hkey_face, strike_index++, buffer, &needed, NULL, NULL, NULL, NULL))
{
if (!RegOpenKeyExW(hkey_face, buffer, 0, KEY_ALL_ACCESS, &hkey_strike))
{
HKEY hkey_strike;
RegOpenKeyExW(hkey_face, strike_name, 0, KEY_ALL_ACCESS, &hkey_strike);
load_face(hkey_strike, face_name, family);
load_face(hkey_strike, face_name, family, buffer, buffer_size);
RegCloseKey(hkey_strike);
needed = sizeof(strike_name) / sizeof(WCHAR);
}
needed = buffer_size;
}
}
static void load_font_list_from_cache(HKEY hkey_font_cache)
{
DWORD max_family_key_len, size;
WCHAR *family_name;
DWORD family_index = 0;
DWORD size, family_index = 0;
Family *family;
HKEY hkey_family;
WCHAR buffer[4096];
RegQueryInfoKeyW(hkey_font_cache, NULL, NULL, NULL, NULL, &max_family_key_len, NULL, NULL,
NULL, NULL, NULL, NULL);
family_name = HeapAlloc(GetProcessHeap(), 0, (max_family_key_len + 1) * sizeof(WCHAR));
size = max_family_key_len + 1;
while(RegEnumKeyExW(hkey_font_cache, family_index++, family_name, &size,
NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
size = sizeof(buffer);
while (!RegEnumKeyExW(hkey_font_cache, family_index++, buffer, &size, NULL, NULL, NULL, NULL))
{
WCHAR *english_family = NULL;
WCHAR *family_name = strdupW( buffer );
DWORD face_index = 0;
WCHAR *face_name;
DWORD max_face_key_len;
RegOpenKeyExW(hkey_font_cache, family_name, 0, KEY_ALL_ACCESS, &hkey_family);
TRACE("opened family key %s\n", debugstr_w(family_name));
if(RegQueryValueExW(hkey_family, english_name_value, NULL, NULL, NULL, &size) == ERROR_SUCCESS)
{
english_family = HeapAlloc(GetProcessHeap(), 0, size);
RegQueryValueExW(hkey_family, english_name_value, NULL, NULL, (BYTE*)english_family, &size);
}
size = sizeof(buffer);
if (!RegQueryValueExW(hkey_family, english_name_value, NULL, NULL, (BYTE *)buffer, &size))
english_family = strdupW( buffer );
family = create_family(strdupW(family_name), english_family);
family = create_family(family_name, english_family);
list_add_tail(&font_list, &family->entry);
if(english_family)
......@@ -1437,27 +1421,23 @@ static void load_font_list_from_cache(HKEY hkey_font_cache)
add_font_subst(&font_subst_list, subst, 0);
}
RegQueryInfoKeyW(hkey_family, NULL, NULL, NULL, NULL, &max_face_key_len, NULL, NULL,
NULL, NULL, NULL, NULL);
face_name = HeapAlloc(GetProcessHeap(), 0, (max_face_key_len + 1) * sizeof(WCHAR));
size = max_face_key_len + 1;
while(RegEnumKeyExW(hkey_family, face_index++, face_name, &size,
NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
size = sizeof(buffer);
while (!RegEnumKeyExW(hkey_family, face_index++, buffer, &size, NULL, NULL, NULL, NULL))
{
WCHAR *face_name = strdupW( buffer );
HKEY hkey_face;
RegOpenKeyExW(hkey_family, face_name, 0, KEY_ALL_ACCESS, &hkey_face);
load_face(hkey_face, face_name, family);
RegCloseKey(hkey_face);
size = max_face_key_len + 1;
if (!RegOpenKeyExW(hkey_family, face_name, 0, KEY_ALL_ACCESS, &hkey_face))
{
load_face(hkey_face, face_name, family, buffer, sizeof(buffer));
RegCloseKey(hkey_face);
}
HeapFree( GetProcessHeap(), 0, face_name );
size = sizeof(buffer);
}
HeapFree(GetProcessHeap(), 0, face_name);
RegCloseKey(hkey_family);
size = max_family_key_len + 1;
size = sizeof(buffer);
}
HeapFree(GetProcessHeap(), 0, family_name);
}
static LONG create_font_cache_key(HKEY *hkey, DWORD *disposition)
......
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