[PATCH 7/8] gdi32: Cleanup and rename AddFontToList similarly.

Rémi Bernon rbernon at codeweavers.com
Wed Sep 9 05:22:03 CDT 2020


There too we will use fontconfig when available to parse font files,
as it may be able to use its cache to improve loading time.

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

diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c
index e26526462ba..6d559a917c1 100644
--- a/dlls/gdi32/freetype.c
+++ b/dlls/gdi32/freetype.c
@@ -2248,75 +2248,63 @@ fail:
     return NULL;
 }
 
-static INT AddFontToList( const char *file, DWORD flags )
+static int add_faces_from_unix_file( const char *unix_name, DWORD flags )
 {
     FT_Face ft_face;
     FT_Long face_index = 0, num_faces;
-    INT ret = 0;
+    int ret = 0;
 
     /* we always load external fonts from files - otherwise we would get a crash in update_reg_entries */
-    assert(file || !(flags & ADDFONT_EXTERNAL_FONT));
+    assert( unix_name || !(flags & ADDFONT_EXTERNAL_FONT) );
 
 #ifdef HAVE_CARBON_CARBON_H
-    if(file)
+    if (unix_name)
     {
-        char **mac_list = expand_mac_font(file);
-        if(mac_list)
+        char **mac_list = expand_mac_font( unix_name );
+        if (mac_list)
         {
             BOOL had_one = FALSE;
             char **cursor;
-            for(cursor = mac_list; *cursor; cursor++)
+            for (cursor = mac_list; *cursor; cursor++)
             {
                 had_one = TRUE;
-                AddFontToList( *cursor, flags );
-                HeapFree(GetProcessHeap(), 0, *cursor);
+                add_faces_from_unix_file( *cursor, flags );
+                HeapFree( GetProcessHeap(), 0, *cursor );
             }
-            HeapFree(GetProcessHeap(), 0, mac_list);
-            if(had_one)
-                return 1;
+            HeapFree( GetProcessHeap(), 0, mac_list );
+            if (had_one) return 1;
         }
     }
 #endif /* HAVE_CARBON_CARBON_H */
 
-    do {
+    do
+    {
         FONTSIGNATURE fs;
 
-        ft_face = new_ft_face( file, face_index, flags & ADDFONT_ALLOW_BITMAP );
+        ft_face = new_ft_face( unix_name, face_index, flags & ADDFONT_ALLOW_BITMAP );
         if (!ft_face) return 0;
 
-        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);
+            TRACE( "Ignoring %s since its family name begins with a dot\n", debugstr_a(unix_name) );
+            pFT_Done_Face( ft_face );
             return 0;
         }
 
-        AddFaceToList( ft_face, file, face_index, flags );
+        AddFaceToList( ft_face, unix_name, face_index, flags );
         ++ret;
 
-        get_fontsig(ft_face, &fs);
+        get_fontsig( ft_face, &fs );
         if (fs.fsCsb[0] & FS_DBCS_MASK)
         {
-            AddFaceToList( ft_face, file, face_index, flags | ADDFONT_VERTICAL_FONT );
+            AddFaceToList( ft_face, unix_name, face_index, flags | ADDFONT_VERTICAL_FONT );
             ++ret;
         }
 
-	num_faces = ft_face->num_faces;
-	pFT_Done_Face(ft_face);
-    } while(num_faces > ++face_index);
-    return ret;
-}
+        num_faces = ft_face->num_faces;
+        pFT_Done_Face( ft_face );
+    } while (num_faces > ++face_index);
 
-static int add_font_resource( const WCHAR *file, DWORD flags )
-{
-    int ret = 0;
-    char *unixname = wine_get_unix_file_name( file );
-
-    if (unixname)
-    {
-        ret = AddFontToList( unixname, flags );
-        HeapFree( GetProcessHeap(), 0, unixname );
-    }
     return ret;
 }
 
@@ -2787,7 +2775,7 @@ static int add_faces_from_unix_dir( const char *unix_name, DWORD flags )
         }
 
         if (S_ISDIR( statbuf.st_mode )) ret += add_faces_from_unix_dir( path, flags );
-        else ret += AddFontToList( path, flags );
+        else ret += add_faces_from_unix_file( path, flags );
     }
 
     closedir( dir );
@@ -2912,7 +2900,7 @@ static void load_fontconfig_fonts(void)
         if(len < 4) continue;
         ext = &file[ len - 3 ];
         if(_strnicmp(ext, "pfa", -1) && _strnicmp(ext, "pfb", -1))
