[PATCH v3 0/1] MR2081: Support relocatable fontconfig cache
For flatpak: ``` bind mount: /run/host/fonts <- /usr/share/fonts /run/host/user-fonts <- ~/.local/share/fonts /run/host/fonts-cache <- /usr/lib/fontconfig/cache /run/host/user-fonts-cache <- ~/.cache/fontconfig ``` For fontconfig: https://bugs.freedesktop.org/show_bug.cgi?id=101889 https://github.com/flatpak/flatpak/issues/589 It supports relocatable cache. ``` FcConfigGetFontDirs( config ) -> /run/host/user-fonts/test,... FcDirCacheRead( /run/host/user-fonts/test, ... ) -> FcCacheCopySet -> pattern FcPatternGetString( pattern, FC_FILE, 0, &filename ) -> ~/.local/share/fonts/test/test.ttf ``` For wine: ``` FcPatternGetString -> unix_name -> add_unix_face( unix_name, ... ) ``` The valid file path for flatpak is `/run/host/user-fonts/test/test.ttf`. `~/.local/share/fonts/test/test.ttf` does not exist in flatpak sandbox. Add a check for this, and switch to right path. Test: ``` flatpak install org.winehq.Wine LANG=zh_CN.UTF-8 flatpak run org.winehq.Wine winecfg ```  -- v3: Support relocatable fontconfig cache https://gitlab.winehq.org/wine/wine/-/merge_requests/2081
From: catsout <outline941(a)live.com> --- dlls/win32u/freetype.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/dlls/win32u/freetype.c b/dlls/win32u/freetype.c index fd402758daa..6ac6670fd89 100644 --- a/dlls/win32u/freetype.c +++ b/dlls/win32u/freetype.c @@ -1524,11 +1524,12 @@ static FcPattern *create_family_pattern( const char *name, FcPattern **cached ) return ret; } -static void fontconfig_add_font( FcPattern *pattern, UINT flags ) +static void fontconfig_add_font( FcPattern *pattern, UINT flags, const char *cache_dir ) { - const char *unix_name, *format; + char *unix_name; + const char *format, *basename; WCHAR *dos_name; - FcBool scalable; + FcBool scalable, reloc; DWORD aa_flags; int face_index; @@ -1564,9 +1565,23 @@ static void fontconfig_add_font( FcPattern *pattern, UINT flags ) if (pFcPatternGetInteger( pattern, FC_INDEX, 0, &face_index ) != FcResultMatch) face_index = 0; + reloc = FcFalse; + if (strncmp( unix_name, cache_dir, strlen(cache_dir) ) != 0 && access( unix_name, F_OK ) != 0) { + basename = strrchr( unix_name, '/' ); + basename = ( basename ? basename+1 : unix_name ); + unix_name = malloc( strlen(cache_dir) + strlen(basename) + 2 ); + if (unix_name) { + sprintf( unix_name, "%s/%s", cache_dir, basename ); + reloc = FcTrue; + } + } + dos_name = get_dos_file_name( unix_name ); add_unix_face( unix_name, dos_name, NULL, 0, face_index, flags, NULL ); free( dos_name ); + + if (reloc == FcTrue) + free( unix_name ); } static void init_fontconfig(void) @@ -1648,7 +1663,7 @@ static void fontconfig_add_fonts_from_dir_list( FcConfig *config, FcStrList *dir if (!(font_set = pFcCacheCopySet( cache ))) goto done; for (i = 0; i < font_set->nfont; i++) - fontconfig_add_font( font_set->fonts[i], flags ); + fontconfig_add_font( font_set->fonts[i], flags , (const char *)dir ); pFcFontSetDestroy( font_set ); font_set = NULL; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/2081
So basically the path of `FC_FILE` in fontconfig under flatpak is incorrect? This doesn't sound like something Wine should have to work around. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/2081#note_24531
On Thu Feb 16 14:36:25 2023 +0000, Huw Davies wrote:
So basically the path of `FC_FILE` in fontconfig under flatpak is incorrect? This doesn't sound like something Wine should have to work around. `FC_FILE` is stored in the font cache file. flatpak mounts the cache into the sandbox. To avoid recreating the cache, maybe have the fontconfig lib check and return the changed `FC_FILE` value?
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/2081#note_24533
To avoid recreating the cache, maybe have the fontconfig lib check and return the changed `FC_FILE` value?
That would seem to be a better place for the fix. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/2081#note_24534
To avoid recreating the cache, maybe have the fontconfig lib check and return the changed `FC_FILE` value?
That would seem to be a better place for the fix.
Either that, or flatpak should copy the font cache and modify its contents to fix up the paths or something. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/2081#note_24537
This merge request was closed by Huw Davies. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/2081
Closing as this isn't something that Wine should need to deal with. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/2081#note_25852
participants (3)
-
catsout -
catsout (@catsout) -
Huw Davies (@huw)