2 * $XFree86: xc/lib/fontconfig/src/fccfg.c,v 1.23 2002/08/31 22:17:32 keithp Exp $
4 * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
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.
35 config
= malloc (sizeof (FcConfig
));
38 FcMemAlloc (FC_MEM_CONFIG
, sizeof (FcConfig
));
40 config
->configDirs
= FcStrSetCreate ();
41 if (!config
->configDirs
)
44 config
->configFiles
= FcStrSetCreate ();
45 if (!config
->configFiles
)
48 config
->fontDirs
= FcStrSetCreate ();
49 if (!config
->fontDirs
)
54 if (!FcConfigSetCache (config
, (FcChar8
*) ("~/" FC_USER_CACHE_FILE
)))
59 config
->substPattern
= 0;
60 config
->substFont
= 0;
61 config
->maxObjects
= 0;
62 for (set
= FcSetSystem
; set
<= FcSetApplication
; set
++)
63 config
->fonts
[set
] = 0;
65 config
->rescanTime
= time(0);
66 config
->rescanInterval
= 30;
71 FcStrSetDestroy (config
->fontDirs
);
73 FcStrSetDestroy (config
->configFiles
);
75 FcStrSetDestroy (config
->configDirs
);
78 FcMemFree (FC_MEM_CONFIG
, sizeof (FcConfig
));
83 typedef struct _FcFileTime
{
89 FcConfigNewestFile (FcStrSet
*files
)
91 FcStrList
*list
= FcStrListCreate (files
);
92 FcFileTime newest
= { 0, FcFalse
};
98 while ((file
= FcStrListNext (list
)))
99 if (stat ((char *) file
, &statb
) == 0)
100 if (!newest
.set
|| statb
.st_mtime
- newest
.time
> 0)
101 newest
.time
= statb
.st_mtime
;
102 FcStrListDone (list
);
108 FcConfigUptoDate (FcConfig
*config
)
110 FcFileTime config_time
, font_time
;
111 time_t now
= time(0);
114 config
= FcConfigGetCurrent ();
118 config_time
= FcConfigNewestFile (config
->configFiles
);
119 font_time
= FcConfigNewestFile (config
->configDirs
);
120 if ((config_time
.set
&& config_time
.time
- config
->rescanTime
> 0) ||
121 (font_time
.set
&& font_time
.time
- config
->rescanTime
) > 0)
125 config
->rescanTime
= now
;
130 FcSubstDestroy (FcSubst
*s
)
137 FcTestDestroy (s
->test
);
138 FcEditDestroy (s
->edit
);
144 FcConfigDestroy (FcConfig
*config
)
148 if (config
== _fcConfig
)
151 FcStrSetDestroy (config
->configDirs
);
152 FcStrSetDestroy (config
->fontDirs
);
153 FcStrSetDestroy (config
->configFiles
);
155 FcStrFree (config
->cache
);
157 FcSubstDestroy (config
->substPattern
);
158 FcSubstDestroy (config
->substFont
);
159 for (set
= FcSetSystem
; set
<= FcSetApplication
; set
++)
160 if (config
->fonts
[set
])
161 FcFontSetDestroy (config
->fonts
[set
]);
163 FcMemFree (FC_MEM_CONFIG
, sizeof (FcConfig
));
167 * Scan the current list of directories in the configuration
168 * and build the set of available fonts. Update the
169 * per-user cache file to reflect the new configuration
173 FcConfigBuildFonts (FcConfig
*config
)
176 FcGlobalCache
*cache
;
180 fonts
= FcFontSetCreate ();
184 cache
= FcGlobalCacheCreate ();
188 FcGlobalCacheLoad (cache
, config
->cache
);
190 list
= FcConfigGetFontDirs (config
);
194 while ((dir
= FcStrListNext (list
)))
196 if (FcDebug () & FC_DBG_FONTSET
)
197 printf ("scan dir %s\n", dir
);
198 FcDirScan (fonts
, config
->fontDirs
, cache
, config
->blanks
, dir
, FcFalse
);
201 FcStrListDone (list
);
203 if (FcDebug () & FC_DBG_FONTSET
)
204 FcFontSetPrint (fonts
);
206 FcGlobalCacheSave (cache
, config
->cache
);
207 FcGlobalCacheDestroy (cache
);
209 FcConfigSetFonts (config
, fonts
, FcSetSystem
);
213 FcFontSetDestroy (fonts
);
219 FcConfigSetCurrent (FcConfig
*config
)
222 if (!FcConfigBuildFonts (config
))
226 FcConfigDestroy (_fcConfig
);
232 FcConfigGetCurrent (void)
241 FcConfigAddConfigDir (FcConfig
*config
,
244 return FcStrSetAddFilename (config
->configDirs
, d
);
248 FcConfigGetConfigDirs (FcConfig
*config
)
252 config
= FcConfigGetCurrent ();
256 return FcStrListCreate (config
->configDirs
);
260 FcConfigAddFontDir (FcConfig
*config
,
263 return FcStrSetAddFilename (config
->fontDirs
, d
);
267 FcConfigAddDir (FcConfig
*config
,
270 return (FcConfigAddConfigDir (config
, d
) &&
271 FcConfigAddFontDir (config
, d
));
275 FcConfigGetFontDirs (FcConfig
*config
)
279 config
= FcConfigGetCurrent ();
283 return FcStrListCreate (config
->fontDirs
);
287 FcConfigAddConfigFile (FcConfig
*config
,
291 FcChar8
*file
= FcConfigFilename (f
);
296 ret
= FcStrSetAdd (config
->configFiles
, file
);
302 FcConfigGetConfigFiles (FcConfig
*config
)
306 config
= FcConfigGetCurrent ();
310 return FcStrListCreate (config
->configFiles
);
314 FcConfigSetCache (FcConfig
*config
,
317 FcChar8
*new = FcStrCopyFilename (c
);
322 FcStrFree (config
->cache
);
328 FcConfigGetCache (FcConfig
*config
)
332 config
= FcConfigGetCurrent ();
336 return config
->cache
;
340 FcConfigGetFonts (FcConfig
*config
,
345 config
= FcConfigGetCurrent ();
349 return config
->fonts
[set
];
353 FcConfigSetFonts (FcConfig
*config
,
357 if (config
->fonts
[set
])
358 FcFontSetDestroy (config
->fonts
[set
]);
359 config
->fonts
[set
] = fonts
;
365 FcConfigGetBlanks (FcConfig
*config
)
369 config
= FcConfigGetCurrent ();
373 return config
->blanks
;
377 FcConfigAddBlank (FcConfig
*config
,
385 b
= FcBlanksCreate ();
389 if (!FcBlanksAdd (b
, blank
))
396 FcConfigGetRescanInverval (FcConfig
*config
)
400 config
= FcConfigGetCurrent ();
404 return config
->rescanInterval
;
408 FcConfigSetRescanInverval (FcConfig
*config
, int rescanInterval
)
412 config
= FcConfigGetCurrent ();
416 config
->rescanInterval
= rescanInterval
;
421 FcConfigAddEdit (FcConfig
*config
,
426 FcSubst
*subst
, **prev
;
430 subst
= (FcSubst
*) malloc (sizeof (FcSubst
));
433 FcMemAlloc (FC_MEM_SUBST
, sizeof (FcSubst
));
434 if (kind
== FcMatchPattern
)
435 prev
= &config
->substPattern
;
437 prev
= &config
->substFont
;
438 for (; *prev
; prev
= &(*prev
)->next
);
444 for (t
= test
; t
; t
= t
->next
)
446 if (t
->kind
== FcMatchDefault
)
450 if (config
->maxObjects
< num
)
451 config
->maxObjects
= num
;
452 if (FcDebug () & FC_DBG_EDIT
)
454 printf ("Add Subst ");
455 FcSubstPrint (subst
);
460 typedef struct _FcSubState
{
466 FcConfigPromote (FcValue v
, FcValue u
)
468 if (v
.type
== FcTypeInteger
)
470 v
.type
= FcTypeDouble
;
471 v
.u
.d
= (double) v
.u
.i
;
473 else if (v
.type
== FcTypeVoid
&& u
.type
== FcTypeMatrix
)
475 v
.u
.m
= &FcIdentityMatrix
;
476 v
.type
= FcTypeMatrix
;
478 else if (v
.type
== FcTypeString
&& u
.type
== FcTypeLangSet
)
480 v
.u
.l
= FcLangSetPromote (v
.u
.s
);
481 v
.type
= FcTypeLangSet
;
487 FcConfigCompareValue (const FcValue m_o
,
493 FcBool ret
= FcFalse
;
495 m
= FcConfigPromote (m
, v
);
496 v
= FcConfigPromote (v
, m
);
497 if (m
.type
== v
.type
)
501 break; /* FcConfigPromote prevents this from happening */
506 ret
= m
.u
.d
== v
.u
.d
;
509 case FcOpNotContains
:
510 ret
= m
.u
.d
!= v
.u
.d
;
516 ret
= m
.u
.d
<= v
.u
.d
;
522 ret
= m
.u
.d
>= v
.u
.d
;
532 ret
= m
.u
.b
== v
.u
.b
;
535 case FcOpNotContains
:
536 ret
= m
.u
.b
!= v
.u
.b
;
546 ret
= FcStrCmpIgnoreCase (m
.u
.s
, v
.u
.s
) == 0;
549 case FcOpNotContains
:
550 ret
= FcStrCmpIgnoreCase (m
.u
.s
, v
.u
.s
) != 0;
560 ret
= FcMatrixEqual (m
.u
.m
, v
.u
.m
);
563 case FcOpNotContains
:
564 ret
= !FcMatrixEqual (m
.u
.m
, v
.u
.m
);
573 /* m contains v if v is a subset of m */
574 ret
= FcCharSetIsSubset (v
.u
.c
, m
.u
.c
);
576 case FcOpNotContains
:
577 /* m contains v if v is a subset of m */
578 ret
= !FcCharSetIsSubset (v
.u
.c
, m
.u
.c
);
581 ret
= FcCharSetEqual (m
.u
.c
, v
.u
.c
);
584 ret
= !FcCharSetEqual (m
.u
.c
, v
.u
.c
);
593 ret
= FcLangSetCompare (v
.u
.l
, m
.u
.l
) != FcLangDifferentLang
;
595 case FcOpNotContains
:
596 ret
= FcLangSetCompare (v
.u
.l
, m
.u
.l
) == FcLangDifferentLang
;
599 ret
= FcLangSetEqual (v
.u
.l
, m
.u
.l
);
602 ret
= !FcLangSetEqual (v
.u
.l
, m
.u
.l
);
622 ret
= m
.u
.f
== v
.u
.f
;
625 case FcOpNotContains
:
626 ret
= m
.u
.f
!= v
.u
.f
;
636 if (op
== FcOpNotEqual
|| op
== FcOpNotContains
)
644 FcConfigEvaluate (FcPattern
*p
, FcExpr
*e
)
652 v
.type
= FcTypeInteger
;
656 v
.type
= FcTypeDouble
;
660 v
.type
= FcTypeString
;
665 v
.type
= FcTypeMatrix
;
670 v
.type
= FcTypeCharSet
;
679 r
= FcPatternGet (p
, e
->u
.field
, 0, &v
);
680 if (r
!= FcResultMatch
)
684 if (FcNameConstant (e
->u
.constant
, &v
.u
.i
))
685 v
.type
= FcTypeInteger
;
690 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
691 if (vl
.type
== FcTypeBool
)
694 v
= FcConfigEvaluate (p
, e
->u
.tree
.right
->u
.tree
.left
);
696 v
= FcConfigEvaluate (p
, e
->u
.tree
.right
->u
.tree
.right
);
709 case FcOpNotContains
:
710 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
711 vr
= FcConfigEvaluate (p
, e
->u
.tree
.right
);
713 v
.u
.b
= FcConfigCompareValue (vl
, e
->op
, vr
);
723 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
724 vr
= FcConfigEvaluate (p
, e
->u
.tree
.right
);
725 vl
= FcConfigPromote (vl
, vr
);
726 vr
= FcConfigPromote (vr
, vl
);
727 if (vl
.type
== vr
.type
)
733 v
.type
= FcTypeDouble
;
734 v
.u
.d
= vl
.u
.d
+ vr
.u
.d
;
737 v
.type
= FcTypeDouble
;
738 v
.u
.d
= vl
.u
.d
- vr
.u
.d
;
741 v
.type
= FcTypeDouble
;
742 v
.u
.d
= vl
.u
.d
* vr
.u
.d
;
745 v
.type
= FcTypeDouble
;
746 v
.u
.d
= vl
.u
.d
/ vr
.u
.d
;
752 if (v
.type
== FcTypeDouble
&&
753 v
.u
.d
== (double) (int) v
.u
.d
)
755 v
.type
= FcTypeInteger
;
763 v
.u
.b
= vl
.u
.b
|| vr
.u
.b
;
767 v
.u
.b
= vl
.u
.b
&& vr
.u
.b
;
777 v
.type
= FcTypeString
;
778 v
.u
.s
= FcStrPlus (vl
.u
.s
, vr
.u
.s
);
790 v
.type
= FcTypeMatrix
;
791 m
= malloc (sizeof (FcMatrix
));
794 FcMemAlloc (FC_MEM_MATRIX
, sizeof (FcMatrix
));
795 FcMatrixMultiply (m
, vl
.u
.m
, vr
.u
.m
);
819 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
839 FcConfigMatchValueList (FcPattern
*p
,
843 FcValueList
*ret
= 0;
850 if (e
->op
== FcOpComma
)
852 value
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
857 value
= FcConfigEvaluate (p
, e
);
861 for (v
= values
; v
; v
= v
->next
)
863 if (FcConfigCompareValue (v
->value
, t
->op
, value
))
870 if (t
->qual
== FcQualAll
)
877 FcValueDestroy (value
);
883 FcConfigValues (FcPattern
*p
, FcExpr
*e
, FcValueBinding binding
)
889 l
= (FcValueList
*) malloc (sizeof (FcValueList
));
892 FcMemAlloc (FC_MEM_VALLIST
, sizeof (FcValueList
));
893 if (e
->op
== FcOpComma
)
895 l
->value
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
896 l
->next
= FcConfigValues (p
, e
->u
.tree
.right
, binding
);
900 l
->value
= FcConfigEvaluate (p
, e
);
903 l
->binding
= binding
;
904 while (l
&& l
->value
.type
== FcTypeVoid
)
906 FcValueList
*next
= l
->next
;
908 FcMemFree (FC_MEM_VALLIST
, sizeof (FcValueList
));
916 FcConfigAdd (FcValueList
**head
,
917 FcValueList
*position
,
921 FcValueList
**prev
, *last
, *v
;
922 FcValueBinding sameBinding
;
925 sameBinding
= position
->binding
;
927 sameBinding
= FcValueBindingWeak
;
928 for (v
= new; v
; v
= v
->next
)
929 if (v
->binding
== FcValueBindingSame
)
930 v
->binding
= sameBinding
;
934 prev
= &position
->next
;
936 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
943 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
945 if (*prev
== position
)
952 if (FcDebug () & FC_DBG_EDIT
)
955 printf ("position not on list\n");
959 if (FcDebug () & FC_DBG_EDIT
)
961 printf ("%s list before ", append
? "Append" : "Prepend");
962 FcValueListPrint (*head
);
976 if (FcDebug () & FC_DBG_EDIT
)
978 printf ("%s list after ", append
? "Append" : "Prepend");
979 FcValueListPrint (*head
);
987 FcConfigDel (FcValueList
**head
,
988 FcValueList
*position
)
992 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
994 if (*prev
== position
)
996 *prev
= position
->next
;
998 FcValueListDestroy (position
);
1005 FcConfigPatternAdd (FcPattern
*p
,
1012 FcPatternElt
*e
= FcPatternInsertElt (p
, object
);
1016 FcConfigAdd (&e
->values
, 0, append
, list
);
1021 * Delete all values associated with a field
1024 FcConfigPatternDel (FcPattern
*p
,
1027 FcPatternElt
*e
= FcPatternFindElt (p
, object
);
1031 FcConfigDel (&e
->values
, e
->values
);
1035 FcConfigPatternCanon (FcPattern
*p
,
1038 FcPatternElt
*e
= FcPatternFindElt (p
, object
);
1042 FcPatternDel (p
, object
);
1046 FcConfigSubstituteWithPat (FcConfig
*config
,
1061 config
= FcConfigGetCurrent ();
1066 st
= (FcSubState
*) malloc (config
->maxObjects
* sizeof (FcSubState
));
1067 if (!st
&& config
->maxObjects
)
1069 FcMemAlloc (FC_MEM_SUBSTATE
, config
->maxObjects
* sizeof (FcSubState
));
1071 if (FcDebug () & FC_DBG_EDIT
)
1073 printf ("FcConfigSubstitute ");
1076 if (kind
== FcMatchPattern
)
1077 s
= config
->substPattern
;
1079 s
= config
->substFont
;
1080 for (; s
; s
= s
->next
)
1083 * Check the tests to see if
1084 * they all match the pattern
1086 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1088 if (FcDebug () & FC_DBG_EDIT
)
1090 printf ("FcConfigSubstitute test ");
1094 if (kind
== FcMatchFont
&& t
->kind
== FcMatchPattern
)
1099 st
[i
].elt
= FcPatternFindElt (m
, t
->field
);
1103 * If there's no such field in the font,
1104 * then FcQualAll matches while FcQualAny does not
1108 if (t
->qual
== FcQualAll
)
1117 * Check to see if there is a match, mark the location
1118 * to apply match-relative edits
1120 st
[i
].value
= FcConfigMatchValueList (m
, t
, st
[i
].elt
->values
);
1123 if (t
->qual
== FcQualFirst
&& st
[i
].value
!= st
[i
].elt
->values
)
1125 if (t
->qual
== FcQualNotFirst
&& st
[i
].value
== st
[i
].elt
->values
)
1130 if (FcDebug () & FC_DBG_EDIT
)
1131 printf ("No match\n");
1134 if (FcDebug () & FC_DBG_EDIT
)
1136 printf ("Substitute ");
1139 for (e
= s
->edit
; e
; e
= e
->next
)
1142 * Evaluate the list of expressions
1144 l
= FcConfigValues (p
, e
->expr
, e
->binding
);
1146 * Locate any test associated with this field, skipping
1147 * tests associated with the pattern when substituting in
1150 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1152 if ((t
->kind
== FcMatchFont
|| kind
== FcMatchPattern
) &&
1153 !FcStrCmpIgnoreCase ((FcChar8
*) t
->field
,
1154 (FcChar8
*) e
->field
))
1164 * If there was a test, then replace the matched
1165 * value with the new list of values
1169 FcValueList
*thisValue
= st
[i
].value
;
1170 FcValueList
*nextValue
= thisValue
? thisValue
->next
: 0;
1173 * Append the new list of values after the current value
1175 FcConfigAdd (&st
[i
].elt
->values
, thisValue
, FcTrue
, l
);
1177 * Delete the marked value
1179 FcConfigDel (&st
[i
].elt
->values
, thisValue
);
1181 * Adjust any pointers into the value list to ensure
1182 * future edits occur at the same place
1184 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1186 if (st
[i
].value
== thisValue
)
1187 st
[i
].value
= nextValue
;
1191 /* fall through ... */
1192 case FcOpAssignReplace
:
1194 * Delete all of the values and insert
1197 FcConfigPatternDel (p
, e
->field
);
1198 FcConfigPatternAdd (p
, e
->field
, l
, FcTrue
);
1200 * Adjust any pointers into the value list as they no
1201 * longer point to anything valid
1205 FcPatternElt
*thisElt
= st
[i
].elt
;
1206 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1208 if (st
[i
].elt
== thisElt
)
1216 FcConfigAdd (&st
[i
].elt
->values
, st
[i
].value
, FcFalse
, l
);
1219 /* fall through ... */
1220 case FcOpPrependFirst
:
1221 FcConfigPatternAdd (p
, e
->field
, l
, FcFalse
);
1226 FcConfigAdd (&st
[i
].elt
->values
, st
[i
].value
, FcTrue
, l
);
1229 /* fall through ... */
1230 case FcOpAppendLast
:
1231 FcConfigPatternAdd (p
, e
->field
, l
, FcTrue
);
1238 * Now go through the pattern and eliminate
1239 * any properties without data
1241 for (e
= s
->edit
; e
; e
= e
->next
)
1242 FcConfigPatternCanon (p
, e
->field
);
1244 if (FcDebug () & FC_DBG_EDIT
)
1246 printf ("FcConfigSubstitute edit");
1250 FcMemFree (FC_MEM_SUBSTATE
, config
->maxObjects
* sizeof (FcSubState
));
1252 if (FcDebug () & FC_DBG_EDIT
)
1254 printf ("FcConfigSubstitute done");
1261 FcConfigSubstitute (FcConfig
*config
,
1265 return FcConfigSubstituteWithPat (config
, p
, 0, kind
);
1268 #ifndef FONTCONFIG_PATH
1269 #define FONTCONFIG_PATH "/etc/fonts"
1272 #ifndef FONTCONFIG_FILE
1273 #define FONTCONFIG_FILE "fonts.conf"
1277 FcConfigFileExists (const FcChar8
*dir
, const FcChar8
*file
)
1282 dir
= (FcChar8
*) "";
1283 path
= malloc (strlen ((char *) dir
) + 1 + strlen ((char *) file
) + 1);
1287 strcpy ((char *) path
, (const char *) dir
);
1288 /* make sure there's a single separating / */
1289 if ((!path
[0] || path
[strlen((char *) path
)-1] != '/') && file
[0] != '/')
1290 strcat ((char *) path
, "/");
1291 strcat ((char *) path
, (char *) file
);
1293 FcMemAlloc (FC_MEM_STRING
, strlen ((char *) path
) + 1);
1294 if (access ((char *) path
, R_OK
) == 0)
1302 FcConfigGetPath (void)
1305 FcChar8
*env
, *e
, *colon
;
1310 npath
= 2; /* default dir + null */
1311 env
= (FcChar8
*) getenv ("FONTCONFIG_PATH");
1320 path
= calloc (npath
, sizeof (FcChar8
*));
1330 colon
= (FcChar8
*) strchr ((char *) e
, ':');
1332 colon
= e
+ strlen ((char *) e
);
1333 path
[i
] = malloc (colon
- e
+ 1);
1336 strncpy ((char *) path
[i
], (const char *) e
, colon
- e
);
1337 path
[i
][colon
- e
] = '\0';
1346 dir
= (FcChar8
*) FONTCONFIG_PATH
;
1347 path
[i
] = malloc (strlen ((char *) dir
) + 1);
1350 strcpy ((char *) path
[i
], (const char *) dir
);
1354 for (i
= 0; path
[i
]; i
++)
1362 FcConfigFreePath (FcChar8
**path
)
1366 for (p
= path
; *p
; p
++)
1371 static FcBool _FcConfigHomeEnabled
= FcTrue
;
1376 if (_FcConfigHomeEnabled
)
1377 return getenv ("HOME");
1382 FcConfigEnableHome (FcBool enable
)
1384 FcBool prev
= _FcConfigHomeEnabled
;
1385 _FcConfigHomeEnabled
= enable
;
1390 FcConfigFilename (const FcChar8
*url
)
1392 FcChar8
*file
, *dir
, **path
, **p
;
1396 url
= (FcChar8
*) getenv ("FONTCONFIG_FILE");
1398 url
= (FcChar8
*) FONTCONFIG_FILE
;
1403 dir
= FcConfigHome ();
1405 file
= FcConfigFileExists (dir
, url
+ 1);
1410 file
= FcConfigFileExists (0, url
);
1413 path
= FcConfigGetPath ();
1416 for (p
= path
; *p
; p
++)
1418 file
= FcConfigFileExists (*p
, url
);
1422 FcConfigFreePath (path
);
1429 * Manage the application-specific fonts
1433 FcConfigAppFontAddFile (FcConfig
*config
,
1434 const FcChar8
*file
)
1443 config
= FcConfigGetCurrent ();
1448 subdirs
= FcStrSetCreate ();
1452 set
= FcConfigGetFonts (config
, FcSetApplication
);
1455 set
= FcFontSetCreate ();
1458 FcStrSetDestroy (subdirs
);
1461 FcConfigSetFonts (config
, set
, FcSetApplication
);
1464 if (!FcFileScan (set
, subdirs
, 0, config
->blanks
, file
, FcFalse
))
1466 FcStrSetDestroy (subdirs
);
1469 if ((sublist
= FcStrListCreate (subdirs
)))
1471 while ((subdir
= FcStrListNext (sublist
)))
1473 FcConfigAppFontAddDir (config
, subdir
);
1475 FcStrListDone (sublist
);
1481 FcConfigAppFontAddDir (FcConfig
*config
,
1491 config
= FcConfigGetCurrent ();
1495 subdirs
= FcStrSetCreate ();
1499 set
= FcConfigGetFonts (config
, FcSetApplication
);
1502 set
= FcFontSetCreate ();
1505 FcStrSetDestroy (subdirs
);
1508 FcConfigSetFonts (config
, set
, FcSetApplication
);
1511 if (!FcDirScan (set
, subdirs
, 0, config
->blanks
, dir
, FcFalse
))
1513 FcStrSetDestroy (subdirs
);
1516 if ((sublist
= FcStrListCreate (subdirs
)))
1518 while ((subdir
= FcStrListNext (sublist
)))
1520 FcConfigAppFontAddDir (config
, subdir
);
1522 FcStrListDone (sublist
);
1528 FcConfigAppFontClear (FcConfig
*config
)
1530 FcConfigSetFonts (config
, 0, FcSetApplication
);