[PATCH] Factor out the logic to compute the family.

Jeremy White jwhite at codeweavers.com
Thu Oct 9 12:21:12 CDT 2008


---
 dlls/gdi32/freetype.c |   92 ++++++++++++++++++++++++++++---------------------
 1 files changed, 53 insertions(+), 39 deletions(-)

diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c
index 55288a7..02adeea 100644
--- a/dlls/gdi32/freetype.c
+++ b/dlls/gdi32/freetype.c
@@ -1263,16 +1263,65 @@ static INT GetFtFace(const char *file, void *font_data_ptr, DWORD font_data_size
 
 }
 
+static Family *GetFamily(FT_Face ft_face, char *family_name, char *fake_family)
+{
+    DWORD len;
+    WCHAR *english_family, *localised_family;
+    Family *family;
+    struct list *family_elem_ptr;
+
+    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 && !strcmpW(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(!strcmpW(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);
+
+    return family;
+}
+
+
 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;
+    WCHAR *StyleW;
     DWORD len;
     Family *family;
     Face *face;
-    struct list *family_elem_ptr, *face_elem_ptr;
+    struct list *face_elem_ptr;
     FT_Long face_index = 0, num_faces;
 #ifdef HAVE_FREETYPE_FTWINFNT_H
     FT_WinFNT_HeaderRec winfnt_header;
@@ -1315,6 +1364,7 @@ static INT AddFontToList(const char *file, void *font_data_ptr, DWORD font_data_
 
         if (target_family)
         {
+            WCHAR *localised_family;
             localised_family = get_familyname(ft_face);
             if (localised_family && strcmpiW(localised_family,target_family)!=0)
             {
@@ -1338,43 +1388,7 @@ static INT AddFontToList(const char *file, void *font_data_ptr, DWORD font_data_
             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 && !strcmpW(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(!strcmpW(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);
+            family = GetFamily(ft_face, family_name, fake_family);
 
             len = MultiByteToWideChar(CP_ACP, 0, ft_face->style_name, -1, NULL, 0);
             StyleW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
-- 
1.5.3.6


--------------090801060605020700020201
Content-Type: text/x-patch;
 name="0003-Simplify-the-setting-of-a-loop-end-condition.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename*0="0003-Simplify-the-setting-of-a-loop-end-condition.patch"



More information about the wine-devel mailing list