X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=src%2Ffccfg.c;h=b0a0f84fb572c6a77fe76a936ec01c602c0388ed;hb=d0471dd2faca37f7ee5997ad9db8278db0e99206;hp=da13f8c6b15a1b6ef14fff6c3314ae9047994fcb;hpb=3074a73b418b40135d4a4f4e0713fcf987d34795;p=fontconfig.git diff --git a/src/fccfg.c b/src/fccfg.c index da13f8c..b0a0f84 100644 --- a/src/fccfg.c +++ b/src/fccfg.c @@ -7,9 +7,9 @@ * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard not be used in + * documentation, and that the name of the author(s) not be used in * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no + * specific, written prior permission. The authors make no * representations about the suitability of this software for any purpose. It * is provided "as is" without express or implied warranty. * @@ -48,19 +48,19 @@ FcConfigCreate (void) if (!config) goto bail0; FcMemAlloc (FC_MEM_CONFIG, sizeof (FcConfig)); - + config->configDirs = FcStrSetCreate (); if (!config->configDirs) goto bail1; - + config->configFiles = FcStrSetCreate (); if (!config->configFiles) goto bail2; - + config->fontDirs = FcStrSetCreate (); if (!config->fontDirs) goto bail3; - + config->acceptGlobs = FcStrSetCreate (); if (!config->acceptGlobs) goto bail4; @@ -72,7 +72,7 @@ FcConfigCreate (void) config->acceptPatterns = FcFontSetCreate (); if (!config->acceptPatterns) goto bail6; - + config->rejectPatterns = FcFontSetCreate (); if (!config->rejectPatterns) goto bail7; @@ -80,7 +80,9 @@ FcConfigCreate (void) config->cacheDirs = FcStrSetCreate (); if (!config->cacheDirs) goto bail8; - + + config->rootDir = FcStrCopy ((const FcChar8 *) ""); + config->blanks = 0; config->substPattern = 0; @@ -91,10 +93,12 @@ FcConfigCreate (void) config->fonts[set] = 0; config->rescanTime = time(0); - config->rescanInterval = 30; + config->rescanInterval = 30; + + config->expr_pool = NULL; config->ref = 1; - + return config; bail8: @@ -119,7 +123,7 @@ bail0: } static FcFileTime -FcConfigNewestFile (FcStrSet *files) +FcConfigNewestFile (FcConfig *config, FcStrSet *files) { FcStrList *list = FcStrListCreate (files); FcFileTime newest = { 0, FcFalse }; @@ -129,7 +133,7 @@ FcConfigNewestFile (FcStrSet *files) if (list) { while ((file = FcStrListNext (list))) - if (FcStat ((char *) file, &statb) == 0) + if (FcStat (config, file, &statb) == 0) if (!newest.set || statb.st_mtime - newest.time > 0) { newest.set = FcTrue; @@ -151,9 +155,9 @@ FcConfigUptoDate (FcConfig *config) if (!config) return FcFalse; } - config_time = FcConfigNewestFile (config->configFiles); - config_dir_time = FcConfigNewestFile (config->configDirs); - font_time = FcConfigNewestFile (config->fontDirs); + config_time = FcConfigNewestFile (config, config->configFiles); + config_dir_time = FcConfigNewestFile (config, config->configDirs); + font_time = FcConfigNewestFile (config, config->fontDirs); if ((config_time.set && config_time.time - config->rescanTime > 0) || (config_dir_time.set && (config_dir_time.time - config->rescanTime) > 0) || (font_time.set && (font_time.time - config->rescanTime) > 0)) @@ -179,7 +183,7 @@ static void FcSubstDestroy (FcSubst *s) { FcSubst *n; - + while (s) { n = s->next; @@ -193,6 +197,26 @@ FcSubstDestroy (FcSubst *s) } } +FcExpr * +FcConfigAllocExpr (FcConfig *config) +{ + if (!config->expr_pool || config->expr_pool->next == config->expr_pool->end) + { + FcExprPage *new_page; + + new_page = malloc (sizeof (FcExprPage)); + if (!new_page) + return 0; + FcMemAlloc (FC_MEM_EXPR, sizeof (FcExprPage)); + + new_page->next_page = config->expr_pool; + new_page->next = new_page->exprs; + config->expr_pool = new_page; + } + + return config->expr_pool->next++; +} + FcConfig * FcConfigReference (FcConfig *config) { @@ -212,6 +236,7 @@ void FcConfigDestroy (FcConfig *config) { FcSetName set; + FcExprPage *page; if (--config->ref > 0) return; @@ -238,6 +263,15 @@ FcConfigDestroy (FcConfig *config) if (config->fonts[set]) FcFontSetDestroy (config->fonts[set]); + page = config->expr_pool; + while (page) + { + FcExprPage *next = page->next_page; + FcMemFree (FC_MEM_EXPR, sizeof (FcExprPage)); + free (page); + page = next; + } + free (config); FcMemFree (FC_MEM_CONFIG, sizeof (FcConfig)); } @@ -247,7 +281,7 @@ FcConfigDestroy (FcConfig *config) */ FcBool -FcConfigAddCache (FcConfig *config, FcCache *cache, +FcConfigAddCache (FcConfig *config, FcCache *cache, FcSetName set, FcStrSet *dirSet) { FcFontSet *fs; @@ -311,7 +345,7 @@ FcConfigAddDirList (FcConfig *config, FcSetName set, FcStrSet *dirSet) FcStrList *dirlist; FcChar8 *dir; FcCache *cache; - + dirlist = FcStrListCreate (dirSet); if (!dirlist) return FcFalse; @@ -350,9 +384,9 @@ FcConfigBuildFonts (FcConfig *config) fonts = FcFontSetCreate (); if (!fonts) return FcFalse; - + FcConfigSetFonts (config, fonts, FcSetSystem); - + if (!FcConfigAddDirList (config, FcSetSystem, config->fontDirs)) return FcFalse; if (FcDebug () & FC_DBG_FONTSET) @@ -415,7 +449,7 @@ FcBool FcConfigAddDir (FcConfig *config, const FcChar8 *d) { - return (FcConfigAddConfigDir (config, d) && + return (FcConfigAddConfigDir (config, d) && FcConfigAddFontDir (config, d)); } @@ -449,17 +483,17 @@ FcConfigGetCacheDirs (FcConfig *config) } return FcStrListCreate (config->cacheDirs); } - + FcBool FcConfigAddConfigFile (FcConfig *config, const FcChar8 *f) { FcBool ret; - FcChar8 *file = FcConfigFilename (f); - + FcChar8 *file = FcConfigFilename2 (config, f); + if (!file) return FcFalse; - + ret = FcStrSetAdd (config->configFiles, file); FcStrFree (file); return ret; @@ -523,7 +557,7 @@ FcConfigAddBlank (FcConfig *config, FcChar32 blank) { FcBlanks *b, *freeme = 0; - + b = config->blanks; if (!b) { @@ -581,7 +615,7 @@ FcConfigSetRescanInverval (FcConfig *config, int rescanInterval) return FcConfigSetRescanInterval (config, rescanInterval); } - + FcBool FcConfigAddEdit (FcConfig *config, FcTest *test, @@ -665,10 +699,10 @@ FcConfigCompareValue (const FcValue *left_o, FcValue left = FcValueCanonicalize(left_o); FcValue right = FcValueCanonicalize(right_o); FcBool ret = FcFalse; - + left = FcConfigPromote (left, right); right = FcConfigPromote (right, left); - if (left.type == right.type) + if (left.type == right.type) { switch (left.type) { case FcTypeInteger: @@ -684,16 +718,16 @@ FcConfigCompareValue (const FcValue *left_o, case FcOpNotContains: ret = left.u.d != right.u.d; break; - case FcOpLess: + case FcOpLess: ret = left.u.d < right.u.d; break; - case FcOpLessEqual: + case FcOpLessEqual: ret = left.u.d <= right.u.d; break; - case FcOpMore: + case FcOpMore: ret = left.u.d > right.u.d; break; - case FcOpMoreEqual: + case FcOpMoreEqual: ret = left.u.d >= right.u.d; break; default: @@ -702,7 +736,7 @@ FcConfigCompareValue (const FcValue *left_o, break; case FcTypeBool: switch (op) { - case FcOpEqual: + case FcOpEqual: case FcOpContains: case FcOpListing: ret = left.u.b == right.u.b; @@ -717,7 +751,7 @@ FcConfigCompareValue (const FcValue *left_o, break; case FcTypeString: switch (op) { - case FcOpEqual: + case FcOpEqual: case FcOpListing: ret = FcStrCmpIgnoreCase (left.u.s, right.u.s) == 0; break; @@ -840,7 +874,7 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e) FcResult r; FcMatrix *m; FcChar8 *str; - + switch (e->op) { case FcOpInteger: v.type = FcTypeInteger; @@ -852,7 +886,8 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e) break; case FcOpString: v.type = FcTypeString; - v.u.s = FcStrStaticName(e->u.sval); + v.u.s = e->u.sval; + v = FcValueSave (v); break; case FcOpMatrix: v.type = FcTypeMatrix; @@ -864,6 +899,11 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e) v.u.c = e->u.cval; v = FcValueSave (v); break; + case FcOpLangSet: + v.type = FcTypeLangSet; + v.u.l = e->u.lval; + v = FcValueSave (v); + break; case FcOpBool: v.type = FcTypeBool; v.u.b = e->u.bval; @@ -924,24 +964,24 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e) switch (vl.type) { case FcTypeDouble: switch (e->op) { - case FcOpPlus: + case FcOpPlus: v.type = FcTypeDouble; - v.u.d = vl.u.d + vr.u.d; + v.u.d = vl.u.d + vr.u.d; break; case FcOpMinus: v.type = FcTypeDouble; - v.u.d = vl.u.d - vr.u.d; + v.u.d = vl.u.d - vr.u.d; break; case FcOpTimes: v.type = FcTypeDouble; - v.u.d = vl.u.d * vr.u.d; + v.u.d = vl.u.d * vr.u.d; break; case FcOpDivide: v.type = FcTypeDouble; - v.u.d = vl.u.d / vr.u.d; + v.u.d = vl.u.d / vr.u.d; break; default: - v.type = FcTypeVoid; + v.type = FcTypeVoid; break; } if (v.type == FcTypeDouble && @@ -962,7 +1002,7 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e) v.u.b = vl.u.b && vr.u.b; break; default: - v.type = FcTypeVoid; + v.type = FcTypeVoid; break; } break; @@ -973,7 +1013,7 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e) str = FcStrPlus (vl.u.s, vr.u.s); v.u.s = FcStrStaticName (str); FcStrFree (str); - + if (!v.u.s) v.type = FcTypeVoid; break; @@ -1003,6 +1043,44 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e) break; } break; + case FcTypeCharSet: + switch (e->op) { + case FcOpPlus: + v.type = FcTypeCharSet; + v.u.c = FcCharSetUnion (vl.u.c, vr.u.c); + if (!v.u.c) + v.type = FcTypeVoid; + break; + case FcOpMinus: + v.type = FcTypeCharSet; + v.u.c = FcCharSetSubtract (vl.u.c, vr.u.c); + if (!v.u.c) + v.type = FcTypeVoid; + break; + default: + v.type = FcTypeVoid; + break; + } + break; + case FcTypeLangSet: + switch (e->op) { + case FcOpPlus: + v.type = FcTypeLangSet; + v.u.l = FcLangSetUnion (vl.u.l, vr.u.l); + if (!v.u.l) + v.type = FcTypeVoid; + break; + case FcOpMinus: + v.type = FcTypeLangSet; + v.u.l = FcLangSetSubtract (vl.u.l, vr.u.l); + if (!v.u.l) + v.type = FcTypeVoid; + break; + default: + v.type = FcTypeVoid; + break; + } + break; default: v.type = FcTypeVoid; break; @@ -1106,7 +1184,7 @@ FcConfigMatchValueList (FcPattern *p, FcExpr *e = t->expr; FcValue value; FcValueList *v; - + while (e) { /* Compute the value of the match expression */ @@ -1147,7 +1225,7 @@ static FcValueList * FcConfigValues (FcPattern *p, FcExpr *e, FcValueBinding binding) { FcValueList *l; - + if (!e) return 0; l = (FcValueList *) malloc (sizeof (FcValueList)); @@ -1185,7 +1263,7 @@ FcConfigAdd (FcValueListPtr *head, { FcValueListPtr *prev, last, v; FcValueBinding sameBinding; - + if (position) sameBinding = position->binding; else @@ -1198,7 +1276,7 @@ FcConfigAdd (FcValueListPtr *head, if (position) prev = &position->next; else - for (prev = head; *prev != NULL; + for (prev = head; *prev != NULL; prev = &(*prev)->next) ; } @@ -1206,7 +1284,7 @@ FcConfigAdd (FcValueListPtr *head, { if (position) { - for (prev = head; *prev != NULL; + for (prev = head; *prev != NULL; prev = &(*prev)->next) { if (*prev == position) @@ -1229,24 +1307,24 @@ FcConfigAdd (FcValueListPtr *head, FcValueListPrint (*head); printf ("\n"); } - + if (new) { last = new; while (last->next != NULL) last = last->next; - + last->next = *prev; *prev = new; } - + if (FcDebug () & FC_DBG_EDIT) { printf ("%s list after ", append ? "Append" : "Prepend"); FcValueListPrint (*head); printf ("\n"); } - + return FcTrue; } @@ -1277,7 +1355,7 @@ FcConfigPatternAdd (FcPattern *p, if (list) { FcPatternElt *e = FcPatternObjectInsertElt (p, object); - + if (!e) return; FcConfigAdd (&e->values, 0, append, list); @@ -1429,7 +1507,7 @@ FcConfigSubstituteWithPat (FcConfig *config, if ((t->kind == FcMatchFont || kind == FcMatchPattern) && t->object == e->object) { - /* + /* * KLUDGE - the pattern may have been reallocated or * things may have been inserted or deleted above * this element by other edits. Go back and find @@ -1452,7 +1530,7 @@ FcConfigSubstituteWithPat (FcConfig *config, { FcValueList *thisValue = st[i].value; FcValueList *nextValue = thisValue; - + /* * Append the new list of values after the current value */ @@ -1591,7 +1669,7 @@ DllMain (HINSTANCE hinstDLL, } else fontconfig_path[0] = '\0'; - + break; } @@ -1610,35 +1688,20 @@ DllMain (HINSTANCE hinstDLL, #endif static FcChar8 * -FcConfigFileExists (const FcChar8 *dir, const FcChar8 *file) +FcConfigFileExists (FcConfig *config, const FcChar8 *dir, const FcChar8 *file) { FcChar8 *path; if (!dir) - dir = (FcChar8 *) ""; - path = malloc (strlen ((char *) dir) + 1 + strlen ((char *) file) + 1); - if (!path) - return 0; + dir = (const FcChar8 *) ""; - strcpy ((char *) path, (const char *) dir); - /* make sure there's a single separator */ -#ifdef _WIN32 - if ((!path[0] || (path[strlen((char *) path)-1] != '/' && - path[strlen((char *) path)-1] != '\\')) && - !(file[0] == '/' || - file[0] == '\\' || - (isalpha (file[0]) && file[1] == ':' && (file[2] == '/' || file[2] == '\\')))) - strcat ((char *) path, "\\"); -#else - if ((!path[0] || path[strlen((char *) path)-1] != '/') && file[0] != '/') - strcat ((char *) path, "/"); -#endif - strcat ((char *) path, (char *) file); - - FcMemAlloc (FC_MEM_STRING, strlen ((char *) path) + 1); + path = FcStrPathPlus (FcConfigGetRoot (config), dir, file, NULL); if (access ((char *) path, R_OK) == 0) - return path; - + { + FcStrFree (path); + return FcStrPathPlus (dir, file, NULL); + } + FcStrFree (path); return 0; } @@ -1670,7 +1733,7 @@ FcConfigGetPath (void) if (env) { e = env; - while (*e) + while (*e) { colon = (FcChar8 *) strchr ((char *) e, FC_SEARCH_PATH_SEPARATOR); if (!colon) @@ -1687,7 +1750,7 @@ FcConfigGetPath (void) i++; } } - + #ifdef _WIN32 if (fontconfig_path[0] == '\0') { @@ -1753,6 +1816,12 @@ FcConfigEnableHome (FcBool enable) FcChar8 * FcConfigFilename (const FcChar8 *url) +{ + return FcConfigFilename2 (FcConfigGetCurrent (), url); +} + +FcChar8 * +FcConfigFilename2 (FcConfig *config, const FcChar8 *url) { FcChar8 *file, *dir, **path, **p; @@ -1775,7 +1844,7 @@ FcConfigFilename (const FcChar8 *url) case '~': dir = FcConfigHome (); if (dir) - file = FcConfigFileExists (dir, url + 1); + file = FcConfigFileExists (config, dir, url + 1); else file = 0; break; @@ -1784,7 +1853,7 @@ FcConfigFilename (const FcChar8 *url) absolute_path: #endif case '/': - file = FcConfigFileExists (0, url); + file = FcConfigFileExists (config, 0, url); break; default: path = FcConfigGetPath (); @@ -1792,7 +1861,7 @@ FcConfigFilename (const FcChar8 *url) return 0; for (p = path; *p; p++) { - file = FcConfigFileExists (*p, url); + file = FcConfigFileExists (config, *p, url); if (file) break; } @@ -1825,7 +1894,7 @@ FcConfigAppFontAddFile (FcConfig *config, subdirs = FcStrSetCreate (); if (!subdirs) return FcFalse; - + set = FcConfigGetFonts (config, FcSetApplication); if (!set) { @@ -1861,7 +1930,7 @@ FcConfigAppFontAddDir (FcConfig *config, { FcFontSet *set; FcStrSet *dirs; - + if (!config) { config = FcConfigGetCurrent (); @@ -1872,7 +1941,7 @@ FcConfigAppFontAddDir (FcConfig *config, dirs = FcStrSetCreate (); if (!dirs) return FcFalse; - + set = FcConfigGetFonts (config, FcSetApplication); if (!set) { @@ -1884,9 +1953,9 @@ FcConfigAppFontAddDir (FcConfig *config, } FcConfigSetFonts (config, set, FcSetApplication); } - + FcStrSetAddFilename (dirs, dir); - + if (!FcConfigAddDirList (config, FcSetApplication, dirs)) { FcStrSetDestroy (dirs); @@ -1929,7 +1998,7 @@ FcConfigGlobMatch (const FcChar8 *glob, { FcChar8 c; - while ((c = *glob++)) + while ((c = *glob++)) { switch (c) { case '*': @@ -2001,7 +2070,7 @@ FcConfigPatternsMatch (const FcFontSet *patterns, const FcPattern *font) { int i; - + for (i = 0; i < patterns->nfont; i++) if (FcListPatternMatchAny (patterns->fonts[i], font)) return FcTrue; @@ -2018,6 +2087,34 @@ FcConfigAcceptFont (FcConfig *config, return FcFalse; return FcTrue; } + +void +FcConfigSetRoot (FcConfig *config, + const FcChar8 *path) +{ + FcStrFree (config->rootDir); + config->rootDir = FcStrCopy (path); +} + +const FcChar8 * +FcConfigGetRoot (FcConfig *config) +{ + return config->rootDir; +} + +FcChar8 * +FcConfigGetRootPlus (FcConfig *config, + const FcChar8 *path) +{ + /* + * Since we have older funcs which do not take a config, it + * might be NULL, so handle that as well rather than crash. + */ + if (!config || !config->rootDir) + return NULL; + return FcStrPathPlus (config->rootDir, path, NULL); +} + #define __fccfg__ #include "fcaliastail.h" #undef __fccfg__