2 * $RCSId: xc/lib/fontconfig/src/fccfg.c,v 1.23 2002/08/31 22:17:32 keithp Exp $
4 * Copyright © 2000 Keith Packard
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of Keith Packard not be used in
11 * advertising or publicity pertaining to distribution of the software without
12 * specific, written prior permission. Keith Packard makes no
13 * representations about the suitability of this software for any purpose. It
14 * is provided "as is" without express or implied warranty.
16 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22 * PERFORMANCE OF THIS SOFTWARE.
27 #include <sys/types.h>
29 #if defined (_WIN32) && (defined (PIC) || defined (DLL_EXPORT))
35 #if defined (_WIN32) && !defined (R_OK)
47 config = malloc (sizeof (FcConfig));
50 FcMemAlloc (FC_MEM_CONFIG, sizeof (FcConfig));
52 config->configDirs = FcStrSetCreate ();
53 if (!config->configDirs)
56 config->configFiles = FcStrSetCreate ();
57 if (!config->configFiles)
60 config->fontDirs = FcStrSetCreate ();
61 if (!config->fontDirs)
64 config->acceptGlobs = FcStrSetCreate ();
65 if (!config->acceptGlobs)
68 config->rejectGlobs = FcStrSetCreate ();
69 if (!config->rejectGlobs)
72 config->acceptPatterns = FcFontSetCreate ();
73 if (!config->acceptPatterns)
76 config->rejectPatterns = FcFontSetCreate ();
77 if (!config->rejectPatterns)
80 config->cacheDirs = FcStrSetCreate ();
81 if (!config->cacheDirs)
86 config->substPattern = 0;
87 config->substFont = 0;
88 config->substScan = 0;
89 config->maxObjects = 0;
90 for (set = FcSetSystem; set <= FcSetApplication; set++)
91 config->fonts[set] = 0;
93 config->rescanTime = time(0);
94 config->rescanInterval = 30;
99 FcFontSetDestroy (config->rejectPatterns);
101 FcFontSetDestroy (config->acceptPatterns);
103 FcStrSetDestroy (config->rejectGlobs);
105 FcStrSetDestroy (config->acceptGlobs);
107 FcStrSetDestroy (config->fontDirs);
109 FcStrSetDestroy (config->configFiles);
111 FcStrSetDestroy (config->configDirs);
114 FcMemFree (FC_MEM_CONFIG, sizeof (FcConfig));
120 FcConfigNewestFile (FcStrSet *files)
122 FcStrList *list = FcStrListCreate (files);
123 FcFileTime newest = { 0, FcFalse };
129 while ((file = FcStrListNext (list)))
130 if (stat ((char *) file, &statb) == 0)
131 if (!newest.set || statb.st_mtime - newest.time > 0)
134 newest.time = statb.st_mtime;
136 FcStrListDone (list);
142 FcConfigUptoDate (FcConfig *config)
144 FcFileTime config_time, config_dir_time, font_time;
145 time_t now = time(0);
148 config = FcConfigGetCurrent ();
152 config_time = FcConfigNewestFile (config->configFiles);
153 config_dir_time = FcConfigNewestFile (config->configDirs);
154 font_time = FcConfigNewestFile (config->fontDirs);
155 if ((config_time.set && config_time.time - config->rescanTime > 0) ||
156 (config_dir_time.set && (config_dir_time.time - config->rescanTime) > 0) ||
157 (font_time.set && (font_time.time - config->rescanTime) > 0))
161 config->rescanTime = now;
166 FcSubstDestroy (FcSubst *s)
174 FcTestDestroy (s->test);
176 FcEditDestroy (s->edit);
178 FcMemFree (FC_MEM_SUBST, sizeof (FcSubst));
184 FcConfigDestroy (FcConfig *config)
188 if (config == _fcConfig)
191 FcStrSetDestroy (config->configDirs);
192 FcStrSetDestroy (config->fontDirs);
193 FcStrSetDestroy (config->cacheDirs);
194 FcStrSetDestroy (config->configFiles);
195 FcStrSetDestroy (config->acceptGlobs);
196 FcStrSetDestroy (config->rejectGlobs);
197 FcFontSetDestroy (config->acceptPatterns);
198 FcFontSetDestroy (config->rejectPatterns);
201 FcBlanksDestroy (config->blanks);
203 FcSubstDestroy (config->substPattern);
204 FcSubstDestroy (config->substFont);
205 FcSubstDestroy (config->substScan);
206 for (set = FcSetSystem; set <= FcSetApplication; set++)
207 if (config->fonts[set])
208 FcFontSetDestroy (config->fonts[set]);
211 FcMemFree (FC_MEM_CONFIG, sizeof (FcConfig));
215 * Add cache to configuration, adding fonts and directories
219 FcConfigAddCache (FcConfig *config, FcCache *cache,
220 FcSetName set, FcStrSet *dirSet)
229 fs = FcCacheSet (cache);
234 for (i = 0; i < fs->nfont; i++)
236 FcPattern *font = FcFontSetFont (fs, i);
240 * Check to see if font is banned by filename
242 if (FcPatternObjectGetString (font, FC_FILE_OBJECT,
243 0, &font_file) == FcResultMatch &&
244 !FcConfigAcceptFilename (config, font_file))
250 * Check to see if font is banned by pattern
252 if (!FcConfigAcceptFont (config, font))
256 FcFontSetAdd (config->fonts[set], font);
258 FcDirCacheReference (cache, nref);
264 dirs = FcCacheDirs (cache);
267 for (i = 0; i < cache->dirs_count; i++)
269 FcChar8 *dir = FcOffsetToPtr (dirs, dirs[i], FcChar8);
270 if (FcConfigAcceptFilename (config, dir))
271 FcStrSetAddFilename (dirSet, dir);
278 FcConfigAddDirList (FcConfig *config, FcSetName set, FcStrSet *dirSet)
284 dirlist = FcStrListCreate (dirSet);
288 while ((dir = FcStrListNext (dirlist)))
290 if (FcDebug () & FC_DBG_FONTSET)
291 printf ("adding fonts from%s\n", dir);
292 cache = FcDirCacheRead (dir, FcFalse, config);
295 FcConfigAddCache (config, cache, set, dirSet);
296 FcDirCacheUnload (cache);
298 FcStrListDone (dirlist);
303 * Scan the current list of directories in the configuration
304 * and build the set of available fonts.
308 FcConfigBuildFonts (FcConfig *config)
314 config = FcConfigGetCurrent ();
319 fonts = FcFontSetCreate ();
323 FcConfigSetFonts (config, fonts, FcSetSystem);
325 if (!FcConfigAddDirList (config, FcSetSystem, config->fontDirs))
327 if (FcDebug () & FC_DBG_FONTSET)
328 FcFontSetPrint (fonts);
333 FcConfigSetCurrent (FcConfig *config)
335 if (config == _fcConfig)
339 if (!FcConfigBuildFonts (config))
343 FcConfigDestroy (_fcConfig);
349 FcConfigGetCurrent (void)
358 FcConfigAddConfigDir (FcConfig *config,
361 return FcStrSetAddFilename (config->configDirs, d);
365 FcConfigGetConfigDirs (FcConfig *config)
369 config = FcConfigGetCurrent ();
373 return FcStrListCreate (config->configDirs);
377 FcConfigAddFontDir (FcConfig *config,
380 return FcStrSetAddFilename (config->fontDirs, d);
384 FcConfigAddDir (FcConfig *config,
387 return (FcConfigAddConfigDir (config, d) &&
388 FcConfigAddFontDir (config, d));
392 FcConfigGetFontDirs (FcConfig *config)
396 config = FcConfigGetCurrent ();
400 return FcStrListCreate (config->fontDirs);
404 FcConfigAddCacheDir (FcConfig *config,
407 return FcStrSetAddFilename (config->cacheDirs, d);
411 FcConfigGetCacheDirs (FcConfig *config)
415 config = FcConfigGetCurrent ();
419 return FcStrListCreate (config->cacheDirs);
423 FcConfigAddConfigFile (FcConfig *config,
427 FcChar8 *file = FcConfigFilename (f);
432 ret = FcStrSetAdd (config->configFiles, file);
438 FcConfigGetConfigFiles (FcConfig *config)
442 config = FcConfigGetCurrent ();
446 return FcStrListCreate (config->configFiles);
450 FcConfigGetCache (FcConfig *config)
456 FcConfigGetFonts (FcConfig *config,
461 config = FcConfigGetCurrent ();
465 return config->fonts[set];
469 FcConfigSetFonts (FcConfig *config,
473 if (config->fonts[set])
474 FcFontSetDestroy (config->fonts[set]);
475 config->fonts[set] = fonts;
479 FcConfigGetBlanks (FcConfig *config)
483 config = FcConfigGetCurrent ();
487 return config->blanks;
491 FcConfigAddBlank (FcConfig *config,
494 FcBlanks *b, *freeme = 0;
499 freeme = b = FcBlanksCreate ();
503 if (!FcBlanksAdd (b, blank))
506 FcBlanksDestroy (freeme);
514 FcConfigGetRescanInterval (FcConfig *config)
518 config = FcConfigGetCurrent ();
522 return config->rescanInterval;
526 FcConfigSetRescanInterval (FcConfig *config, int rescanInterval)
530 config = FcConfigGetCurrent ();
534 config->rescanInterval = rescanInterval;
539 * A couple of typos escaped into the library
542 FcConfigGetRescanInverval (FcConfig *config)
544 return FcConfigGetRescanInterval (config);
548 FcConfigSetRescanInverval (FcConfig *config, int rescanInterval)
550 return FcConfigSetRescanInterval (config, rescanInterval);
555 FcConfigAddEdit (FcConfig *config,
560 FcSubst *subst, **prev;
566 prev = &config->substPattern;
569 prev = &config->substFont;
572 prev = &config->substScan;
577 subst = (FcSubst *) malloc (sizeof (FcSubst));
580 FcMemAlloc (FC_MEM_SUBST, sizeof (FcSubst));
581 for (; *prev; prev = &(*prev)->next);
587 for (t = test; t; t = t->next)
589 if (t->kind == FcMatchDefault)
593 if (config->maxObjects < num)
594 config->maxObjects = num;
595 if (FcDebug () & FC_DBG_EDIT)
597 printf ("Add Subst ");
598 FcSubstPrint (subst);
603 typedef struct _FcSubState {
609 FcConfigPromote (FcValue v, FcValue u)
611 if (v.type == FcTypeInteger)
613 v.type = FcTypeDouble;
614 v.u.d = (double) v.u.i;
616 else if (v.type == FcTypeVoid && u.type == FcTypeMatrix)
618 v.u.m = &FcIdentityMatrix;
619 v.type = FcTypeMatrix;
621 else if (v.type == FcTypeString && u.type == FcTypeLangSet)
623 v.u.l = FcLangSetPromote (v.u.s);
624 v.type = FcTypeLangSet;
630 FcConfigCompareValue (const FcValue *left_o,
632 const FcValue *right_o)
634 FcValue left = FcValueCanonicalize(left_o);
635 FcValue right = FcValueCanonicalize(right_o);
636 FcBool ret = FcFalse;
638 left = FcConfigPromote (left, right);
639 right = FcConfigPromote (right, left);
640 if (left.type == right.type)
644 break; /* FcConfigPromote prevents this from happening */
650 ret = left.u.d == right.u.d;
653 case FcOpNotContains:
654 ret = left.u.d != right.u.d;
657 ret = left.u.d < right.u.d;
660 ret = left.u.d <= right.u.d;
663 ret = left.u.d > right.u.d;
666 ret = left.u.d >= right.u.d;
677 ret = left.u.b == right.u.b;
680 case FcOpNotContains:
681 ret = left.u.b != right.u.b;
691 ret = FcStrCmpIgnoreCase (left.u.s, right.u.s) == 0;
694 ret = FcStrStrIgnoreCase (left.u.s, right.u.s) != 0;
697 ret = FcStrCmpIgnoreCase (left.u.s, right.u.s) != 0;
699 case FcOpNotContains:
700 ret = FcStrCmpIgnoreCase (left.u.s, right.u.s) == 0;
711 ret = FcMatrixEqual (left.u.m, right.u.m);
714 case FcOpNotContains:
715 ret = !FcMatrixEqual (left.u.m, right.u.m);
725 /* left contains right if right is a subset of left */
726 ret = FcCharSetIsSubset (right.u.c, left.u.c);
728 case FcOpNotContains:
729 /* left contains right if right is a subset of left */
730 ret = !FcCharSetIsSubset (right.u.c, left.u.c);
733 ret = FcCharSetEqual (left.u.c, right.u.c);
736 ret = !FcCharSetEqual (left.u.c, right.u.c);
746 ret = FcLangSetContains (left.u.l, right.u.l);
748 case FcOpNotContains:
749 ret = !FcLangSetContains (left.u.l, right.u.l);
752 ret = FcLangSetEqual (left.u.l, right.u.l);
755 ret = !FcLangSetEqual (left.u.l, right.u.l);
777 ret = left.u.f == right.u.f;
780 case FcOpNotContains:
781 ret = left.u.f != right.u.f;
791 if (op == FcOpNotEqual || op == FcOpNotContains)
798 #define _FcDoubleFloor(d) ((int) (d))
799 #define _FcDoubleCeil(d) ((double) (int) (d) == (d) ? (int) (d) : (int) ((d) + 1))
800 #define FcDoubleFloor(d) ((d) >= 0 ? _FcDoubleFloor(d) : -_FcDoubleCeil(-(d)))
801 #define FcDoubleCeil(d) ((d) >= 0 ? _FcDoubleCeil(d) : -_FcDoubleFloor(-(d)))
802 #define FcDoubleRound(d) FcDoubleFloor ((d) + 0.5)
803 #define FcDoubleTrunc(d) ((d) >= 0 ? _FcDoubleFloor (d) : -_FcDoubleFloor (-(d)))
806 FcConfigEvaluate (FcPattern *p, FcExpr *e)
815 v.type = FcTypeInteger;
819 v.type = FcTypeDouble;
823 v.type = FcTypeString;
824 v.u.s = FcStrStaticName(e->u.sval);
827 v.type = FcTypeMatrix;
832 v.type = FcTypeCharSet;
841 r = FcPatternObjectGet (p, e->u.object, 0, &v);
842 if (r != FcResultMatch)
847 if (FcNameConstant (e->u.constant, &v.u.i))
848 v.type = FcTypeInteger;
853 vl = FcConfigEvaluate (p, e->u.tree.left);
854 if (vl.type == FcTypeBool)
857 v = FcConfigEvaluate (p, e->u.tree.right->u.tree.left);
859 v = FcConfigEvaluate (p, e->u.tree.right->u.tree.right);
872 case FcOpNotContains:
874 vl = FcConfigEvaluate (p, e->u.tree.left);
875 vr = FcConfigEvaluate (p, e->u.tree.right);
877 v.u.b = FcConfigCompareValue (&vl, e->op, &vr);
887 vl = FcConfigEvaluate (p, e->u.tree.left);
888 vr = FcConfigEvaluate (p, e->u.tree.right);
889 vl = FcConfigPromote (vl, vr);
890 vr = FcConfigPromote (vr, vl);
891 if (vl.type == vr.type)
897 v.type = FcTypeDouble;
898 v.u.d = vl.u.d + vr.u.d;
901 v.type = FcTypeDouble;
902 v.u.d = vl.u.d - vr.u.d;
905 v.type = FcTypeDouble;
906 v.u.d = vl.u.d * vr.u.d;
909 v.type = FcTypeDouble;
910 v.u.d = vl.u.d / vr.u.d;
916 if (v.type == FcTypeDouble &&
917 v.u.d == (double) (int) v.u.d)
919 v.type = FcTypeInteger;
927 v.u.b = vl.u.b || vr.u.b;
931 v.u.b = vl.u.b && vr.u.b;
941 v.type = FcTypeString;
942 str = FcStrPlus (vl.u.s, vr.u.s);
943 v.u.s = FcStrStaticName (str);
957 v.type = FcTypeMatrix;
958 m = malloc (sizeof (FcMatrix));
961 FcMemAlloc (FC_MEM_MATRIX, sizeof (FcMatrix));
962 FcMatrixMultiply (m, vl.u.m, vr.u.m);
986 vl = FcConfigEvaluate (p, e->u.tree.left);
999 vl = FcConfigEvaluate (p, e->u.tree.left);
1005 v.type = FcTypeInteger;
1006 v.u.i = FcDoubleFloor (vl.u.d);
1009 v.type = FcTypeVoid;
1012 FcValueDestroy (vl);
1015 vl = FcConfigEvaluate (p, e->u.tree.left);
1021 v.type = FcTypeInteger;
1022 v.u.i = FcDoubleCeil (vl.u.d);
1025 v.type = FcTypeVoid;
1028 FcValueDestroy (vl);
1031 vl = FcConfigEvaluate (p, e->u.tree.left);
1037 v.type = FcTypeInteger;
1038 v.u.i = FcDoubleRound (vl.u.d);
1041 v.type = FcTypeVoid;
1044 FcValueDestroy (vl);
1047 vl = FcConfigEvaluate (p, e->u.tree.left);
1053 v.type = FcTypeInteger;
1054 v.u.i = FcDoubleTrunc (vl.u.d);
1057 v.type = FcTypeVoid;
1060 FcValueDestroy (vl);
1063 v.type = FcTypeVoid;
1069 static FcValueList *
1070 FcConfigMatchValueList (FcPattern *p,
1072 FcValueList *values)
1074 FcValueList *ret = 0;
1075 FcExpr *e = t->expr;
1081 /* Compute the value of the match expression */
1082 if (e->op == FcOpComma)
1084 value = FcConfigEvaluate (p, e->u.tree.left);
1085 e = e->u.tree.right;
1089 value = FcConfigEvaluate (p, e);
1093 for (v = values; v; v = FcValueListNext(v))
1095 /* Compare the pattern value to the match expression value */
1096 if (FcConfigCompareValue (&v->value, t->op, &value))
1103 if (t->qual == FcQualAll)
1110 FcValueDestroy (value);
1115 static FcValueList *
1116 FcConfigValues (FcPattern *p, FcExpr *e, FcValueBinding binding)
1122 l = (FcValueList *) malloc (sizeof (FcValueList));
1125 FcMemAlloc (FC_MEM_VALLIST, sizeof (FcValueList));
1126 if (e->op == FcOpComma)
1128 l->value = FcConfigEvaluate (p, e->u.tree.left);
1129 l->next = FcConfigValues (p, e->u.tree.right, binding);
1133 l->value = FcConfigEvaluate (p, e);
1136 l->binding = binding;
1137 if (l->value.type == FcTypeVoid)
1139 FcValueList *next = FcValueListNext(l);
1141 FcMemFree (FC_MEM_VALLIST, sizeof (FcValueList));
1150 FcConfigAdd (FcValueListPtr *head,
1151 FcValueList *position,
1155 FcValueListPtr *prev, last, v;
1156 FcValueBinding sameBinding;
1159 sameBinding = position->binding;
1161 sameBinding = FcValueBindingWeak;
1162 for (v = new; v != NULL; v = FcValueListNext(v))
1163 if (v->binding == FcValueBindingSame)
1164 v->binding = sameBinding;
1168 prev = &position->next;
1170 for (prev = head; *prev != NULL;
1171 prev = &(*prev)->next)
1178 for (prev = head; *prev != NULL;
1179 prev = &(*prev)->next)
1181 if (*prev == position)
1188 if (FcDebug () & FC_DBG_EDIT)
1191 printf ("position not on list\n");
1195 if (FcDebug () & FC_DBG_EDIT)
1197 printf ("%s list before ", append ? "Append" : "Prepend");
1198 FcValueListPrint (*head);
1205 while (last->next != NULL)
1212 if (FcDebug () & FC_DBG_EDIT)
1214 printf ("%s list after ", append ? "Append" : "Prepend");
1215 FcValueListPrint (*head);
1223 FcConfigDel (FcValueListPtr *head,
1224 FcValueList *position)
1226 FcValueListPtr *prev;
1228 for (prev = head; *prev != NULL; prev = &(*prev)->next)
1230 if (*prev == position)
1232 *prev = position->next;
1233 position->next = NULL;
1234 FcValueListDestroy (position);
1241 FcConfigPatternAdd (FcPattern *p,
1248 FcPatternElt *e = FcPatternObjectInsertElt (p, object);
1252 FcConfigAdd (&e->values, 0, append, list);
1257 * Delete all values associated with a field
1260 FcConfigPatternDel (FcPattern *p,
1263 FcPatternElt *e = FcPatternObjectFindElt (p, object);
1266 while (e->values != NULL)
1267 FcConfigDel (&e->values, e->values);
1271 FcConfigPatternCanon (FcPattern *p,
1274 FcPatternElt *e = FcPatternObjectFindElt (p, object);
1277 if (e->values == NULL)
1278 FcPatternObjectDel (p, object);
1282 FcConfigSubstituteWithPat (FcConfig *config,
1297 config = FcConfigGetCurrent ();
1303 case FcMatchPattern:
1304 s = config->substPattern;
1307 s = config->substFont;
1310 s = config->substScan;
1316 st = (FcSubState *) malloc (config->maxObjects * sizeof (FcSubState));
1317 if (!st && config->maxObjects)
1319 FcMemAlloc (FC_MEM_SUBSTATE, config->maxObjects * sizeof (FcSubState));
1321 if (FcDebug () & FC_DBG_EDIT)
1323 printf ("FcConfigSubstitute ");
1326 for (; s; s = s->next)
1329 * Check the tests to see if
1330 * they all match the pattern
1332 for (t = s->test, i = 0; t; t = t->next, i++)
1334 if (FcDebug () & FC_DBG_EDIT)
1336 printf ("FcConfigSubstitute test ");
1340 if (kind == FcMatchFont && t->kind == FcMatchPattern)
1345 st[i].elt = FcPatternObjectFindElt (m, t->object);
1349 * If there's no such field in the font,
1350 * then FcQualAll matches while FcQualAny does not
1354 if (t->qual == FcQualAll)
1363 * Check to see if there is a match, mark the location
1364 * to apply match-relative edits
1366 st[i].value = FcConfigMatchValueList (m, t, st[i].elt->values);
1369 if (t->qual == FcQualFirst && st[i].value != st[i].elt->values)
1371 if (t->qual == FcQualNotFirst && st[i].value == st[i].elt->values)
1376 if (FcDebug () & FC_DBG_EDIT)
1377 printf ("No match\n");
1380 if (FcDebug () & FC_DBG_EDIT)
1382 printf ("Substitute ");
1385 for (e = s->edit; e; e = e->next)
1388 * Evaluate the list of expressions
1390 l = FcConfigValues (p, e->expr, e->binding);
1392 * Locate any test associated with this field, skipping
1393 * tests associated with the pattern when substituting in
1396 for (t = s->test, i = 0; t; t = t->next, i++)
1398 if ((t->kind == FcMatchFont || kind == FcMatchPattern) &&
1399 t->object == e->object)
1402 * KLUDGE - the pattern may have been reallocated or
1403 * things may have been inserted or deleted above
1404 * this element by other edits. Go back and find
1407 if (e != s->edit && st[i].elt)
1408 st[i].elt = FcPatternObjectFindElt (p, t->object);
1417 * If there was a test, then replace the matched
1418 * value with the new list of values
1422 FcValueList *thisValue = st[i].value;
1423 FcValueList *nextValue = thisValue;
1426 * Append the new list of values after the current value
1428 FcConfigAdd (&st[i].elt->values, thisValue, FcTrue, l);
1430 * Delete the marked value
1433 FcConfigDel (&st[i].elt->values, thisValue);
1435 * Adjust any pointers into the value list to ensure
1436 * future edits occur at the same place
1438 for (t = s->test, i = 0; t; t = t->next, i++)
1440 if (st[i].value == thisValue)
1441 st[i].value = nextValue;
1445 /* fall through ... */
1446 case FcOpAssignReplace:
1448 * Delete all of the values and insert
1451 FcConfigPatternDel (p, e->object);
1452 FcConfigPatternAdd (p, e->object, l, FcTrue);
1454 * Adjust any pointers into the value list as they no
1455 * longer point to anything valid
1459 FcPatternElt *thisElt = st[i].elt;
1460 for (t = s->test, i = 0; t; t = t->next, i++)
1462 if (st[i].elt == thisElt)
1470 FcConfigAdd (&st[i].elt->values, st[i].value, FcFalse, l);
1473 /* fall through ... */
1474 case FcOpPrependFirst:
1475 FcConfigPatternAdd (p, e->object, l, FcFalse);
1480 FcConfigAdd (&st[i].elt->values, st[i].value, FcTrue, l);
1483 /* fall through ... */
1484 case FcOpAppendLast:
1485 FcConfigPatternAdd (p, e->object, l, FcTrue);
1488 FcValueListDestroy (l);
1493 * Now go through the pattern and eliminate
1494 * any properties without data
1496 for (e = s->edit; e; e = e->next)
1497 FcConfigPatternCanon (p, e->object);
1499 if (FcDebug () & FC_DBG_EDIT)
1501 printf ("FcConfigSubstitute edit");
1505 FcMemFree (FC_MEM_SUBSTATE, config->maxObjects * sizeof (FcSubState));
1507 if (FcDebug () & FC_DBG_EDIT)
1509 printf ("FcConfigSubstitute done");
1516 FcConfigSubstitute (FcConfig *config,
1520 return FcConfigSubstituteWithPat (config, p, 0, kind);
1523 #if defined (_WIN32) && (defined (PIC) || defined (DLL_EXPORT))
1525 static FcChar8 fontconfig_path[1000] = "";
1528 DllMain (HINSTANCE hinstDLL,
1534 switch (fdwReason) {
1535 case DLL_PROCESS_ATTACH:
1536 if (!GetModuleFileName ((HMODULE) hinstDLL, fontconfig_path,
1537 sizeof (fontconfig_path)))
1540 /* If the fontconfig DLL is in a "bin" or "lib" subfolder,
1541 * assume it's a Unix-style installation tree, and use
1542 * "etc/fonts" in there as FONTCONFIG_PATH. Otherwise use the
1543 * folder where the DLL is as FONTCONFIG_PATH.
1545 p = strrchr (fontconfig_path, '\\');
1549 p = strrchr (fontconfig_path, '\\');
1550 if (p && (FcStrCmpIgnoreCase (p + 1, "bin") == 0 ||
1551 FcStrCmpIgnoreCase (p + 1, "lib") == 0))
1553 strcat (fontconfig_path, "\\etc\\fonts");
1556 fontconfig_path[0] = '\0';
1564 #undef FONTCONFIG_PATH
1565 #define FONTCONFIG_PATH fontconfig_path
1567 #else /* !(_WIN32 && PIC) */
1569 #endif /* !(_WIN32 && PIC) */
1571 #ifndef FONTCONFIG_FILE
1572 #define FONTCONFIG_FILE "fonts.conf"
1576 FcConfigFileExists (const FcChar8 *dir, const FcChar8 *file)
1581 dir = (FcChar8 *) "";
1582 path = malloc (strlen ((char *) dir) + 1 + strlen ((char *) file) + 1);
1586 strcpy ((char *) path, (const char *) dir);
1587 /* make sure there's a single separator */
1589 if ((!path[0] || (path[strlen((char *) path)-1] != '/' &&
1590 path[strlen((char *) path)-1] != '\\')) &&
1593 (isalpha (file[0]) && file[1] == ':' && (file[2] == '/' || file[2] == '\\'))))
1594 strcat ((char *) path, "\\");
1596 if ((!path[0] || path[strlen((char *) path)-1] != '/') && file[0] != '/')
1597 strcat ((char *) path, "/");
1599 strcat ((char *) path, (char *) file);
1601 FcMemAlloc (FC_MEM_STRING, strlen ((char *) path) + 1);
1602 if (access ((char *) path, R_OK) == 0)
1610 FcConfigGetPath (void)
1613 FcChar8 *env, *e, *colon;
1618 npath = 2; /* default dir + null */
1619 env = (FcChar8 *) getenv ("FONTCONFIG_PATH");
1625 if (*e++ == FC_SEARCH_PATH_SEPARATOR)
1628 path = calloc (npath, sizeof (FcChar8 *));
1638 colon = (FcChar8 *) strchr ((char *) e, FC_SEARCH_PATH_SEPARATOR);
1640 colon = e + strlen ((char *) e);
1641 path[i] = malloc (colon - e + 1);
1644 strncpy ((char *) path[i], (const char *) e, colon - e);
1645 path[i][colon - e] = '\0';
1654 dir = (FcChar8 *) FONTCONFIG_PATH;
1655 path[i] = malloc (strlen ((char *) dir) + 1);
1658 strcpy ((char *) path[i], (const char *) dir);
1662 for (i = 0; path[i]; i++)
1670 FcConfigFreePath (FcChar8 **path)
1674 for (p = path; *p; p++)
1679 static FcBool _FcConfigHomeEnabled = FcTrue;
1684 if (_FcConfigHomeEnabled)
1686 char *home = getenv ("HOME");
1690 home = getenv ("USERPROFILE");
1693 return (FcChar8 *) home;
1699 FcConfigEnableHome (FcBool enable)
1701 FcBool prev = _FcConfigHomeEnabled;
1702 _FcConfigHomeEnabled = enable;
1707 FcConfigFilename (const FcChar8 *url)
1709 FcChar8 *file, *dir, **path, **p;
1713 url = (FcChar8 *) getenv ("FONTCONFIG_FILE");
1715 url = (FcChar8 *) FONTCONFIG_FILE;
1720 if (isalpha (*url) &&
1722 (url[2] == '/' || url[2] == '\\'))
1728 dir = FcConfigHome ();
1730 file = FcConfigFileExists (dir, url + 1);
1739 file = FcConfigFileExists (0, url);
1742 path = FcConfigGetPath ();
1745 for (p = path; *p; p++)
1747 file = FcConfigFileExists (*p, url);
1751 FcConfigFreePath (path);
1758 * Manage the application-specific fonts
1762 FcConfigAppFontAddFile (FcConfig *config,
1763 const FcChar8 *file)
1772 config = FcConfigGetCurrent ();
1777 subdirs = FcStrSetCreate ();
1781 set = FcConfigGetFonts (config, FcSetApplication);
1784 set = FcFontSetCreate ();
1787 FcStrSetDestroy (subdirs);
1790 FcConfigSetFonts (config, set, FcSetApplication);
1793 if (!FcFileScanConfig (set, subdirs, config->blanks, file, config))
1795 FcStrSetDestroy (subdirs);
1798 if ((sublist = FcStrListCreate (subdirs)))
1800 while ((subdir = FcStrListNext (sublist)))
1802 FcConfigAppFontAddDir (config, subdir);
1804 FcStrListDone (sublist);
1806 FcStrSetDestroy (subdirs);
1811 FcConfigAppFontAddDir (FcConfig *config,
1819 config = FcConfigGetCurrent ();
1824 dirs = FcStrSetCreate ();
1828 set = FcConfigGetFonts (config, FcSetApplication);
1831 set = FcFontSetCreate ();
1834 FcStrSetDestroy (dirs);
1837 FcConfigSetFonts (config, set, FcSetApplication);
1840 FcStrSetAddFilename (dirs, dir);
1842 if (!FcConfigAddDirList (config, FcSetApplication, dirs))
1844 FcStrSetDestroy (dirs);
1847 FcStrSetDestroy (dirs);
1852 FcConfigAppFontClear (FcConfig *config)
1856 config = FcConfigGetCurrent ();
1861 FcConfigSetFonts (config, 0, FcSetApplication);
1865 * Manage filename-based font source selectors
1869 FcConfigGlobAdd (FcConfig *config,
1870 const FcChar8 *glob,
1873 FcStrSet *set = accept ? config->acceptGlobs : config->rejectGlobs;
1875 return FcStrSetAdd (set, glob);
1879 FcConfigGlobMatch (const FcChar8 *glob,
1880 const FcChar8 *string)
1884 while ((c = *glob++))
1888 /* short circuit common case */
1891 /* short circuit another common case */
1892 if (strchr ((char *) glob, '*') == 0)
1893 string += strlen ((char *) string) - strlen ((char *) glob);
1896 if (FcConfigGlobMatch (glob, string))
1902 if (*string++ == '\0')
1911 return *string == '\0';
1915 FcConfigGlobsMatch (const FcStrSet *globs,
1916 const FcChar8 *string)
1920 for (i = 0; i < globs->num; i++)
1921 if (FcConfigGlobMatch (globs->strs[i], string))
1927 FcConfigAcceptFilename (FcConfig *config,
1928 const FcChar8 *filename)
1930 if (FcConfigGlobsMatch (config->acceptGlobs, filename))
1932 if (FcConfigGlobsMatch (config->rejectGlobs, filename))
1938 * Manage font-pattern based font source selectors
1942 FcConfigPatternsAdd (FcConfig *config,
1946 FcFontSet *set = accept ? config->acceptPatterns : config->rejectPatterns;
1948 return FcFontSetAdd (set, pattern);
1952 FcConfigPatternsMatch (const FcFontSet *patterns,
1953 const FcPattern *font)
1957 for (i = 0; i < patterns->nfont; i++)
1958 if (FcListPatternMatchAny (patterns->fonts[i], font))
1964 FcConfigAcceptFont (FcConfig *config,
1965 const FcPattern *font)
1967 if (FcConfigPatternsMatch (config->acceptPatterns, font))
1969 if (FcConfigPatternsMatch (config->rejectPatterns, font))
1974 #include "fcaliastail.h"