-            AddFontToList( file, ADDFONT_EXTERNAL_FONT | ADDFONT_ADD_TO_CACHE | ADDFONT_AA_FLAGS( aa_flags ) );
+            add_faces_from_unix_file(file, ADDFONT_EXTERNAL_FONT | ADDFONT_ADD_TO_CACHE | ADDFONT_AA_FLAGS(aa_flags) );
     }
     pFcFontSetDestroy(fontset);
     pFcPatternDestroy(pat);
@@ -2931,7 +2919,7 @@ static void load_mac_font_callback(const void *value, void *context)
     if (path && CFStringGetFileSystemRepresentation(pathStr, path, len))
     {
         TRACE("font file %s\n", path);
-        AddFontToList( path, ADDFONT_EXTERNAL_FONT | ADDFONT_ADD_TO_CACHE );
+        add_faces_from_unix_file( path, ADDFONT_EXTERNAL_FONT | ADDFONT_ADD_TO_CACHE );
     }
     HeapFree(GetProcessHeap(), 0, path);
 }
@@ -3042,6 +3030,17 @@ static void load_mac_fonts(void)
 
 #endif
 
+static int add_faces_from_file( const WCHAR *file, DWORD flags )
+{
+    int ret;
+    char *unix_name = wine_get_unix_file_name( file );
+    if (!unix_name) return 0;
+
+    ret = add_faces_from_unix_file( unix_name, flags );
+    HeapFree( GetProcessHeap(), 0, unix_name );
+    return ret;
+}
+
 static int add_faces_from_dir( const WCHAR *dirname, DWORD flags )
 {
     int ret;
@@ -3105,10 +3104,10 @@ static void load_system_fonts(void)
             if(RegQueryValueExW(hkey, *value, 0, &type, (void*)data, &dlen) == ERROR_SUCCESS &&
                type == REG_SZ) {
                 get_winfonts_dir_path( data, pathW );
-                if (!add_font_resource( pathW, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_TO_CACHE ))
+                if (!add_faces_from_file( pathW, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_TO_CACHE ))
                 {
                     get_data_dir_path( data, pathW );
-                    add_font_resource( pathW, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_TO_CACHE );
+                    add_faces_from_file( pathW, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_TO_CACHE );
                 }
             }
         }
@@ -3305,17 +3304,17 @@ INT WineEngAddFontResourceEx( LPCWSTR file, DWORD flags, PVOID pdv, BOOL mem_res
         EnterCriticalSection( &freetype_cs );
 
         if (!(flags & FR_PRIVATE)) addfont_flags |= ADDFONT_ADD_TO_CACHE;
-        ret = add_font_resource( file, addfont_flags );
+        ret = add_faces_from_file( file, addfont_flags );
 
         if (!ret && !strchrW(file, '\\')) {
             /* Try in %WINDIR%/fonts, needed for Fotobuch Designer */
             get_winfonts_dir_path( file, path );
-            ret = add_font_resource( path, addfont_flags & ~ADDFONT_ADD_TO_CACHE );
+            ret = add_faces_from_file( path, addfont_flags & ~ADDFONT_ADD_TO_CACHE );
             /* Try in datadir/fonts (or builddir/fonts), needed for Magic the Gathering Online */
             if (!ret)
             {
                 get_data_dir_path( file, path );
-                ret = add_font_resource( path, addfont_flags & ~ADDFONT_ADD_TO_CACHE );
+                ret = add_faces_from_file( path, addfont_flags & ~ADDFONT_ADD_TO_CACHE );
             }
         }
 
@@ -4224,17 +4223,17 @@ static void init_font_list(void)
             {
                 if(data[0] && (data[1] == ':'))
                 {
-                    add_font_resource( data, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_TO_CACHE);
+                    add_faces_from_file( data, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_TO_CACHE );
                 }
                 else if(dlen / 2 >= 6 && !strcmpiW(data + dlen / 2 - 5, dot_fonW))
                 {
                     WCHAR pathW[MAX_PATH];
 
                     get_winfonts_dir_path( data, pathW );
-                    if (!add_font_resource( pathW, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_TO_CACHE ))
+                    if (!add_faces_from_file( pathW, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_TO_CACHE ))
                     {
                         get_data_dir_path( data, pathW );
-                        add_font_resource( pathW, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_TO_CACHE );
+                        add_faces_from_file( pathW, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_TO_CACHE );
                     }
                 }
                 /* reset dlen and vlen */
-- 
2.28.0




More information about the wine-devel mailing list