[PATCH] Move the FreeType face creation logic to a separate function.

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


---
 dlls/gdi32/freetype.c |  146 +++++++++++++++++++++++++++----------------------
 1 files changed, 80 insertions(+), 66 deletions(-)

diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c
index 0ab4c7a..55288a7 100644
--- a/dlls/gdi32/freetype.c
+++ b/dlls/gdi32/freetype.c
@@ -1186,6 +1186,83 @@ static void AddFaceToFamily(Face *face, Family *family)
 
 #define ADDFONT_EXTERNAL_FONT 0x01
 #define ADDFONT_FORCE_BITMAP  0x02
+static INT GetFtFace(const char *file, void *font_data_ptr, DWORD font_data_size, char *fake_family, DWORD flags, FT_Long face_index, FT_Face *ft_face)
+{
+    FT_Error err;
+    TT_OS2 *pOS2;
+
+    if (file)
+    {
+        TRACE("Loading font file %s index %ld\n", debugstr_a(file), face_index);
+        err = pFT_New_Face(library, file, face_index, ft_face);
+    } else
+    {
+        TRACE("Loading font from ptr %p size %d, index %ld\n", font_data_ptr, font_data_size, face_index);
+        err = pFT_New_Memory_Face(library, font_data_ptr, font_data_size, face_index, ft_face);
+    }
+
+    if(err != 0) {
+        WARN("Unable to load font %s/%p err = %x\n", debugstr_a(file), font_data_ptr, err);
+        return 0;
+    }
+
+    if(!FT_IS_SFNT((*ft_face)) && (FT_IS_SCALABLE((*ft_face)) || !(flags & ADDFONT_FORCE_BITMAP))) { /* for now we'll accept TT/OT or bitmap fonts*/
+        WARN("Ignoring font %s/%p\n", debugstr_a(file), font_data_ptr);
+        pFT_Done_Face(*ft_face);
+        return 0;
+    }
+
+    /* There are too many bugs in FreeType < 2.1.9 for bitmap font support */
+    if(!FT_IS_SCALABLE((*ft_face)) && FT_SimpleVersion < ((2 << 16) | (1 << 8) | (9 << 0))) {
+        WARN("FreeType version < 2.1.9, skipping bitmap font %s/%p\n", debugstr_a(file), font_data_ptr);
+        pFT_Done_Face(*ft_face);
+        return 0;
+    }
+
+    if(FT_IS_SFNT((*ft_face)))
+    {
+        if(!(pOS2 = pFT_Get_Sfnt_Table(*ft_face, ft_sfnt_os2)) ||
+           !pFT_Get_Sfnt_Table(*ft_face, ft_sfnt_hhea) ||
+           !pFT_Get_Sfnt_Table(*ft_face, ft_sfnt_head))
+        {
+            TRACE("Font %s/%p lacks either an OS2, HHEA or HEAD table.\n"
+                  "Skipping this font.\n", debugstr_a(file), font_data_ptr);
+            pFT_Done_Face(*ft_face);
+            return 0;
+        }
+
+        /* Wine uses ttfs as an intermediate step in building its bitmap fonts;
+           we don't want to load these. */
+        if(!memcmp(pOS2->achVendID, "Wine", sizeof(pOS2->achVendID)))
+        {
+            FT_ULong len = 0;
+
+            if(!load_sfnt_table(*ft_face, FT_MAKE_TAG('E','B','S','C'), 0, NULL, &len))
+            {
+                TRACE("Skipping Wine bitmap-only TrueType font %s\n", debugstr_a(file));
+                pFT_Done_Face(*ft_face);
+                return 0;
+            }
+        }
+    }
+
+    if(!(*ft_face)->family_name || !(*ft_face)->style_name) {
+        TRACE("Font %s/%p lacks either a family or style name\n", debugstr_a(file), font_data_ptr);
+        pFT_Done_Face(*ft_face);
+        return 0;
+    }
+
+    if((*ft_face)->family_name[0] == '.') /* Ignore fonts with names beginning with a dot */
+    {
+        TRACE("Ignoring %s since its family name begins with a dot\n", debugstr_a(file));
+        pFT_Done_Face(*ft_face);
+        return 0;
+    }
+
+    return 1;
+
+}
+
 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;
