Alexandre Julliard : gdi32: Move the loading of filesystem fonts out of freetype.c.

Alexandre Julliard julliard at winehq.org
Tue Oct 27 16:43:49 CDT 2020


Module: wine
Branch: master
Commit: 7b291a094d20e315d44ae88a09529581556fd9d6
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=7b291a094d20e315d44ae88a09529581556fd9d6

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue Oct 27 10:27:32 2020 +0100

gdi32: Move the loading of filesystem fonts out of freetype.c.

The fonts Path value now expects DOS paths.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/gdi32/font.c        | 68 ++++++++++++++++++++++++++++++++++----------
 dlls/gdi32/freetype.c    | 73 ++----------------------------------------------
 dlls/gdi32/gdi_private.h |  2 +-
 3 files changed, 58 insertions(+), 85 deletions(-)

diff --git a/dlls/gdi32/font.c b/dlls/gdi32/font.c
index 3718d73f871..4e1c69d886e 100644
--- a/dlls/gdi32/font.c
+++ b/dlls/gdi32/font.c
@@ -359,36 +359,26 @@ CRITICAL_SECTION font_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
 #define WINE_FONT_DIR "fonts"
 #endif
 
-void get_font_dir( WCHAR *path )
+static void get_fonts_data_dir_path( const WCHAR *file, WCHAR *path )
 {
-    static const WCHAR slashW[] = {'\\',0};
-    static const WCHAR fontsW[] = {'\\','f','o','n','t','s',0};
+    static const WCHAR fontsW[] = {'\\','f','o','n','t','s','\\',0};
     static const WCHAR winedatadirW[] = {'W','I','N','E','D','A','T','A','D','I','R',0};
     static const WCHAR winebuilddirW[] = {'W','I','N','E','B','U','I','L','D','D','I','R',0};
 
     if (GetEnvironmentVariableW( winedatadirW, path, MAX_PATH ))
     {
-        const char fontdir[] = WINE_FONT_DIR;
-        strcatW( path, slashW );
+        const char fontdir[] = "\\" WINE_FONT_DIR "\\";
         MultiByteToWideChar( CP_ACP, 0, fontdir, -1, path + strlenW(path), MAX_PATH - strlenW(path) );
     }
     else if (GetEnvironmentVariableW( winebuilddirW, path, MAX_PATH ))
     {
         strcatW( path, fontsW );
     }
+    strcatW( path, file );
     if (path[5] == ':') memmove( path, path + 4, (strlenW(path) - 3) * sizeof(WCHAR) );
     else path[1] = '\\';  /* change \??\ to \\?\ */
 }
 
-static void get_fonts_data_dir_path( const WCHAR *file, WCHAR *path )
-{
-    static const WCHAR slashW[] = {'\\',0};
-
-    get_font_dir( path );
-    strcatW( path, slashW );
-    strcatW( path, file );
-}
-
 static void get_fonts_win_dir_path( const WCHAR *file, WCHAR *path )
 {
     static const WCHAR fontsW[] = {'\\','f','o','n','t','s','\\',0};
@@ -5402,6 +5392,56 @@ void load_system_bitmap_fonts(void)
     RegCloseKey( hkey );
 }
 
