gdi32: Allocate cache for face enumeration data only when necessary.

This commit is contained in:
Dmitry Timoshkov 2008-01-16 14:46:24 +08:00 committed by Alexandre Julliard
parent ced64861f5
commit ec4a46f93a

View File

@ -242,6 +242,13 @@ typedef struct {
FT_Pos size, x_ppem, y_ppem; FT_Pos size, x_ppem, y_ppem;
} My_FT_Bitmap_Size; } My_FT_Bitmap_Size;
struct enum_data
{
ENUMLOGFONTEXW elf;
NEWTEXTMETRICEXW ntm;
DWORD type;
};
typedef struct tagFace { typedef struct tagFace {
struct list entry; struct list entry;
WCHAR *StyleName; WCHAR *StyleName;
@ -260,10 +267,7 @@ typedef struct tagFace {
BOOL external; /* TRUE if we should manually add this font to the registry */ BOOL external; /* TRUE if we should manually add this font to the registry */
struct tagFamily *family; struct tagFamily *family;
/* Cached data for Enum */ /* Cached data for Enum */
BOOL cache_valid; struct enum_data *cached_enum_data;
ENUMLOGFONTEXW elf;
NEWTEXTMETRICEXW ntm;
DWORD type;
} Face; } Face;
typedef struct tagFamily { typedef struct tagFamily {
@ -1239,7 +1243,7 @@ static INT AddFontToList(const char *file, void *font_data_ptr, DWORD font_data_
} }
} }
face = HeapAlloc(GetProcessHeap(), 0, sizeof(*face)); face = HeapAlloc(GetProcessHeap(), 0, sizeof(*face));
face->cache_valid = FALSE; face->cached_enum_data = NULL;
list_add_tail(&family->faces, &face->entry); list_add_tail(&family->faces, &face->entry);
face->StyleName = StyleW; face->StyleName = StyleW;
if (file) if (file)
@ -3290,12 +3294,12 @@ static void GetEnumStructs(Face *face, LPENUMLOGFONTEXW pelf,
GdiFont *font; GdiFont *font;
LONG width, height; LONG width, height;
if (face->cache_valid) if (face->cached_enum_data)
{ {
TRACE("Cached\n"); TRACE("Cached\n");
memcpy(pelf,&face->elf,sizeof(ENUMLOGFONTEXW)); memcpy(pelf, &face->cached_enum_data->elf, sizeof(ENUMLOGFONTEXW));
memcpy(pntm,&face->ntm,sizeof(NEWTEXTMETRICEXW)); memcpy(pntm, &face->cached_enum_data->ntm, sizeof(NEWTEXTMETRICEXW));
*ptype = face->type; *ptype = face->cached_enum_data->type;
return; return;
} }
@ -3374,10 +3378,13 @@ static void GetEnumStructs(Face *face, LPENUMLOGFONTEXW pelf,
if(!(pntm->ntmTm.tmPitchAndFamily & TMPF_VECTOR)) if(!(pntm->ntmTm.tmPitchAndFamily & TMPF_VECTOR))
*ptype |= RASTER_FONTTYPE; *ptype |= RASTER_FONTTYPE;
memcpy(&face->elf,pelf,sizeof(ENUMLOGFONTEXW)); face->cached_enum_data = HeapAlloc(GetProcessHeap(), 0, sizeof(*face->cached_enum_data));
memcpy(&face->ntm,pntm,sizeof(NEWTEXTMETRICEXW)); if (face->cached_enum_data)
face->type = *ptype; {
face->cache_valid = TRUE; memcpy(&face->cached_enum_data->elf, pelf, sizeof(ENUMLOGFONTEXW));
memcpy(&face->cached_enum_data->ntm, pntm, sizeof(NEWTEXTMETRICEXW));
face->cached_enum_data->type = *ptype;
}
free_font(font); free_font(font);
} }