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 #if defined (_WIN32) && (defined (PIC) || defined (DLL_EXPORT))
33 #if defined (_WIN32) && !defined (R_OK)
45 config
= malloc (sizeof (FcConfig
));
48 FcMemAlloc (FC_MEM_CONFIG
, sizeof (FcConfig
));
50 config
->configDirs
= FcStrSetCreate ();
51 if (!config
->configDirs
)
54 config
->configFiles
= FcStrSetCreate ();
55 if (!config
->configFiles
)
58 config
->fontDirs
= FcStrSetCreate ();
59 if (!config
->fontDirs
)
62 config
->acceptGlobs
= FcStrSetCreate ();
63 if (!config
->acceptGlobs
)
66 config
->rejectGlobs
= FcStrSetCreate ();
67 if (!config
->rejectGlobs
)
72 if (!FcConfigSetCache (config
, (FcChar8
*) ("~/" FC_USER_CACHE_FILE
)))
76 if (config
->cache
== 0)
78 /* If no home, use the temp folder. */
80 int templen
= GetTempPath (1, dummy
);
81 FcChar8
*temp
= malloc (templen
+ 1);
87 GetTempPath (templen
+ 1, temp
);
88 cache_dir
= FcStrPlus (temp
, FC_USER_CACHE_FILE
);
90 if (!FcConfigSetCache (config
, cache_dir
))
92 FcStrFree (cache_dir
);
95 FcStrFree (cache_dir
);
102 config
->substPattern
= 0;
103 config
->substFont
= 0;
104 config
->maxObjects
= 0;
105 for (set
= FcSetSystem
; set
<= FcSetApplication
; set
++)
106 config
->fonts
[set
] = 0;
108 config
->rescanTime
= time(0);
109 config
->rescanInterval
= 30;
114 FcStrSetDestroy (config
->rejectGlobs
);
116 FcStrSetDestroy (config
->acceptGlobs
);
118 FcStrSetDestroy (config
->fontDirs
);
120 FcStrSetDestroy (config
->configFiles
);
122 FcStrSetDestroy (config
->configDirs
);
125 FcMemFree (FC_MEM_CONFIG
, sizeof (FcConfig
));
130 typedef struct _FcFileTime
{
136 FcConfigNewestFile (FcStrSet
*files
)
138 FcStrList
*list
= FcStrListCreate (files
);
139 FcFileTime newest
= { 0, FcFalse
};
145 while ((file
= FcStrListNext (list
)))
146 if (stat ((char *) file
, &statb
) == 0)
147 if (!newest
.set
|| statb
.st_mtime
- newest
.time
> 0)
148 newest
.time
= statb
.st_mtime
;
149 FcStrListDone (list
);
155 FcConfigUptoDate (FcConfig
*config
)
157 FcFileTime config_time
, font_time
;
158 time_t now
= time(0);
161 config
= FcConfigGetCurrent ();
165 config_time
= FcConfigNewestFile (config
->configFiles
);
166 font_time
= FcConfigNewestFile (config
->configDirs
);
167 if ((config_time
.set
&& config_time
.time
- config
->rescanTime
> 0) ||
168 (font_time
.set
&& font_time
.time
- config
->rescanTime
) > 0)
172 config
->rescanTime
= now
;
177 FcSubstDestroy (FcSubst
*s
)
185 FcTestDestroy (s
->test
);
187 FcEditDestroy (s
->edit
);
189 FcMemFree (FC_MEM_SUBST
, sizeof (FcSubst
));
195 FcConfigDestroy (FcConfig
*config
)
199 if (config
== _fcConfig
)
202 FcStrSetDestroy (config
->configDirs
);
203 FcStrSetDestroy (config
->fontDirs
);
204 FcStrSetDestroy (config
->configFiles
);
205 FcStrSetDestroy (config
->acceptGlobs
);
206 FcStrSetDestroy (config
->rejectGlobs
);
209 FcBlanksDestroy (config
->blanks
);
212 FcStrFree (config
->cache
);
214 FcSubstDestroy (config
->substPattern
);
215 FcSubstDestroy (config
->substFont
);
216 for (set
= FcSetSystem
; set
<= FcSetApplication
; set
++)
217 if (config
->fonts
[set
])
218 FcFontSetDestroy (config
->fonts
[set
]);
221 FcMemFree (FC_MEM_CONFIG
, sizeof (FcConfig
));
225 * Scan the current list of directories in the configuration
226 * and build the set of available fonts. Update the
227 * per-user cache file to reflect the new configuration
231 FcConfigBuildFonts (FcConfig
*config
)
234 FcGlobalCache
*cache
;
238 fonts
= FcFontSetCreate ();
242 cache
= FcGlobalCacheCreate ();
247 FcGlobalCacheLoad (cache
, config
->cache
);
249 list
= FcConfigGetFontDirs (config
);
253 while ((dir
= FcStrListNext (list
)))
255 if (FcDebug () & FC_DBG_FONTSET
)
256 printf ("scan dir %s\n", dir
);
257 FcDirScanConfig (fonts
, config
->fontDirs
, cache
,
258 config
->blanks
, dir
, FcFalse
, config
);
261 FcStrListDone (list
);
263 if (FcDebug () & FC_DBG_FONTSET
)
264 FcFontSetPrint (fonts
);
267 FcGlobalCacheSave (cache
, config
->cache
);
268 FcGlobalCacheDestroy (cache
);
270 FcConfigSetFonts (config
, fonts
, FcSetSystem
);
274 FcFontSetDestroy (fonts
);
280 FcConfigSetCurrent (FcConfig
*config
)
283 if (!FcConfigBuildFonts (config
))
287 FcConfigDestroy (_fcConfig
);
293 FcConfigGetCurrent (void)
302 FcConfigAddConfigDir (FcConfig
*config
,
305 return FcStrSetAddFilename (config
->configDirs
, d
);
309 FcConfigGetConfigDirs (FcConfig
*config
)
313 config
= FcConfigGetCurrent ();
317 return FcStrListCreate (config
->configDirs
);
321 FcConfigAddFontDir (FcConfig
*config
,
324 return FcStrSetAddFilename (config
->fontDirs
, d
);
328 FcConfigAddDir (FcConfig
*config
,
331 return (FcConfigAddConfigDir (config
, d
) &&
332 FcConfigAddFontDir (config
, d
));
336 FcConfigGetFontDirs (FcConfig
*config
)
340 config
= FcConfigGetCurrent ();
344 return FcStrListCreate (config
->fontDirs
);
348 FcConfigAddConfigFile (FcConfig
*config
,
352 FcChar8
*file
= FcConfigFilename (f
);
357 ret
= FcStrSetAdd (config
->configFiles
, file
);
363 FcConfigGetConfigFiles (FcConfig
*config
)
367 config
= FcConfigGetCurrent ();
371 return FcStrListCreate (config
->configFiles
);
375 FcConfigSetCache (FcConfig
*config
,
378 FcChar8
*new = FcStrCopyFilename (c
);
383 FcStrFree (config
->cache
);
389 FcConfigGetCache (FcConfig
*config
)
393 config
= FcConfigGetCurrent ();
397 return config
->cache
;
401 FcConfigGetFonts (FcConfig
*config
,
406 config
= FcConfigGetCurrent ();
410 return config
->fonts
[set
];
414 FcConfigSetFonts (FcConfig
*config
,
418 if (config
->fonts
[set
])
419 FcFontSetDestroy (config
->fonts
[set
]);
420 config
->fonts
[set
] = fonts
;
426 FcConfigGetBlanks (FcConfig
*config
)
430 config
= FcConfigGetCurrent ();
434 return config
->blanks
;
438 FcConfigAddBlank (FcConfig
*config
,
446 b
= FcBlanksCreate ();
450 if (!FcBlanksAdd (b
, blank
))
457 FcConfigGetRescanInverval (FcConfig
*config
)
461 config
= FcConfigGetCurrent ();
465 return config
->rescanInterval
;
469 FcConfigSetRescanInverval (FcConfig
*config
, int rescanInterval
)
473 config
= FcConfigGetCurrent ();
477 config
->rescanInterval
= rescanInterval
;
482 FcConfigAddEdit (FcConfig
*config
,
487 FcSubst
*subst
, **prev
;
491 subst
= (FcSubst
*) malloc (sizeof (FcSubst
));
494 FcMemAlloc (FC_MEM_SUBST
, sizeof (FcSubst
));
495 if (kind
== FcMatchPattern
)
496 prev
= &config
->substPattern
;
498 prev
= &config
->substFont
;
499 for (; *prev
; prev
= &(*prev
)->next
);
505 for (t
= test
; t
; t
= t
->next
)
507 if (t
->kind
== FcMatchDefault
)
511 if (config
->maxObjects
< num
)
512 config
->maxObjects
= num
;
513 if (FcDebug () & FC_DBG_EDIT
)
515 printf ("Add Subst ");
516 FcSubstPrint (subst
);
521 typedef struct _FcSubState
{
527 FcConfigPromote (FcValue v
, FcValue u
)
529 if (v
.type
== FcTypeInteger
)
531 v
.type
= FcTypeDouble
;
532 v
.u
.d
= (double) v
.u
.i
;
534 else if (v
.type
== FcTypeVoid
&& u
.type
== FcTypeMatrix
)
536 v
.u
.m
= &FcIdentityMatrix
;
537 v
.type
= FcTypeMatrix
;
539 else if (v
.type
== FcTypeString
&& u
.type
== FcTypeLangSet
)
541 v
.u
.l
= FcLangSetPromote (v
.u
.s
);
542 v
.type
= FcTypeLangSet
;
548 FcConfigCompareValue (const FcValue left_o
,
550 const FcValue right_o
)
552 FcValue left
= left_o
;
553 FcValue right
= right_o
;
554 FcBool ret
= FcFalse
;
556 left
= FcConfigPromote (left
, right
);
557 right
= FcConfigPromote (right
, left
);
558 if (left
.type
== right
.type
)
562 break; /* FcConfigPromote prevents this from happening */
568 ret
= left
.u
.d
== right
.u
.d
;
571 case FcOpNotContains
:
572 ret
= left
.u
.d
!= right
.u
.d
;
575 ret
= left
.u
.d
< right
.u
.d
;
578 ret
= left
.u
.d
<= right
.u
.d
;
581 ret
= left
.u
.d
> right
.u
.d
;
584 ret
= left
.u
.d
>= right
.u
.d
;
595 ret
= left
.u
.b
== right
.u
.b
;
598 case FcOpNotContains
:
599 ret
= left
.u
.b
!= right
.u
.b
;
609 ret
= FcStrCmpIgnoreCase (left
.u
.s
, right
.u
.s
) == 0;
612 ret
= FcStrStrIgnoreCase (left
.u
.s
, right
.u
.s
) != 0;
615 case FcOpNotContains
:
616 ret
= FcStrCmpIgnoreCase (left
.u
.s
, right
.u
.s
) != 0;
627 ret
= FcMatrixEqual (left
.u
.m
, right
.u
.m
);
630 case FcOpNotContains
:
631 ret
= !FcMatrixEqual (left
.u
.m
, right
.u
.m
);
641 /* left contains right if right is a subset of left */
642 ret
= FcCharSetIsSubset (right
.u
.c
, left
.u
.c
);
644 case FcOpNotContains
:
645 /* left contains right if right is a subset of left */
646 ret
= !FcCharSetIsSubset (right
.u
.c
, left
.u
.c
);
649 ret
= FcCharSetEqual (left
.u
.c
, right
.u
.c
);
652 ret
= !FcCharSetEqual (left
.u
.c
, right
.u
.c
);
662 ret
= FcLangSetContains (left
.u
.l
, right
.u
.l
);
664 case FcOpNotContains
:
665 ret
= FcLangSetContains (left
.u
.l
, right
.u
.l
);
668 ret
= FcLangSetEqual (left
.u
.l
, right
.u
.l
);
671 ret
= !FcLangSetEqual (left
.u
.l
, right
.u
.l
);
693 ret
= left
.u
.f
== right
.u
.f
;
696 case FcOpNotContains
:
697 ret
= left
.u
.f
!= right
.u
.f
;
707 if (op
== FcOpNotEqual
|| op
== FcOpNotContains
)
714 #define _FcDoubleFloor(d) ((int) (d))
715 #define _FcDoubleCeil(d) ((double) (int) (d) == (d) ? (int) (d) : (int) ((d) + 1))
716 #define FcDoubleFloor(d) ((d) >= 0 ? _FcDoubleFloor(d) : -_FcDoubleCeil(-(d)))
717 #define FcDoubleCeil(d) ((d) >= 0 ? _FcDoubleCeil(d) : -_FcDoubleFloor(-(d)))
718 #define FcDoubleRound(d) FcDoubleFloor ((d) + 0.5)
719 #define FcDoubleTrunc(d) ((d) >= 0 ? _FcDoubleFloor (d) : -_FcDoubleFloor (-(d)))
722 FcConfigEvaluate (FcPattern
*p
, FcExpr
*e
)
730 v
.type
= FcTypeInteger
;
734 v
.type
= FcTypeDouble
;
738 v
.type
= FcTypeString
;
743 v
.type
= FcTypeMatrix
;
748 v
.type
= FcTypeCharSet
;
757 r
= FcPatternGet (p
, e
->u
.field
, 0, &v
);
758 if (r
!= FcResultMatch
)
762 if (FcNameConstant (e
->u
.constant
, &v
.u
.i
))
763 v
.type
= FcTypeInteger
;
768 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
769 if (vl
.type
== FcTypeBool
)
772 v
= FcConfigEvaluate (p
, e
->u
.tree
.right
->u
.tree
.left
);
774 v
= FcConfigEvaluate (p
, e
->u
.tree
.right
->u
.tree
.right
);
787 case FcOpNotContains
:
789 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
790 vr
= FcConfigEvaluate (p
, e
->u
.tree
.right
);
792 v
.u
.b
= FcConfigCompareValue (vl
, e
->op
, vr
);
802 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
803 vr
= FcConfigEvaluate (p
, e
->u
.tree
.right
);
804 vl
= FcConfigPromote (vl
, vr
);
805 vr
= FcConfigPromote (vr
, vl
);
806 if (vl
.type
== vr
.type
)
812 v
.type
= FcTypeDouble
;
813 v
.u
.d
= vl
.u
.d
+ vr
.u
.d
;
816 v
.type
= FcTypeDouble
;
817 v
.u
.d
= vl
.u
.d
- vr
.u
.d
;
820 v
.type
= FcTypeDouble
;
821 v
.u
.d
= vl
.u
.d
* vr
.u
.d
;
824 v
.type
= FcTypeDouble
;
825 v
.u
.d
= vl
.u
.d
/ vr
.u
.d
;
831 if (v
.type
== FcTypeDouble
&&
832 v
.u
.d
== (double) (int) v
.u
.d
)
834 v
.type
= FcTypeInteger
;
842 v
.u
.b
= vl
.u
.b
|| vr
.u
.b
;
846 v
.u
.b
= vl
.u
.b
&& vr
.u
.b
;
856 v
.type
= FcTypeString
;
857 v
.u
.s
= FcStrPlus (vl
.u
.s
, vr
.u
.s
);
869 v
.type
= FcTypeMatrix
;
870 m
= malloc (sizeof (FcMatrix
));
873 FcMemAlloc (FC_MEM_MATRIX
, sizeof (FcMatrix
));
874 FcMatrixMultiply (m
, vl
.u
.m
, vr
.u
.m
);
898 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
911 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
917 v
.type
= FcTypeInteger
;
918 v
.u
.i
= FcDoubleFloor (vl
.u
.d
);
927 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
933 v
.type
= FcTypeInteger
;
934 v
.u
.i
= FcDoubleCeil (vl
.u
.d
);
943 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
949 v
.type
= FcTypeInteger
;
950 v
.u
.i
= FcDoubleRound (vl
.u
.d
);
959 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
965 v
.type
= FcTypeInteger
;
966 v
.u
.i
= FcDoubleTrunc (vl
.u
.d
);
982 FcConfigMatchValueList (FcPattern
*p
,
986 FcValueList
*ret
= 0;
993 /* Compute the value of the match expression */
994 if (e
->op
== FcOpComma
)
996 value
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
1001 value
= FcConfigEvaluate (p
, e
);
1005 for (v
= values
; v
; v
= v
->next
)
1007 /* Compare the pattern value to the match expression value */
1008 if (FcConfigCompareValue (v
->value
, t
->op
, value
))
1015 if (t
->qual
== FcQualAll
)
1022 FcValueDestroy (value
);
1027 static FcValueList
*
1028 FcConfigValues (FcPattern
*p
, FcExpr
*e
, FcValueBinding binding
)
1034 l
= (FcValueList
*) malloc (sizeof (FcValueList
));
1037 FcMemAlloc (FC_MEM_VALLIST
, sizeof (FcValueList
));
1038 if (e
->op
== FcOpComma
)
1040 l
->value
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
1041 l
->next
= FcConfigValues (p
, e
->u
.tree
.right
, binding
);
1045 l
->value
= FcConfigEvaluate (p
, e
);
1048 l
->binding
= binding
;
1049 while (l
&& l
->value
.type
== FcTypeVoid
)
1051 FcValueList
*next
= l
->next
;
1053 FcMemFree (FC_MEM_VALLIST
, sizeof (FcValueList
));
1061 FcConfigAdd (FcValueList
**head
,
1062 FcValueList
*position
,
1066 FcValueList
**prev
, *last
, *v
;
1067 FcValueBinding sameBinding
;
1070 sameBinding
= position
->binding
;
1072 sameBinding
= FcValueBindingWeak
;
1073 for (v
= new; v
; v
= v
->next
)
1074 if (v
->binding
== FcValueBindingSame
)
1075 v
->binding
= sameBinding
;
1079 prev
= &position
->next
;
1081 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1088 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1090 if (*prev
== position
)
1097 if (FcDebug () & FC_DBG_EDIT
)
1100 printf ("position not on list\n");
1104 if (FcDebug () & FC_DBG_EDIT
)
1106 printf ("%s list before ", append
? "Append" : "Prepend");
1107 FcValueListPrint (*head
);
1121 if (FcDebug () & FC_DBG_EDIT
)
1123 printf ("%s list after ", append
? "Append" : "Prepend");
1124 FcValueListPrint (*head
);
1132 FcConfigDel (FcValueList
**head
,
1133 FcValueList
*position
)
1137 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1139 if (*prev
== position
)
1141 *prev
= position
->next
;
1143 FcValueListDestroy (position
);
1150 FcConfigPatternAdd (FcPattern
*p
,
1157 FcPatternElt
*e
= FcPatternInsertElt (p
, object
);
1161 FcConfigAdd (&e
->values
, 0, append
, list
);
1166 * Delete all values associated with a field
1169 FcConfigPatternDel (FcPattern
*p
,
1172 FcPatternElt
*e
= FcPatternFindElt (p
, object
);
1176 FcConfigDel (&e
->values
, e
->values
);
1180 FcConfigPatternCanon (FcPattern
*p
,
1183 FcPatternElt
*e
= FcPatternFindElt (p
, object
);
1187 FcPatternDel (p
, object
);
1191 FcConfigSubstituteWithPat (FcConfig
*config
,
1206 config
= FcConfigGetCurrent ();
1211 st
= (FcSubState
*) malloc (config
->maxObjects
* sizeof (FcSubState
));
1212 if (!st
&& config
->maxObjects
)
1214 FcMemAlloc (FC_MEM_SUBSTATE
, config
->maxObjects
* sizeof (FcSubState
));
1216 if (FcDebug () & FC_DBG_EDIT
)
1218 printf ("FcConfigSubstitute ");
1221 if (kind
== FcMatchPattern
)
1222 s
= config
->substPattern
;
1224 s
= config
->substFont
;
1225 for (; s
; s
= s
->next
)
1228 * Check the tests to see if
1229 * they all match the pattern
1231 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1233 if (FcDebug () & FC_DBG_EDIT
)
1235 printf ("FcConfigSubstitute test ");
1239 if (kind
== FcMatchFont
&& t
->kind
== FcMatchPattern
)
1244 st
[i
].elt
= FcPatternFindElt (m
, t
->field
);
1248 * If there's no such field in the font,
1249 * then FcQualAll matches while FcQualAny does not
1253 if (t
->qual
== FcQualAll
)
1262 * Check to see if there is a match, mark the location
1263 * to apply match-relative edits
1265 st
[i
].value
= FcConfigMatchValueList (m
, t
, st
[i
].elt
->values
);
1268 if (t
->qual
== FcQualFirst
&& st
[i
].value
!= st
[i
].elt
->values
)
1270 if (t
->qual
== FcQualNotFirst
&& st
[i
].value
== st
[i
].elt
->values
)
1275 if (FcDebug () & FC_DBG_EDIT
)
1276 printf ("No match\n");
1279 if (FcDebug () & FC_DBG_EDIT
)
1281 printf ("Substitute ");
1284 for (e
= s
->edit
; e
; e
= e
->next
)
1287 * Evaluate the list of expressions
1289 l
= FcConfigValues (p
, e
->expr
, e
->binding
);
1291 * Locate any test associated with this field, skipping
1292 * tests associated with the pattern when substituting in
1295 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1297 if ((t
->kind
== FcMatchFont
|| kind
== FcMatchPattern
) &&
1298 !FcStrCmpIgnoreCase ((FcChar8
*) t
->field
,
1299 (FcChar8
*) e
->field
))
1302 * KLUDGE - the pattern may have been reallocated or
1303 * things may have been inserted or deleted above
1304 * this element by other edits. Go back and find
1307 if (e
!= s
->edit
&& st
[i
].elt
)
1308 st
[i
].elt
= FcPatternFindElt (p
, t
->field
);
1317 * If there was a test, then replace the matched
1318 * value with the new list of values
1322 FcValueList
*thisValue
= st
[i
].value
;
1323 FcValueList
*nextValue
= thisValue
? thisValue
->next
: 0;
1326 * Append the new list of values after the current value
1328 FcConfigAdd (&st
[i
].elt
->values
, thisValue
, FcTrue
, l
);
1330 * Delete the marked value
1332 FcConfigDel (&st
[i
].elt
->values
, thisValue
);
1334 * Adjust any pointers into the value list to ensure
1335 * future edits occur at the same place
1337 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1339 if (st
[i
].value
== thisValue
)
1340 st
[i
].value
= nextValue
;
1344 /* fall through ... */
1345 case FcOpAssignReplace
:
1347 * Delete all of the values and insert
1350 FcConfigPatternDel (p
, e
->field
);
1351 FcConfigPatternAdd (p
, e
->field
, l
, FcTrue
);
1353 * Adjust any pointers into the value list as they no
1354 * longer point to anything valid
1358 FcPatternElt
*thisElt
= st
[i
].elt
;
1359 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1361 if (st
[i
].elt
== thisElt
)
1369 FcConfigAdd (&st
[i
].elt
->values
, st
[i
].value
, FcFalse
, l
);
1372 /* fall through ... */
1373 case FcOpPrependFirst
:
1374 FcConfigPatternAdd (p
, e
->field
, l
, FcFalse
);
1379 FcConfigAdd (&st
[i
].elt
->values
, st
[i
].value
, FcTrue
, l
);
1382 /* fall through ... */
1383 case FcOpAppendLast
:
1384 FcConfigPatternAdd (p
, e
->field
, l
, FcTrue
);
1391 * Now go through the pattern and eliminate
1392 * any properties without data
1394 for (e
= s
->edit
; e
; e
= e
->next
)
1395 FcConfigPatternCanon (p
, e
->field
);
1397 if (FcDebug () & FC_DBG_EDIT
)
1399 printf ("FcConfigSubstitute edit");
1403 FcMemFree (FC_MEM_SUBSTATE
, config
->maxObjects
* sizeof (FcSubState
));
1405 if (FcDebug () & FC_DBG_EDIT
)
1407 printf ("FcConfigSubstitute done");
1414 FcConfigSubstitute (FcConfig
*config
,
1418 return FcConfigSubstituteWithPat (config
, p
, 0, kind
);
1421 #if defined (_WIN32) && (defined (PIC) || defined (DLL_EXPORT))
1423 static FcChar8 fontconfig_path
[1000] = "";
1426 DllMain (HINSTANCE hinstDLL
,
1432 switch (fdwReason
) {
1433 case DLL_PROCESS_ATTACH
:
1434 if (!GetModuleFileName ((HMODULE
) hinstDLL
, fontconfig_path
,
1435 sizeof (fontconfig_path
)))
1438 /* If the fontconfig DLL is in a "bin" or "lib" subfolder,
1439 * assume it's a Unix-style installation tree, and use
1440 * "etc/fonts" in there as FONTCONFIG_PATH. Otherwise use the
1441 * folder where the DLL is as FONTCONFIG_PATH.
1443 p
= strrchr (fontconfig_path
, '\\');
1447 p
= strrchr (fontconfig_path
, '\\');
1448 if (p
&& (FcStrCmpIgnoreCase (p
+ 1, "bin") == 0 ||
1449 FcStrCmpIgnoreCase (p
+ 1, "lib") == 0))
1451 strcat (fontconfig_path
, "\\etc\\fonts");
1454 fontconfig_path
[0] = '\0';
1462 #undef FONTCONFIG_PATH
1463 #define FONTCONFIG_PATH fontconfig_path
1465 #else /* !(_WIN32 && PIC) */
1467 #endif /* !(_WIN32 && PIC) */
1469 #ifndef FONTCONFIG_FILE
1470 #define FONTCONFIG_FILE "fonts.conf"
1474 FcConfigFileExists (const FcChar8
*dir
, const FcChar8
*file
)
1479 dir
= (FcChar8
*) "";
1480 path
= malloc (strlen ((char *) dir
) + 1 + strlen ((char *) file
) + 1);
1484 strcpy ((char *) path
, (const char *) dir
);
1485 /* make sure there's a single separator */
1487 if ((!path
[0] || (path
[strlen((char *) path
)-1] != '/' &&
1488 path
[strlen((char *) path
)-1] != '\\')) &&
1489 (file
[0] != '/' && file
[0] != '\\'))
1490 strcat ((char *) path
, "\\");
1492 if ((!path
[0] || path
[strlen((char *) path
)-1] != '/') && file
[0] != '/')
1493 strcat ((char *) path
, "/");
1495 strcat ((char *) path
, (char *) file
);
1497 FcMemAlloc (FC_MEM_STRING
, strlen ((char *) path
) + 1);
1498 if (access ((char *) path
, R_OK
) == 0)
1506 FcConfigGetPath (void)
1509 FcChar8
*env
, *e
, *colon
;
1514 npath
= 2; /* default dir + null */
1515 env
= (FcChar8
*) getenv ("FONTCONFIG_PATH");
1521 if (*e
++ == FC_SEARCH_PATH_SEPARATOR
)
1524 path
= calloc (npath
, sizeof (FcChar8
*));
1534 colon
= (FcChar8
*) strchr ((char *) e
, FC_SEARCH_PATH_SEPARATOR
);
1536 colon
= e
+ strlen ((char *) e
);
1537 path
[i
] = malloc (colon
- e
+ 1);
1540 strncpy ((char *) path
[i
], (const char *) e
, colon
- e
);
1541 path
[i
][colon
- e
] = '\0';
1550 dir
= (FcChar8
*) FONTCONFIG_PATH
;
1551 path
[i
] = malloc (strlen ((char *) dir
) + 1);
1554 strcpy ((char *) path
[i
], (const char *) dir
);
1558 for (i
= 0; path
[i
]; i
++)
1566 FcConfigFreePath (FcChar8
**path
)
1570 for (p
= path
; *p
; p
++)
1575 static FcBool _FcConfigHomeEnabled
= FcTrue
;
1580 if (_FcConfigHomeEnabled
)
1582 char *home
= getenv ("HOME");
1586 home
= getenv ("USERPROFILE");
1595 FcConfigEnableHome (FcBool enable
)
1597 FcBool prev
= _FcConfigHomeEnabled
;
1598 _FcConfigHomeEnabled
= enable
;
1603 FcConfigFilename (const FcChar8
*url
)
1605 FcChar8
*file
, *dir
, **path
, **p
;
1609 url
= (FcChar8
*) getenv ("FONTCONFIG_FILE");
1611 url
= (FcChar8
*) FONTCONFIG_FILE
;
1616 if (isalpha (*url
) &&
1618 (url
[2] == '/' || url
[2] == '\\'))
1624 dir
= FcConfigHome ();
1626 file
= FcConfigFileExists (dir
, url
+ 1);
1635 file
= FcConfigFileExists (0, url
);
1638 path
= FcConfigGetPath ();
1641 for (p
= path
; *p
; p
++)
1643 file
= FcConfigFileExists (*p
, url
);
1647 FcConfigFreePath (path
);
1654 * Manage the application-specific fonts
1658 FcConfigAppFontAddFile (FcConfig
*config
,
1659 const FcChar8
*file
)
1668 config
= FcConfigGetCurrent ();
1673 subdirs
= FcStrSetCreate ();
1677 set
= FcConfigGetFonts (config
, FcSetApplication
);
1680 set
= FcFontSetCreate ();
1683 FcStrSetDestroy (subdirs
);
1686 FcConfigSetFonts (config
, set
, FcSetApplication
);
1689 if (!FcFileScanConfig (set
, subdirs
, 0, config
->blanks
, file
, FcFalse
, config
))
1691 FcStrSetDestroy (subdirs
);
1694 if ((sublist
= FcStrListCreate (subdirs
)))
1696 while ((subdir
= FcStrListNext (sublist
)))
1698 FcConfigAppFontAddDir (config
, subdir
);
1700 FcStrListDone (sublist
);
1706 FcConfigAppFontAddDir (FcConfig
*config
,
1716 config
= FcConfigGetCurrent ();
1720 subdirs
= FcStrSetCreate ();
1724 set
= FcConfigGetFonts (config
, FcSetApplication
);
1727 set
= FcFontSetCreate ();
1730 FcStrSetDestroy (subdirs
);
1733 FcConfigSetFonts (config
, set
, FcSetApplication
);
1736 if (!FcDirScanConfig (set
, subdirs
, 0, config
->blanks
, dir
, FcFalse
, config
))
1738 FcStrSetDestroy (subdirs
);
1741 if ((sublist
= FcStrListCreate (subdirs
)))
1743 while ((subdir
= FcStrListNext (sublist
)))
1745 FcConfigAppFontAddDir (config
, subdir
);
1747 FcStrListDone (sublist
);
1753 FcConfigAppFontClear (FcConfig
*config
)
1757 config
= FcConfigGetCurrent ();
1762 FcConfigSetFonts (config
, 0, FcSetApplication
);
1766 * Manage filename-based font source selectors
1770 FcConfigGlobAdd (FcConfig
*config
,
1771 const FcChar8
*glob
,
1774 FcStrSet
*set
= accept
? config
->acceptGlobs
: config
->rejectGlobs
;
1776 return FcStrSetAdd (set
, glob
);
1780 FcConfigGlobMatch (const FcChar8
*glob
,
1781 const FcChar8
*string
)
1785 while ((c
= *glob
++))
1789 /* short circuit common case */
1792 /* short circuit another common case */
1793 if (strchr ((char *) glob
, '*') == 0)
1794 string
+= strlen ((char *) string
) - strlen ((char *) glob
);
1797 if (FcConfigGlobMatch (glob
, string
))
1803 if (*string
++ == '\0')
1812 return *string
== '\0';
1816 FcConfigGlobsMatch (const FcStrSet
*globs
,
1817 const FcChar8
*string
)
1821 for (i
= 0; i
< globs
->num
; i
++)
1822 if (FcConfigGlobMatch (globs
->strs
[i
], string
))
1828 FcConfigAcceptFilename (FcConfig
*config
,
1829 const FcChar8
*filename
)
1831 if (FcConfigGlobsMatch (config
->acceptGlobs
, filename
))
1833 if (FcConfigGlobsMatch (config
->rejectGlobs
, filename
))