[1/2] gdi32: Use helper functions when loading font from cache.
Kusanagi Kouichi
slash at ac.auone-net.jp
Thu Mar 29 03:49:38 CDT 2012
Signed-off-by: Kusanagi Kouichi <slash at ac.auone-net.jp>
---
dlls/gdi32/freetype.c | 350 +++++++++++++++++++++++--------------------------
1 file changed, 165 insertions(+), 185 deletions(-)
diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c
index 8a077a9..f3313a5 100644
--- a/dlls/gdi32/freetype.c
+++ b/dlls/gdi32/freetype.c
@@ -1190,6 +1190,161 @@ static WCHAR *get_face_name(FT_Face ft_face, FT_UShort name_id, FT_UShort langua
return ret;
}
+static inline BOOL faces_equal( const Face *f1, const Face *f2 )
+{
+ if (strcmpiW( f1->StyleName, f2->StyleName )) return FALSE;
+ if (f1->scalable) return TRUE;
+ if (f2->size.y_ppem != f2->size.y_ppem) return FALSE;
+ return !memcmp( &f1->fs, &f2->fs, sizeof(f1->fs) );
+}
+
+static inline void free_face( Face *face )
+{
+ HeapFree( GetProcessHeap(), 0, face->file );
+ HeapFree( GetProcessHeap(), 0, face->StyleName );
+ HeapFree( GetProcessHeap(), 0, face->FullName );
+ HeapFree( GetProcessHeap(), 0, face->cached_enum_data );
+ HeapFree( GetProcessHeap(), 0, face );
+}
+
+static inline int style_order(const Face *face)
+{
+ switch (face->ntmFlags & (NTM_REGULAR | NTM_BOLD | NTM_ITALIC))
+ {
+ case NTM_REGULAR:
+ return 0;
+ case NTM_BOLD:
+ return 1;
+ case NTM_ITALIC:
+ return 2;
+ case NTM_BOLD | NTM_ITALIC:
+ return 3;
+ default:
+ WARN("Don't know how to order font %s %s with flags 0x%08x\n",
+ debugstr_w(face->family->FamilyName),
+ debugstr_w(face->StyleName),
+ face->ntmFlags);
+ return 9999;
+ }
+}
+
+static BOOL insert_face_in_family_list( Face *face, Family *family )
+{
+ Face *cursor;
+
+ LIST_FOR_EACH_ENTRY( cursor, &family->faces, Face, entry )
+ {
+ if (faces_equal( face, cursor ))
+ {
+ TRACE("Already loaded font %s %s original version is %lx, this version is %lx\n",
+ debugstr_w(family->FamilyName), debugstr_w(face->StyleName),
+ cursor->font_version, face->font_version);
+
+ if (face->font_version <= cursor->font_version)
+ {
+ TRACE("Original font is newer so skipping this one\n");
+ return FALSE;
+ }
+ else
+ {
+ TRACE("Replacing original with this one\n");
+ list_add_before( &cursor->entry, &face->entry );
+ face->family = family;
+ list_remove( &cursor->entry);
+ free_face( cursor );
+ return TRUE;
+ }
+ }
+
+ if (style_order( face ) < style_order( cursor )) break;
+ }
+
+ list_add_before( &cursor->entry, &face->entry );
+ face->family = family;
+ return TRUE;
+}
+
+static WCHAR *prepend_at(WCHAR *family)
+{
+ WCHAR *str;
+
+ if (!family)
+ return NULL;
+
+ str = HeapAlloc(GetProcessHeap(), 0, sizeof (WCHAR) * (strlenW(family) + 2));
+ str[0] = '@';
+ strcpyW(str + 1, family);
+ HeapFree(GetProcessHeap(), 0, family);
+ return str;
+}
+
+static void get_family_names( WCHAR **name, WCHAR **english, BOOL vertical )
+{
+ if (!*name)
+ {
+ *name = *english;
+ *english = NULL;
+ }
+ else if (*english && !strcmpiW( *name, *english ))
+ {
+ HeapFree( GetProcessHeap(), 0, *english );
+ *english = NULL;
+ }
+
+ if (vertical)
+ {
+ *name = prepend_at( *name );
+ *english = prepend_at( *english );
+ }
+}
+
+/****************************************************************
+ * NB This function stores the ptrs to the strings to save copying.
+ * Don't free them after calling.
+ */
+static Family *create_family( WCHAR *name, WCHAR *english_name )
+{
+ Family * const family = HeapAlloc( GetProcessHeap(), 0, sizeof(*family) );
+ family->FamilyName = name;
+ family->EnglishName = english_name;
+ list_init( &family->faces );
+ family->replacement = &family->faces;
+
+ return family;
+}
+
+static Family *get_family( WCHAR *name, WCHAR *english_name, BOOL vertical )
+{
+ Family *family;
+
+ get_family_names( &name, &english_name, vertical );
+
+ family = find_family_from_name( name );
+
+ if (!family)
+ {
+ family = create_family( name, english_name );
+ list_add_tail(&font_list, &family->entry);
+
+ if (english_name)
+ {
+ FontSubst *subst = HeapAlloc( GetProcessHeap(), 0, sizeof(*subst) );
+ subst->from.name = strdupW( english_name );
+ subst->from.charset = -1;
+ subst->to.name = strdupW( name );
+ subst->to.charset = -1;
+ add_font_subst( &font_subst_list, subst, 0 );
+ }
+ }
+ else
+ {
+ HeapFree( GetProcessHeap(), 0, name );
+ HeapFree( GetProcessHeap(), 0, english_name );
+ }
+
+ return family;
+}
+
static LONG reg_load_dword(HKEY hkey, const WCHAR *value, DWORD *data)
{
DWORD type, needed;
@@ -1222,7 +1377,6 @@ static void load_face(HKEY hkey_face, WCHAR *face_name, Family *family)
RegQueryValueExA(hkey_face, "File Name", NULL, NULL, (BYTE*)face->file, &needed);
face->StyleName = strdupW(face_name);
- face->family = family;
face->vertical = (family->FamilyName[0] == '@');
if(RegQueryValueExW(hkey_face, face_full_name_value, NULL, NULL, NULL, &needed) == ERROR_SUCCESS)
@@ -1272,10 +1426,7 @@ static void load_face(HKEY hkey_face, WCHAR *face_name, Family *family)
face->fs.fsUsb[0], face->fs.fsUsb[1],
face->fs.fsUsb[2], face->fs.fsUsb[3]);
- if(!italic && !bold)
- list_add_head(&family->faces, &face->entry);
- else
- list_add_tail(&family->faces, &face->entry);
+ insert_face_in_family_list(face, family);
TRACE("Added font %s %s\n", debugstr_w(family->FamilyName), debugstr_w(face->StyleName));
}
@@ -1330,22 +1481,7 @@ static void load_font_list_from_cache(HKEY hkey_font_cache)
RegQueryValueExW(hkey_family, english_name_value, NULL, NULL, (BYTE*)english_family, &size);
}
- family = HeapAlloc(GetProcessHeap(), 0, sizeof(*family));
- family->FamilyName = strdupW(family_name);
- family->EnglishName = english_family;
- list_init(&family->faces);
- family->replacement = &family->faces;
- list_add_tail(&font_list, &family->entry);
-
- if(english_family)
- {
- FontSubst *subst = HeapAlloc(GetProcessHeap(), 0, sizeof(*subst));
- subst->from.name = strdupW(english_family);
- subst->from.charset = -1;
- subst->to.name = strdupW(family_name);
- subst->to.charset = -1;
- add_font_subst(&font_subst_list, subst, 0);
- }
+ family = get_family(strdupW(family_name), english_family, FALSE);
RegQueryInfoKeyW(hkey_family, NULL, NULL, NULL, NULL, &max_face_key_len, NULL, NULL,
NULL, NULL, NULL, NULL);
@@ -1443,116 +1579,6 @@ static void add_face_to_cache(Face *face)
RegCloseKey(hkey_font_cache);
}
-static inline int TestStyles(DWORD flags, DWORD styles)
-{
- return (flags & styles) == styles;
-}
-
-static inline int style_order(Face *face)
-{
- if (TestStyles(face->ntmFlags, NTM_BOLD | NTM_ITALIC))
- return 3;
- if (TestStyles(face->ntmFlags, NTM_ITALIC))
- return 2;
- if (TestStyles(face->ntmFlags, NTM_BOLD))
- return 1;
- if (TestStyles(face->ntmFlags, NTM_REGULAR))
- return 0;
-
- WARN("Don't know how to order font %s %s with flags 0x%08x\n",
- debugstr_w(face->family->FamilyName),
- debugstr_w(face->StyleName),
- face->ntmFlags);
-
- return 9999;
-}
-
-static WCHAR *prepend_at(WCHAR *family)
-{
- WCHAR *str;
-
- if (!family)
- return NULL;
-
- str = HeapAlloc(GetProcessHeap(), 0, sizeof (WCHAR) * (strlenW(family) + 2));
- str[0] = '@';
- strcpyW(str + 1, family);
- HeapFree(GetProcessHeap(), 0, family);
- return str;
-}
-
-static void get_family_names( FT_Face ft_face, WCHAR **name, WCHAR **english, BOOL vertical )
-{
- *english = get_face_name( ft_face, TT_NAME_ID_FONT_FAMILY, TT_MS_LANGID_ENGLISH_UNITED_STATES );
- if (!*english) *english = towstr( CP_ACP, ft_face->family_name );
-
- *name = get_face_name( ft_face, TT_NAME_ID_FONT_FAMILY, GetUserDefaultLCID() );
- if (!*name)
- {
- *name = *english;
- *english = NULL;
- }
- else if (!strcmpiW( *name, *english ))
- {
- HeapFree( GetProcessHeap(), 0, *english );
- *english = NULL;
- }
-
- if (vertical)
- {
- *name = prepend_at( *name );
- *english = prepend_at( *english );
- }
-}
-
-/****************************************************************
- * NB This function stores the ptrs to the strings to save copying.
- * Don't free them after calling.
- */
-static Family *create_family( WCHAR *name, WCHAR *english_name )
-{
- Family *family = HeapAlloc( GetProcessHeap(), 0, sizeof(*family) );
- family->FamilyName = name;
- family->EnglishName = english_name;
- list_init( &family->faces );
- family->replacement = &family->faces;
-
- return family;
-}
-
-static Family *get_family( FT_Face ft_face, BOOL vertical )
-{
- Family *family;
- WCHAR *name, *english_name;
-
- get_family_names( ft_face, &name, &english_name, vertical );
-
- family = find_family_from_name( name );
-
- if (!family)
- {
- family = create_family( name, english_name );
- list_add_tail( &font_list, &family->entry );
-
- if (english_name)
- {
- FontSubst *subst = HeapAlloc( GetProcessHeap(), 0, sizeof(*subst) );
- subst->from.name = strdupW( english_name );
- subst->from.charset = -1;
- subst->to.name = strdupW( name );
- subst->to.charset = -1;
- add_font_subst( &font_subst_list, subst, 0 );
- }
- }
- else
- {
- HeapFree( GetProcessHeap(), 0, name );
- HeapFree( GetProcessHeap(), 0, english_name );
- }
-
- return family;
-}
-
static inline FT_Fixed get_font_version( FT_Face ft_face )
{
FT_Fixed version = 0;
@@ -1653,15 +1679,6 @@ static inline void get_fontsig( FT_Face ft_face, FONTSIGNATURE *fs )
}
}
-static inline void free_face( Face *face )
-{
- HeapFree( GetProcessHeap(), 0, face->file );
- HeapFree( GetProcessHeap(), 0, face->StyleName );
- HeapFree( GetProcessHeap(), 0, face->FullName );
- HeapFree( GetProcessHeap(), 0, face->cached_enum_data );
- HeapFree( GetProcessHeap(), 0, face );
-}
-
#define ADDFONT_EXTERNAL_FONT 0x01
#define ADDFONT_FORCE_BITMAP 0x02
#define ADDFONT_ADD_TO_CACHE 0x04
@@ -1724,58 +1741,21 @@ static Face *create_face( FT_Face ft_face, FT_Long face_index, const char *file,
return face;
}
-static inline BOOL faces_equal( Face *f1, Face *f2 )
-{
- if (strcmpiW( f1->StyleName, f2->StyleName )) return FALSE;
- if (f1->scalable) return TRUE;
- if (f2->size.y_ppem != f2->size.y_ppem) return FALSE;
- return !memcmp( &f1->fs, &f2->fs, sizeof(f1->fs) );
-}
-
-static BOOL insert_face_in_family_list( Face *face, Family *family )
-{
- Face *cursor;
-
- LIST_FOR_EACH_ENTRY( cursor, &family->faces, Face, entry )
- {
- if (faces_equal( face, cursor ))
- {
- TRACE("Already loaded font %s %s original version is %lx, this version is %lx\n",
- debugstr_w(family->FamilyName), debugstr_w(face->StyleName),
- cursor->font_version, face->font_version);
-
- if (face->font_version <= cursor->font_version)
- {
- TRACE("Original font is newer so skipping this one\n");
- return FALSE;
- }
- else
- {
- TRACE("Replacing original with this one\n");
- list_add_before( &cursor->entry, &face->entry );
- face->family = family;
- list_remove( &cursor->entry);
- free_face( cursor );
- return TRUE;
- }
- }
-
- if (style_order( face ) < style_order( cursor )) break;
- }
-
- list_add_before( &cursor->entry, &face->entry );
- face->family = family;
- return TRUE;
-}
-
static void AddFaceToList(FT_Face ft_face, const char *file, void *font_data_ptr, DWORD font_data_size,
FT_Long face_index, DWORD flags, BOOL vertical)
{
Face *face;
+ WCHAR *family_name, *english_family;
Family *family;
face = create_face( ft_face, face_index, file, font_data_ptr, font_data_size, flags, vertical );
- family = get_family( ft_face, vertical );
+
+ family_name = get_face_name( ft_face, TT_NAME_ID_FONT_FAMILY, GetUserDefaultLCID() );
+ english_family = get_face_name( ft_face, TT_NAME_ID_FONT_FAMILY, TT_MS_LANGID_ENGLISH_UNITED_STATES );
+ if (!english_family)
+ english_family = towstr( CP_ACP, ft_face->family_name );
+ family = get_family( family_name, english_family, vertical );
+
if (!insert_face_in_family_list( face, family ))
{
free_face( face );
--
1.7.9.5
More information about the wine-patches
mailing list