[PATCH v2 8/8] gdi32: Create face first then initialize with ft_face.

Rémi Bernon rbernon at codeweavers.com
Wed Sep 9 07:50:31 CDT 2020


We will use FreeType cache manager to load FT_Face from Face pointers.

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---

Supersedes: 192328

v2: Fix the test regression, face_init_from_ft_face was also used in
    get_fontdir but only to retrieve some face information, and it
    shouldn't insert the face into its family there (or we need to
    properly remove it, which we don't).

    Let's keep it simple: rename AddFaceToList to face_insert_in_family,
    and call it only when we should.

    As Marvin isn't going to pick this up, I did it manually, and for a
    few locales:

    * https://testbot.winehq.org/JobDetails.pl?Key=78403
    * https://testbot.winehq.org/JobDetails.pl?Key=78404
    * https://testbot.winehq.org/JobDetails.pl?Key=78406
    * https://testbot.winehq.org/JobDetails.pl?Key=78407


 dlls/gdi32/freetype.c | 60 ++++++++++++++++++++++---------------------
 1 file changed, 31 insertions(+), 29 deletions(-)

diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c
index 6d559a917c1..abbeb5036f2 100644
--- a/dlls/gdi32/freetype.c
+++ b/dlls/gdi32/freetype.c
@@ -2139,12 +2139,8 @@ static inline void get_fontsig( FT_Face ft_face, FONTSIGNATURE *fs )
     }
 }
 
-static Face *create_face( FT_Face ft_face, FT_Long face_index, const char *file, DWORD flags )
+static void face_init_from_ft_face( Face *face, FT_Face ft_face )
 {
-    Face *face;
-
-    if (!(face = face_create( file, face_index, 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 );
@@ -2159,27 +2155,21 @@ static Face *create_face( FT_Face ft_face, FT_Long face_index, const char *file,
           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, FT_Long face_index, DWORD flags )
+static BOOL face_insert_in_family( Face *face, FT_Face ft_face )
 {
-    Face *face;
     Family *family;
-
-    face = create_face( ft_face, face_index, file, flags );
-    family = get_family( ft_face, flags & ADDFONT_VERTICAL_FONT );
+    if (!(family = get_family( ft_face, face->flags & ADDFONT_VERTICAL_FONT ))) return FALSE;
 
     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) );
     }
 
-    face_release( face );
     family_release( family );
+    return TRUE;
 }
 
 static FT_Face new_ft_face( const char *file, FT_Long face_index, BOOL allow_bitmap )
@@ -2250,7 +2240,8 @@ fail:
 
 static int add_faces_from_unix_file( const char *unix_name, DWORD flags )
 {
-    FT_Face ft_face;
+    Face *face = NULL;
+    FT_Face ft_face = NULL;
     FT_Long face_index = 0, num_faces;
     int ret = 0;
 
@@ -2279,33 +2270,39 @@ static int add_faces_from_unix_file( const char *unix_name, DWORD flags )
 
     do
     {
-        FONTSIGNATURE fs;
-
-        ft_face = new_ft_face( unix_name, face_index, flags & ADDFONT_ALLOW_BITMAP );
-        if (!ft_face) return 0;
+        if (!(face = face_create( unix_name, face_index, flags ))) goto failed;
+        if (!(ft_face = new_ft_face( unix_name, face_index, flags & ADDFONT_ALLOW_BITMAP ))) goto failed;
 
         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(unix_name) );
-            pFT_Done_Face( ft_face );
-            return 0;
+            goto failed;
         }
 
-        AddFaceToList( ft_face, unix_name, 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, unix_name, face_index, flags | ADDFONT_VERTICAL_FONT );
+            face_release( face );
+            if (!(face = face_create( unix_name, face_index, 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 );
+        face_release( face );
     } while (num_faces > ++face_index);
 
     return ret;
+
+failed:
+    if (ft_face) pFT_Done_Face( ft_face );
+    if (face) face_release( face );
+    return 0;
 }
 
 static int remove_font_resource( const WCHAR *file, DWORD flags )
@@ -3435,15 +3432,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, 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( ft_face, 0, unix_name, 0 );
+    if (!(face = face_create( unix_name, 0, 0 ))) return FALSE;
+    if (!(ft_face = new_ft_face( unix_name, 0, FALSE )))
+    {
+        face_release( 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