@@ -1196,7 +1273,6 @@ static INT AddFontToList(const char *file, void *font_data_ptr, DWORD font_data_
     Family *family;
     Face *face;
     struct list *family_elem_ptr, *face_elem_ptr;
-    FT_Error err;
     FT_Long face_index = 0, num_faces;
 #ifdef HAVE_FREETYPE_FTWINFNT_H
     FT_WinFNT_HeaderRec winfnt_header;
@@ -1231,73 +1307,11 @@ static INT AddFontToList(const char *file, void *font_data_ptr, DWORD font_data_
     do {
         char *family_name = fake_family;
 
-        if (file)
-        {
-            TRACE("Loading font file %s index %ld\n", debugstr_a(file), face_index);
-            err = pFT_New_Face(library, file, face_index, &ft_face);
-        } else
-        {
-            TRACE("Loading font from ptr %p size %d, index %ld\n", font_data_ptr, font_data_size, face_index);
-            err = pFT_New_Memory_Face(library, font_data_ptr, font_data_size, face_index, &ft_face);
-        }
-
-	if(err != 0) {
-	    WARN("Unable to load font %s/%p err = %x\n", debugstr_a(file), font_data_ptr, err);
-	    return 0;
-	}
-
-	if(!FT_IS_SFNT(ft_face) && (FT_IS_SCALABLE(ft_face) || !(flags & ADDFONT_FORCE_BITMAP))) { /* for now we'll accept TT/OT or bitmap fonts*/
-	    WARN("Ignoring font %s/%p\n", debugstr_a(file), font_data_ptr);
-	    pFT_Done_Face(ft_face);
-	    return 0;
-	}
-
-        /* There are too many bugs in FreeType < 2.1.9 for bitmap font support */
-        if(!FT_IS_SCALABLE(ft_face) && FT_SimpleVersion < ((2 << 16) | (1 << 8) | (9 << 0))) {
-	    WARN("FreeType version < 2.1.9, skipping bitmap font %s/%p\n", debugstr_a(file), font_data_ptr);
-	    pFT_Done_Face(ft_face);
-	    return 0;
-	}
-
-        if(FT_IS_SFNT(ft_face))
-        {
-            if(!(pOS2 = pFT_Get_Sfnt_Table(ft_face, ft_sfnt_os2)) ||
-               !pFT_Get_Sfnt_Table(ft_face, ft_sfnt_hhea) ||
-               !(pHeader = pFT_Get_Sfnt_Table(ft_face, ft_sfnt_head)))
-            {
-                TRACE("Font %s/%p lacks either an OS2, HHEA or HEAD table.\n"
-                      "Skipping this font.\n", debugstr_a(file), font_data_ptr);
-                pFT_Done_Face(ft_face);
-                return 0;
-            }
-
-            /* Wine uses ttfs as an intermediate step in building its bitmap fonts;
-               we don't want to load these. */
-            if(!memcmp(pOS2->achVendID, "Wine", sizeof(pOS2->achVendID)))
-            {
-                FT_ULong len = 0;
-
-                if(!load_sfnt_table(ft_face, FT_MAKE_TAG('E','B','S','C'), 0, NULL, &len))
-                {
-                    TRACE("Skipping Wine bitmap-only TrueType font %s\n", debugstr_a(file));
-                    pFT_Done_Face(ft_face);
-                    return 0;
-                }
-            }
-        }
-
-        if(!ft_face->family_name || !ft_face->style_name) {
-            TRACE("Font %s/%p lacks either a family or style name\n", debugstr_a(file), font_data_ptr);
-            pFT_Done_Face(ft_face);
+        if (! GetFtFace(file, font_data_ptr, font_data_size, fake_family, flags, face_index, &ft_face))
             return 0;
-        }
 
-        if(ft_face->family_name[0] == '.') /* Ignore fonts with names beginning with a dot */
-        {
-            TRACE("Ignoring %s since its family name begins with a dot\n", debugstr_a(file));
-            pFT_Done_Face(ft_face);
-            return 0;
-        }
+        if(FT_IS_SFNT(ft_face))
+           pHeader = pFT_Get_Sfnt_Table(ft_face, ft_sfnt_head);
 
         if (target_family)
         {
-- 
1.5.3.6


--------------090801060605020700020201
Content-Type: text/x-patch;
 name="0002-Factor-out-the-logic-to-compute-the-family.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename*0="0002-Factor-out-the-logic-to-compute-the-family.patch"



More information about the wine-devel mailing list