[PATCH 3/4] gdi32: Create face first then initialize with ft_face.

Rémi Bernon rbernon at codeweavers.com
Thu Sep 24 06:41:11 CDT 2020


Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
 dlls/gdi32/freetype.c | 83 ++++++++++++++++++++++---------------------
 1 file changed, 43 insertions(+), 40 deletions(-)

diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c
index e61f8a180c5..51c67514856 100644
--- a/dlls/gdi32/freetype.c
+++ b/dlls/gdi32/freetype.c
@@ -2154,14 +2154,8 @@ static inline void get_fontsig( FT_Face ft_face, FONTSIGNATURE *fs )
     }
 }
 
-static Face *create_face_from_ft_face( FT_Face ft_face, FT_Long face_index, const char *file,
-                                       void *font_data_ptr, DWORD font_data_size, DWORD flags )
+static void face_init_from_ft_face( Face *face, FT_Face ft_face )
 {
-    Face *face;
-
-    if (!(face = create_face( file, face_index, font_data_ptr, font_data_size, flags )))
-        return NULL;
-
     face->style_name = ft_face_get_style_name( ft_face, GetSystemDefaultLangID() );
     face->full_name = ft_face_get_full_name( ft_face, GetSystemDefaultLangID() );
     if (face->flags & ADDFONT_VERTICAL_FONT) face->full_name = get_vertical_name( face->full_name );
@@ -2176,28 +2170,21 @@ static Face *create_face_from_ft_face( FT_Face ft_face, FT_Long face_index, cons
           face->fs.fsCsb[0], face->fs.fsCsb[1],
           face->fs.fsUsb[0], face->fs.fsUsb[1],
           face->fs.fsUsb[2], face->fs.fsUsb[3]);
-
-    return face;
 }
 
-static void AddFaceToList(FT_Face ft_face, const char *file, void *font_data_ptr, DWORD font_data_size,
-                          FT_Long face_index, DWORD flags )
+static BOOL face_insert_in_family( Face *face, FT_Face ft_face )
 {
-    Face *face;
     Family *family;
+    if (!(family = get_family( ft_face, face->flags & ADDFONT_VERTICAL_FONT ))) return FALSE;
 
-    if (!(face = create_face_from_ft_face( ft_face, face_index, file, font_data_ptr, font_data_size, flags )))
-        return;
-
-    family = get_family( ft_face, flags & ADDFONT_VERTICAL_FONT );
     if (insert_face_in_family_list( face, family ))
     {
-        if (flags & ADDFONT_ADD_TO_CACHE)
-            add_face_to_cache( face );
+        if (face->flags & ADDFONT_ADD_TO_CACHE) add_face_to_cache( face );
         TRACE( "Added face %s to family %s\n", debugstr_w(face->full_name), debugstr_w(family->family_name) );
     }
-    release_face( face );
+
     release_family( family );
+    return TRUE;
 }
 
 static FT_Face new_ft_face( const char *file, void *font_data_ptr, DWORD font_data_size,
@@ -2278,7 +2265,8 @@ fail:
 
 static INT AddFontToList(const char *file, void *font_data_ptr, DWORD font_data_size, DWORD flags)
 {
-    FT_Face ft_face;
+    Face *face = NULL;
+    FT_Face ft_face = NULL;
     FT_Long face_index = 0, num_faces;
     INT ret = 0;
 
@@ -2306,34 +2294,44 @@ static INT AddFontToList(const char *file, void *font_data_ptr, DWORD font_data_
     }
 #endif /* HAVE_CARBON_CARBON_H */
 
-    do {
-        FONTSIGNATURE fs;
-
-        ft_face = new_ft_face( file, font_data_ptr, font_data_size, face_index, flags & ADDFONT_ALLOW_BITMAP );
-        if (!ft_face) return 0;
+    do
+    {
+        if (!(face = create_face( file, face_index, font_data_ptr, font_data_size, flags )))
+            goto failed;
+        if (!(ft_face = new_ft_face( file, font_data_ptr, font_data_size, face_index, flags & ADDFONT_ALLOW_BITMAP )))
+            goto failed;
 
-        if(ft_face->family_name[0] == '.') /* Ignore fonts with names beginning with a dot */
+        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;
+            TRACE( "Ignoring %s since its family name begins with a dot\n", debugstr_a(file) );
+            goto failed;
         }
 
-        AddFaceToList(ft_face, file, font_data_ptr, font_data_size, face_index, flags);
+        face_init_from_ft_face( face, ft_face );
+        if (!face_insert_in_family( face, ft_face )) goto failed;
         ++ret;
 
-        get_fontsig(ft_face, &fs);
-        if (fs.fsCsb[0] & FS_DBCS_MASK)
+        if (face->fs.fsCsb[0] & FS_DBCS_MASK)
         {
-            AddFaceToList(ft_face, file, font_data_ptr, font_data_size, face_index,
-                          flags | ADDFONT_VERTICAL_FONT);
+            release_face( face );
+            if (!(face = create_face( file, face_index, font_data_ptr, font_data_size, flags | ADDFONT_VERTICAL_FONT )))
+                goto failed;
+            face_init_from_ft_face( face, ft_face );
+            if (!face_insert_in_family( face, ft_face )) goto failed;
             ++ret;
         }
 
-	num_faces = ft_face->num_faces;
-	pFT_Done_Face(ft_face);
-    } while(num_faces > ++face_index);
+        num_faces = ft_face->num_faces;
+        pFT_Done_Face( ft_face );
+        release_face( face );
+    } while (num_faces > ++face_index);
+
     return ret;
+
+failed:
+    if (ft_face) pFT_Done_Face( ft_face );
+    if (face) release_face( face );
+    return 0;
 }
 
 static int add_font_resource( const WCHAR *file, DWORD flags )
@@ -3525,15 +3523,20 @@ static void GetEnumStructs(Face *face, const WCHAR *family_name, LPENUMLOGFONTEX
 
 static BOOL get_fontdir( const char *unix_name, struct fontdir *fd )
 {
-    FT_Face ft_face = new_ft_face( unix_name, NULL, 0, 0, FALSE );
+    FT_Face ft_face;
     Face *face;
     WCHAR *family_name;
     ENUMLOGFONTEXW elf;
     NEWTEXTMETRICEXW ntm;
     DWORD type;
 
-    if (!ft_face) return FALSE;
-    face = create_face_from_ft_face( ft_face, 0, unix_name, NULL, 0, 0 );
+    if (!(face = create_face( unix_name, 0, NULL, 0, 0 ))) return FALSE;
+    if (!(ft_face = new_ft_face( unix_name, NULL, 0, 0, FALSE )))
+    {
+        release_face( face );
+        return FALSE;
+    }
+    face_init_from_ft_face( face, ft_face );
     family_name = ft_face_get_family_name( ft_face, GetSystemDefaultLCID() );
     pFT_Done_Face( ft_face );
 
-- 
2.28.0




More information about the wine-devel mailing list