[1/3] gdi32: Make AddFontToList skip adding a face into global lists if the font is not supposed to be enumerated. Take 2.

Dmitry Timoshkov dmitry at codeweavers.com
Wed Oct 27 06:33:42 CDT 2010


---
 dlls/gdi32/freetype.c |  160 +++++++++++++++++++++++++++----------------------
 1 files changed, 89 insertions(+), 71 deletions(-)

diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c
index e2db1aa..52eb6aa 100644
--- a/dlls/gdi32/freetype.c
+++ b/dlls/gdi32/freetype.c
@@ -1207,14 +1207,15 @@ static void AddFaceToFamily(Face *face, Family *family)
 
 #define ADDFONT_EXTERNAL_FONT 0x01
 #define ADDFONT_FORCE_BITMAP  0x02
-static INT AddFontToList(const char *file, void *font_data_ptr, DWORD font_data_size, char *fake_family, const WCHAR *target_family, DWORD flags)
+#define ADDFONT_HIDDEN        0x04
+static INT AddFontToList(const char *file, void *font_data_ptr, DWORD font_data_size,
+                         char *fake_family, const WCHAR *target_family, DWORD flags)
 {
     FT_Face ft_face;
     TT_OS2 *pOS2;
     TT_Header *pHeader = NULL;
     WCHAR *english_family, *localised_family, *StyleW;
-    DWORD len;
-    Family *family;
+    Family *family = NULL;
     Face *face;
     struct list *family_elem_ptr, *face_elem_ptr;
     FT_Error err;
@@ -1341,48 +1342,11 @@ static INT AddFontToList(const char *file, void *font_data_ptr, DWORD font_data_
         do {
             My_FT_Bitmap_Size *size = NULL;
             FT_ULong tmp_size;
+            DWORD len;
 
             if(!FT_IS_SCALABLE(ft_face))
                 size = (My_FT_Bitmap_Size *)ft_face->available_sizes + bitmap_num;
 
-            len = MultiByteToWideChar(CP_ACP, 0, family_name, -1, NULL, 0);
-            english_family = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
-            MultiByteToWideChar(CP_ACP, 0, family_name, -1, english_family, len);
-
-            localised_family = NULL;
-            if(!fake_family) {
-                localised_family = get_familyname(ft_face);
-                if(localised_family && !strcmpiW(localised_family, english_family)) {
-                    HeapFree(GetProcessHeap(), 0, localised_family);
-                    localised_family = NULL;
-                }
-            }
-
-            family = NULL;
-            LIST_FOR_EACH(family_elem_ptr, &font_list) {
-                family = LIST_ENTRY(family_elem_ptr, Family, entry);
-                if(!strcmpiW(family->FamilyName, localised_family ? localised_family : english_family))
-                    break;
-                family = NULL;
-            }
-            if(!family) {
-                family = HeapAlloc(GetProcessHeap(), 0, sizeof(*family));
-                family->FamilyName = strdupW(localised_family ? localised_family : english_family);
-                list_init(&family->faces);
-                list_add_tail(&font_list, &family->entry);
-
-                if(localised_family) {
-                    FontSubst *subst = HeapAlloc(GetProcessHeap(), 0, sizeof(*subst));
-                    subst->from.name = strdupW(english_family);
-                    subst->from.charset = -1;
-                    subst->to.name = strdupW(localised_family);
-                    subst->to.charset = -1;
-                    add_font_subst(&font_subst_list, subst, 0);
-                }
-            }
-            HeapFree(GetProcessHeap(), 0, localised_family);
-            HeapFree(GetProcessHeap(), 0, english_family);
-
             len = MultiByteToWideChar(CP_ACP, 0, ft_face->style_name, -1, NULL, 0);
             StyleW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
             MultiByteToWideChar(CP_ACP, 0, ft_face->style_name, -1, StyleW, len);
@@ -1418,34 +1382,86 @@ static INT AddFontToList(const char *file, void *font_data_ptr, DWORD font_data_
             }
 #endif
 
-            face_elem_ptr = list_head(&family->faces);
-            while(face_elem_ptr) {
-                face = LIST_ENTRY(face_elem_ptr, Face, entry);
-                face_elem_ptr = list_next(&family->faces, face_elem_ptr);
-                if(!strcmpiW(face->StyleName, StyleW) &&
-                   (FT_IS_SCALABLE(ft_face) || ((size->y_ppem == face->size.y_ppem) && !memcmp(&fs, &face->fs, sizeof(fs)) ))) {
-                    TRACE("Already loaded font %s %s original version is %lx, this version is %lx\n",
-                          debugstr_w(family->FamilyName), debugstr_w(StyleW),
-                          face->font_version,  pHeader ? pHeader->Font_Revision : 0);
-
-                    if(fake_family) {
-                        TRACE("This font is a replacement but the original really exists, so we'll skip the replacement\n");
-                        HeapFree(GetProcessHeap(), 0, StyleW);
-                        pFT_Done_Face(ft_face);
-                        return 1;
+            if (!(flags & ADDFONT_HIDDEN))
+            {
+                len = MultiByteToWideChar(CP_ACP, 0, family_name, -1, NULL, 0);
+                english_family = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
+                MultiByteToWideChar(CP_ACP, 0, family_name, -1, english_family, len);
+
+                localised_family = NULL;
+                if (!fake_family)
+                {
+                    localised_family = get_familyname(ft_face);
+                    if (localised_family && !strcmpiW(localised_family, english_family))
+                    {
+                        HeapFree(GetProcessHeap(), 0, localised_family);
+                        localised_family = NULL;
                     }
-                    if(!pHeader || pHeader->Font_Revision <= face->font_version) {
-                        TRACE("Original font is newer so skipping this one\n");
-                        HeapFree(GetProcessHeap(), 0, StyleW);
-                        pFT_Done_Face(ft_face);
-                        return 1;
-                    } else {
-                        TRACE("Replacing original with this one\n");
-                        list_remove(&face->entry);
-                        HeapFree(GetProcessHeap(), 0, face->file);
-                        HeapFree(GetProcessHeap(), 0, face->StyleName);
-                        HeapFree(GetProcessHeap(), 0, face);
+                }
+
+                family = NULL;
+                LIST_FOR_EACH(family_elem_ptr, &font_list)
+                {
+                    family = LIST_ENTRY(family_elem_ptr, Family, entry);
+                    if(!strcmpiW(family->FamilyName, localised_family ? localised_family : english_family))
                         break;
+                    family = NULL;
+                }
+                if (!family)
+                {
+                    family = HeapAlloc(GetProcessHeap(), 0, sizeof(*family));
+                    family->FamilyName = strdupW(localised_family ? localised_family : english_family);
+                    list_init(&family->faces);
+                    list_add_tail(&font_list, &family->entry);
+
+                    if (localised_family)
+                    {
+                        FontSubst *subst = HeapAlloc(GetProcessHeap(), 0, sizeof(*subst));
+                        subst->from.name = strdupW(english_family);
+                        subst->from.charset = -1;
+                        subst->to.name = strdupW(localised_family);
+                        subst->to.charset = -1;
+                        add_font_subst(&font_subst_list, subst, 0);
+                    }
+                }
+                HeapFree(GetProcessHeap(), 0, localised_family);
+                HeapFree(GetProcessHeap(), 0, english_family);
+
+                face_elem_ptr = list_head(&family->faces);
+                while(face_elem_ptr)
+                {
+                    face = LIST_ENTRY(face_elem_ptr, Face, entry);
+                    face_elem_ptr = list_next(&family->faces, face_elem_ptr);
+                    if (!strcmpiW(face->StyleName, StyleW) &&
+                       (FT_IS_SCALABLE(ft_face) || ((size->y_ppem == face->size.y_ppem) && !memcmp(&fs, &face->fs, sizeof(fs)) )))
+                    {
+                        TRACE("Already loaded font %s %s original version is %lx, this version is %lx\n",
+                              debugstr_w(family->FamilyName), debugstr_w(StyleW),
+                              face->font_version,  pHeader ? pHeader->Font_Revision : 0);
+
+                        if (fake_family)
+                        {
+                            TRACE("This font is a replacement but the original really exists, so we'll skip the replacement\n");
+                            HeapFree(GetProcessHeap(), 0, StyleW);
+                            pFT_Done_Face(ft_face);
+                            return 1;
+                        }
+                        if (!pHeader || pHeader->Font_Revision <= face->font_version)
+                        {
+                            TRACE("Original font is newer so skipping this one\n");
+                            HeapFree(GetProcessHeap(), 0, StyleW);
+                            pFT_Done_Face(ft_face);
+                            return 1;
+                        }
+                        else
+                        {
+                            TRACE("Replacing original with this one\n");
+                            list_remove(&face->entry);
+                            HeapFree(GetProcessHeap(), 0, face->file);
+                            HeapFree(GetProcessHeap(), 0, face->StyleName);
+                            HeapFree(GetProcessHeap(), 0, face);
+                            break;
+                        }
                     }
                 }
             }
@@ -1523,11 +1539,13 @@ static INT AddFontToList(const char *file, void *font_data_ptr, DWORD font_data_
                 }
             }
 
-            if (!(face->fs.fsCsb[0] & FS_SYMBOL))
-                have_installed_roman_font = TRUE;
-
-            AddFaceToFamily(face, family);
+            if (!(flags & ADDFONT_HIDDEN))
+            {
+                if (!(face->fs.fsCsb[0] & FS_SYMBOL))
+                    have_installed_roman_font = TRUE;
 
+                AddFaceToFamily(face, family);
+            }
         } while(!FT_IS_SCALABLE(ft_face) && ++bitmap_num < ft_face->num_fixed_sizes);
 
 	num_faces = ft_face->num_faces;
-- 
1.7.0.6




More information about the wine-patches mailing list