diff options
Diffstat (limited to 'fontconfig/src/fcdir.c')
-rw-r--r-- | fontconfig/src/fcdir.c | 84 |
1 files changed, 73 insertions, 11 deletions
diff --git a/fontconfig/src/fcdir.c b/fontconfig/src/fcdir.c index 49259c1f2..593382f43 100644 --- a/fontconfig/src/fcdir.c +++ b/fontconfig/src/fcdir.c @@ -69,6 +69,7 @@ FcFileScanFontConfig (FcFontSet *set, FcBool ret = FcTrue; int id; int count = 0; + const FcChar8 *sysroot = FcConfigGetSysRoot (config); id = 0; do @@ -85,6 +86,28 @@ FcFileScanFontConfig (FcFontSet *set, font = FcFreeTypeQuery (file, id, blanks, &count); if (FcDebug () & FC_DBG_SCAN) printf ("done\n"); + /* + * Get rid of sysroot here so that targeting scan rule may contains FC_FILE pattern + * and they should usually expect without sysroot. + */ + if (sysroot) + { + size_t len = strlen ((const char *)sysroot); + FcChar8 *f = NULL; + + if (FcPatternObjectGetString (font, FC_FILE_OBJECT, 0, &f) == FcResultMatch && + strncmp ((const char *)f, (const char *)sysroot, len) == 0) + { + FcChar8 *s = FcStrdup (f); + FcPatternObjectDel (font, FC_FILE_OBJECT); + if (s[len] != '/') + len--; + else if (s[len+1] == '/') + len++; + FcPatternObjectAddString (font, FC_FILE_OBJECT, &s[len]); + FcStrFree (s); + } + } /* * Edit pattern with user-defined rules @@ -128,7 +151,25 @@ FcFileScanConfig (FcFontSet *set, FcConfig *config) { if (FcFileIsDir (file)) - return FcStrSetAdd (dirs, file); + { + const FcChar8 *sysroot = FcConfigGetSysRoot (config); + const FcChar8 *d = file; + size_t len; + + if (sysroot) + { + len = strlen ((const char *)sysroot); + if (strncmp ((const char *)file, (const char *)sysroot, len) == 0) + { + if (file[len] != '/') + len--; + else if (file[len+1] == '/') + len++; + d = &file[len]; + } + } + return FcStrSetAdd (dirs, d); + } else { if (set) @@ -238,7 +279,7 @@ FcDirScanConfig (FcFontSet *set, if (scanOnly) { if (FcFileIsDir (files->strs[i])) - FcStrSetAdd (dirs, files->strs[i]); + FcFileScanConfig (NULL, dirs, NULL, files->strs[i], config); } else { @@ -273,9 +314,10 @@ FcDirScan (FcFontSet *set, FcBool FcDirScanOnly (FcStrSet *dirs, - const FcChar8 *dir) + const FcChar8 *dir, + FcConfig *config) { - return FcDirScanConfig (NULL, dirs, NULL, dir, FcTrue, NULL, FcTrue); + return FcDirScanConfig (NULL, dirs, NULL, dir, FcTrue, config, FcTrue); } /* @@ -288,11 +330,18 @@ FcDirCacheScan (const FcChar8 *dir, FcConfig *config) FcFontSet *set; FcCache *cache = NULL; struct stat dir_stat; + const FcChar8 *sysroot = FcConfigGetSysRoot (config); + FcChar8 *d; + + if (sysroot) + d = FcStrBuildFilename (sysroot, dir, NULL); + else + d = FcStrdup (dir); if (FcDebug () & FC_DBG_FONTSET) - printf ("cache scan dir %s\n", dir); + printf ("cache scan dir %s\n", d); - if (FcStatChecksum (dir, &dir_stat) < 0) + if (FcStatChecksum (d, &dir_stat) < 0) goto bail; set = FcFontSetCreate(); @@ -306,7 +355,7 @@ FcDirCacheScan (const FcChar8 *dir, FcConfig *config) /* * Scan the dir */ - if (!FcDirScanConfig (set, dirs, NULL, dir, FcTrue, config, FcFalse)) + if (!FcDirScanConfig (set, dirs, NULL, d, FcTrue, config, FcFalse)) goto bail2; /* @@ -326,20 +375,30 @@ FcDirCacheScan (const FcChar8 *dir, FcConfig *config) bail1: FcFontSetDestroy (set); bail: + FcStrFree (d); + return cache; } FcCache * FcDirCacheRescan (const FcChar8 *dir, FcConfig *config) { - FcCache *cache = FcDirCacheLoad (dir, config, NULL); + FcCache *cache; FcCache *new = NULL; struct stat dir_stat; FcStrSet *dirs; + const FcChar8 *sysroot = FcConfigGetSysRoot (config); + FcChar8 *d = NULL; + cache = FcDirCacheLoad (dir, config, NULL); if (!cache) - return NULL; - if (FcStatChecksum (dir, &dir_stat) < 0) + goto bail; + + if (sysroot) + d = FcStrBuildFilename (sysroot, dir, NULL); + else + d = FcStrdup (dir); + if (FcStatChecksum (d, &dir_stat) < 0) goto bail; dirs = FcStrSetCreate (); if (!dirs) @@ -348,7 +407,7 @@ FcDirCacheRescan (const FcChar8 *dir, FcConfig *config) /* * Scan the dir */ - if (!FcDirScanConfig (NULL, dirs, NULL, dir, FcTrue, config, FcFalse)) + if (!FcDirScanConfig (NULL, dirs, NULL, d, FcTrue, config, FcFalse)) goto bail1; /* * Rebuild the cache object @@ -365,6 +424,9 @@ FcDirCacheRescan (const FcChar8 *dir, FcConfig *config) bail1: FcStrSetDestroy (dirs); bail: + if (d) + FcStrFree (d); + return new; } |