Skip to content

Commit

Permalink
libass: enable fontconfig
Browse files Browse the repository at this point in the history
This will solve hang issue when starting mpv if someone has 1000+ fonts installed in his windows :)
  • Loading branch information
shinchiro committed Jan 4, 2020
1 parent 3d22e03 commit b4ecef4
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 1 deletion.
138 changes: 138 additions & 0 deletions packages/fontconfig-0002-custom-changes-for-mpv-builds.patch
@@ -0,0 +1,138 @@
From 9a17cadaa905b8866ef8c8e0ca09fb37dcb53b9d Mon Sep 17 00:00:00 2001
From: shinchiro <shinchiro@users.noreply.github.com>
Date: Fri, 3 Jan 2020 23:02:52 +0800
Subject: [PATCH] Custom changes for mpv builds

Based on original lachs0r's patch for fontconfig
---
src/fcdir.c | 36 ++++++++++++++++++++++++------------
src/fcinit.c | 35 +++++++++++++++++++++++++++++++++++
2 files changed, 59 insertions(+), 12 deletions(-)

diff --git a/src/fcdir.c b/src/fcdir.c
index 693c845..6addf48 100644
--- a/src/fcdir.c
+++ b/src/fcdir.c
@@ -69,18 +69,9 @@ FcFileScanFontConfig (FcFontSet *set,
int old_nfont = set->nfont;
const FcChar8 *sysroot = FcConfigGetSysRoot (config);

- if (FcDebug () & FC_DBG_SCAN)
- {
- printf ("\tScanning file %s...", file);
- fflush (stdout);
- }
-
if (!FcFreeTypeQueryAll (file, -1, NULL, NULL, set))
return FcFalse;

- if (FcDebug () & FC_DBG_SCAN)
- printf ("done\n");
-
for (i = old_nfont; i < set->nfont; i++)
{
FcPattern *font = set->fonts[i];
@@ -221,8 +212,8 @@ FcDirScanConfig (FcFontSet *set,
base = file + strlen ((char *) file);

if (FcDebug () & FC_DBG_SCAN)
- printf ("\tScanning dir %s\n", dir);
-
+ fprintf (stderr, "[fontconfig] Scanning dir %s\n", dir);
+
d = opendir ((char *) dir);
if (!d)
{
@@ -258,8 +249,29 @@ FcDirScanConfig (FcFontSet *set,
/*
* Scan file files to build font patterns
*/
+ char buf1[512], buf2[512], pad[512], *str = &buf1[0], *prev = &buf2[0], *tmp;
+ int j, diff;
+ prev[0] = pad[0] = 0;
+
for (i = 0; i < files->num; i++)
- FcFileScanConfig (set, dirs, files->strs[i], config);
+ {
+ snprintf (str, 512, "\r[%d/%d] %s", i+1, files->num, files->strs[i]);
+
+ for (diff = strlen (prev) - strlen (str), j = 0; diff > 0; diff--, j++)
+ pad[j] = ' ';
+
+ pad[j] = 0;
+
+ if (FcDebug () & FC_DBG_SCAN)
+ fprintf (stderr, "%s%s", str, pad);
+
+ tmp = str; str = prev; prev = tmp;
+
+ FcFileScanConfig (set, dirs, files->strs[i], config);
+ }
+
+ if (FcDebug () & FC_DBG_SCAN)
+ fprintf (stderr, "\n[fontconfig] Finished scanning dir %s\n", dir);

bail2:
FcStrSetDestroy (files);
diff --git a/src/fcinit.c b/src/fcinit.c
index 6f82ebd..3202a2c 100644
--- a/src/fcinit.c
+++ b/src/fcinit.c
@@ -35,6 +35,12 @@
#pragma message("To suppress these warnings, define FC_NO_MT.")
#endif

+#ifdef _WIN32
+#define _WIN32_IE 0x0500
+#include <shlobj.h>
+#include <malloc.h>
+#endif
+
static FcConfig *
FcInitFallbackConfig (const FcChar8 *sysroot)
{
@@ -52,12 +58,41 @@ FcInitFallbackConfig (const FcChar8 *sysroot)
config = FcConfigCreate ();
if (!config)
goto bail0;
+
+#ifdef _WIN32
+ char *buf = malloc (MAX_PATH+1);
+ if (!buf) goto bail1;
+ if (SHGetFolderPathA (NULL, CSIDL_FONTS|CSIDL_FLAG_CREATE, NULL,
+ SHGFP_TYPE_CURRENT, buf) == S_OK) {
+ if (!FcConfigAddConfigDir (config, (FcChar8 *) buf))
+ goto bail2;
+ }
+
+ char *buf2 = malloc (MAX_PATH+1);
+ if (!buf) goto bail2;
+ if (SHGetFolderPathA (NULL, CSIDL_LOCAL_APPDATA|CSIDL_FLAG_CREATE, NULL,
+ SHGFP_TYPE_CURRENT, buf2) == S_OK) {
+ if (buf2[strlen(buf2)-1] != '\\')
+ strcat (buf2, "\\");
+ strcat (buf2, "fontconfig");
+ if (!FcConfigAddCacheDir (config, (FcChar8 *) buf2))
+ goto bail3;
+ }
+#else
FcConfigSetSysRoot (config, sysroot);
if (!FcConfigParseAndLoadFromMemory (config, fallback, FcFalse))
goto bail1;
+#endif

return config;

+#ifdef _WIN32
+bail3:
+ free(buf2);
+bail2:
+ free(buf);
+#endif
+
bail1:
FcConfigDestroy (config);
bail0:
--
2.17.1

3 changes: 2 additions & 1 deletion packages/libass.cmake
Expand Up @@ -4,14 +4,15 @@ ExternalProject_Add(libass
freetype2
fribidi
libiconv
fontconfig
GIT_REPOSITORY https://github.com/libass/libass.git
GIT_SHALLOW 1
UPDATE_COMMAND ""
CONFIGURE_COMMAND ${EXEC} <SOURCE_DIR>/configure
--host=${TARGET_ARCH}
--prefix=${MINGW_INSTALL_PREFIX}
--disable-shared
--disable-fontconfig
--disable-directwrite
BUILD_COMMAND ${MAKE}
INSTALL_COMMAND ${MAKE} install
LOG_DOWNLOAD 1 LOG_UPDATE 1 LOG_CONFIGURE 1 LOG_BUILD 1 LOG_INSTALL 1
Expand Down

0 comments on commit b4ecef4

Please sign in to comment.