+static void load_directory_fonts( WCHAR *path, UINT flags )
+{
+    HANDLE handle;
+    WIN32_FIND_DATAW data;
+    WCHAR *p;
+
+    p = path + strlenW(path) - 1;
+    TRACE( "loading fonts from %s\n", debugstr_w(path) );
+    handle = FindFirstFileW( path, &data );
+    if (handle == INVALID_HANDLE_VALUE) return;
+    do
+    {
+        if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue;
+        strcpyW( p, data.cFileName );
+        font_funcs->add_font( path, flags );
+    } while (FindNextFileW( handle, &data ));
+    FindClose( handle );
+}
+
+void load_file_system_fonts(void)
+{
+    static const WCHAR pathW[] = {'P','a','t','h',0};
+    static const WCHAR slashstarW[] = {'\\','*',0};
+    static const WCHAR starW[] = {'*',0};
+    WCHAR *ptr, *next, path[MAX_PATH], value[1024];
+    DWORD len = ARRAY_SIZE(value);
+
+    /* Windows directory */
+    get_fonts_win_dir_path( starW, path );
+    load_directory_fonts( path, ADDFONT_ADD_TO_CACHE );
+
+    /* Wine data directory */
+    get_fonts_data_dir_path( starW, path );
+    load_directory_fonts( path, ADDFONT_ADD_TO_CACHE | ADDFONT_EXTERNAL_FONT );
+
+    /* custom paths */
+    /* @@ Wine registry key: HKCU\Software\Wine\Fonts */
+    if (!RegQueryValueExW( wine_fonts_key, pathW, NULL, NULL, (BYTE *)value, &len ))
+    {
+        for (ptr = value; ptr; ptr = next)
+        {
+            if ((next = strchrW( ptr, ';' ))) *next++ = 0;
+            if (next && next - ptr < 2) continue;
+            lstrcpynW( path, ptr, MAX_PATH - 2 );
+            strcatW( path, slashstarW );
+            load_directory_fonts( path, ADDFONT_ADD_TO_CACHE | ADDFONT_EXTERNAL_FONT );
+        }
+    }
+}
+
 void load_registry_fonts(void)
 {
     static const WCHAR dot_fonW[] = {'.','f','o','n',0};
diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c
index ee628a08304..0a5f5af491b 100644
--- a/dlls/gdi32/freetype.c
+++ b/dlls/gdi32/freetype.c
@@ -329,7 +329,6 @@ static struct list font_list = LIST_INIT(font_list);
 
 static const struct font_backend_funcs font_funcs;
 
-static const WCHAR fontsW[] = {'\\','f','o','n','t','s','\0'};
 static const WCHAR win9x_font_reg_key[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
                                            'W','i','n','d','o','w','s','\\',
                                            'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
@@ -2545,6 +2544,7 @@ skip_internal:
     list_add_tail(&system_links, &system_font_link->entry);
 }
 
+#ifdef __ANDROID__
 static BOOL ReadFontDir(const char *dirname, BOOL external_fonts)
 {
     DIR *dir;
@@ -2585,16 +2585,7 @@ static BOOL ReadFontDir(const char *dirname, BOOL external_fonts)
     closedir(dir);
     return TRUE;
 }
-
-static void read_font_dir( const WCHAR *dirname, BOOL external_fonts )
-{
-    char *unixname = wine_get_unix_file_name( dirname );
-    if (unixname)
-    {
-        ReadFontDir( unixname, external_fonts );
-        HeapFree( GetProcessHeap(), 0, unixname );
-    }
-}
+#endif
 
 #ifdef SONAME_LIBFONTCONFIG
 
@@ -3407,24 +3398,9 @@ sym_not_found:
 
 static void init_font_list(void)
 {
-    static const WCHAR pathW[] = {'P','a','t','h',0};
-    HKEY hkey;
-    WCHAR path[MAX_PATH];
-    char *unixname;
-
     delete_external_font_keys();
-
     load_system_bitmap_fonts();
-
-    /* load in the fonts from %WINDOWSDIR%\\Fonts first of all */
-    GetWindowsDirectoryW(path, ARRAY_SIZE(path));
-    strcatW(path, fontsW);
-    read_font_dir( path, FALSE );
-
-    /* load the wine fonts */
-    get_font_dir( path );
-    read_font_dir( path, TRUE );
-
+    load_file_system_fonts();
     load_registry_fonts();
 
 #ifdef SONAME_LIBFONTCONFIG
@@ -3434,49 +3410,6 @@ static void init_font_list(void)
 #elif defined(__ANDROID__)
     ReadFontDir("/system/fonts", TRUE);
 #endif
-
-    /* then look in any directories that we've specified in the config file */
-    /* @@ Wine registry key: HKCU\Software\Wine\Fonts */
-    if(RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Fonts", &hkey) == ERROR_SUCCESS)
-    {
-        DWORD len;
-        LPWSTR valueW;
-        LPSTR valueA, ptr;
-
-        if (RegQueryValueExW( hkey, pathW, NULL, NULL, NULL, &len ) == ERROR_SUCCESS)
-        {
-            len += sizeof(WCHAR);
-            valueW = HeapAlloc( GetProcessHeap(), 0, len );
-            if (RegQueryValueExW( hkey, pathW, NULL, NULL, (LPBYTE)valueW, &len ) == ERROR_SUCCESS)
-            {
-                len = WideCharToMultiByte( CP_UNIXCP, 0, valueW, -1, NULL, 0, NULL, NULL );
-                valueA = HeapAlloc( GetProcessHeap(), 0, len );
-                WideCharToMultiByte( CP_UNIXCP, 0, valueW, -1, valueA, len, NULL, NULL );
-                TRACE( "got font path %s\n", debugstr_a(valueA) );
-                ptr = valueA;
-                while (ptr)
-                {
-                    const char* home;
-                    LPSTR next = strchr( ptr, ':' );
-                    if (next) *next++ = 0;
-                    if (ptr[0] == '~' && ptr[1] == '/' && (home = getenv( "HOME" )) &&
-                        (unixname = HeapAlloc( GetProcessHeap(), 0, strlen(ptr) + strlen(home) )))
-                    {
-                        strcpy( unixname, home );
-                        strcat( unixname, ptr + 1 );
-                        ReadFontDir( unixname, TRUE );
-                        HeapFree( GetProcessHeap(), 0, unixname );
-                    }
-                    else
-                        ReadFontDir( ptr, TRUE );
-                    ptr = next;
-                }
-                HeapFree( GetProcessHeap(), 0, valueA );
-            }
-            HeapFree( GetProcessHeap(), 0, valueW );
-        }
-        RegCloseKey(hkey);
-    }
 }
 
 static BOOL move_to_front(const WCHAR *name)
diff --git a/dlls/gdi32/gdi_private.h b/dlls/gdi32/gdi_private.h
index 080f53c1b61..aa6e6ddcaa9 100644
--- a/dlls/gdi32/gdi_private.h
+++ b/dlls/gdi32/gdi_private.h
@@ -389,8 +389,8 @@ struct font_backend_funcs
     void  (CDECL *destroy_font)( struct gdi_font *font );
 };
 
-extern void get_font_dir( WCHAR *path ) DECLSPEC_HIDDEN;
 extern void load_system_bitmap_fonts(void) DECLSPEC_HIDDEN;
+extern void load_file_system_fonts(void) DECLSPEC_HIDDEN;
 extern void load_registry_fonts(void) DECLSPEC_HIDDEN;
 
 extern struct gdi_font *alloc_gdi_font( const WCHAR *file, void *data_ptr, SIZE_T data_size ) DECLSPEC_HIDDEN;




More information about the wine-cvs mailing list