Skip to content

Instantly share code, notes, and snippets.

@Jessidhia
Last active December 20, 2015 01:29
Show Gist options
  • Save Jessidhia/6049312 to your computer and use it in GitHub Desktop.
Save Jessidhia/6049312 to your computer and use it in GitHub Desktop.
[PATCH] Make fontconfig-2.11.0 less dumb on windows
From 771818fab860a6e897f4046d67d8fd9949662977 Mon Sep 17 00:00:00 2001
From: "Diogo Franco (Kovensky)" <diogomfranco@gmail.com>
Date: Sat, 25 Jan 2014 18:04:20 -0300
Subject: [PATCH] Make fontconfig-2.11.0 less dumb on windows
Yes, fontconfig's indentation is that weird.
Adds the windows font directory to the default search path, stores
fontconfig cache files in a folder in the local application data folder.
This behaves correctly with roaming profiles and doesn't litter the
filesystem with a new cache on every working directory fontconfig is used
in.
Print a status line with the current font it's looking at when rebuilding
cache; makes at least command-line programs don't look like they're frozen
while rebuilding it.
---
src/fcdir.c | 16 +++++++++++++++-
src/fcinit.c | 41 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 56 insertions(+), 1 deletion(-)
diff --git a/src/fcdir.c b/src/fcdir.c
index 2b476e8..a9bd2bc 100644
--- a/src/fcdir.c
+++ b/src/fcdir.c
@@ -203,8 +203,22 @@ FcDirScanConfig (FcFontSet *set,
/*
* Scan file files to build font patterns
*/
- for (i = 0; i < files->num; i++)
+ char buf1[512], buf2[512], pad[512], *str = &buf1[0], *prev = &buf2[0], *tmp;
+ int j, diff;
+ prev[0] = pad[0] = 0;
+ fprintf (stderr, "\n");
+ for (i = 0; i < files->num; i++) {
+ // damn your indentation fontconfig
+ 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;
+ fprintf (stderr, "%s%s", str, pad);
+ tmp = str; str = prev; prev = tmp;
FcFileScanConfig (set, dirs, blanks, files->strs[i], config);
+ }
+ fprintf (stderr, "\n");
bail2:
FcStrSetDestroy (files);
diff --git a/src/fcinit.c b/src/fcinit.c
index ab64012..f66029c 100644
--- a/src/fcinit.c
+++ b/src/fcinit.c
@@ -25,6 +25,19 @@
#include "fcint.h"
#include <stdlib.h>
+#ifdef _WIN32
+
+#if defined(_WIN32_IE) && _WIN32_IE < 0x0500
+#undef _WIN32_IE
+#endif
+#ifndef _WIN32_IE
+#define _WIN32_IE 0x0500
+#endif
+
+#include <shlobj.h>
+#include <malloc.h>
+#endif
+
#if defined(FC_ATOMIC_INT_NIL)
#pragma message("Could not find any system to define atomic_int macros, library may NOT be thread-safe.")
#endif
@@ -33,12 +46,40 @@ FcInitFallbackConfig (void)
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 (!FcConfigAddDir (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
if (!FcConfigAddDir (config, (FcChar8 *) FC_DEFAULT_FONTS))
goto bail1;
if (!FcConfigAddCacheDir (config, (FcChar8 *) FC_CACHEDIR))
goto bail1;
+#endif
+
return config;
+#ifdef _WIN32
+bail3:
+ free(buf2);
+bail2:
+ free(buf);
+#endif
bail1:
FcConfigDestroy (config);
bail0:
--
1.8.3.3.755.g001b097
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment