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
)))
77 config
->substPattern
= 0;
78 config
->substFont
= 0;
79 config
->maxObjects
= 0;
80 for (set
= FcSetSystem
; set
<= FcSetApplication
; set
++)
81 config
->fonts
[set
] = 0;
83 config
->rescanTime
= time(0);
84 config
->rescanInterval
= 30;
89 FcStrSetDestroy (config
->rejectGlobs
);
91 FcStrSetDestroy (config
->acceptGlobs
);
93 FcStrSetDestroy (config
->fontDirs
);
95 FcStrSetDestroy (config
->configFiles
);
97 FcStrSetDestroy (config
->configDirs
);
100 FcMemFree (FC_MEM_CONFIG
, sizeof (FcConfig
));
105 typedef struct _FcFileTime
{
111 FcConfigNewestFile (FcStrSet
*files
)
113 FcStrList
*list
= FcStrListCreate (files
);
114 FcFileTime newest
= { 0, FcFalse
};
120 while ((file
= FcStrListNext (list
)))
121 if (stat ((char *) file
, &statb
) == 0)
122 if (!newest
.set
|| statb
.st_mtime
- newest
.time
> 0)
123 newest
.time
= statb
.st_mtime
;
124 FcStrListDone (list
);
130 FcConfigUptoDate (FcConfig
*config
)
132 FcFileTime config_time
, font_time
;
133 time_t now
= time(0);
136 config
= FcConfigGetCurrent ();
140 config_time
= FcConfigNewestFile (config
->configFiles
);
141 font_time
= FcConfigNewestFile (config
->configDirs
);
142 if ((config_time
.set
&& config_time
.time
- config
->rescanTime
> 0) ||
143 (font_time
.set
&& font_time
.time
- config
->rescanTime
) > 0)
147 config
->rescanTime
= now
;
152 FcSubstDestroy (FcSubst
*s
)
160 FcTestDestroy (s
->test
);
162 FcEditDestroy (s
->edit
);
168 FcConfigDestroy (FcConfig
*config
)
172 if (config
== _fcConfig
)
175 FcStrSetDestroy (config
->configDirs
);
176 FcStrSetDestroy (config
->fontDirs
);
177 FcStrSetDestroy (config
->configFiles
);
178 FcStrSetDestroy (config
->acceptGlobs
);
179 FcStrSetDestroy (config
->rejectGlobs
);
182 FcStrFree (config
->cache
);
184 FcSubstDestroy (config
->substPattern
);
185 FcSubstDestroy (config
->substFont
);
186 for (set
= FcSetSystem
; set
<= FcSetApplication
; set
++)
187 if (config
->fonts
[set
])
188 FcFontSetDestroy (config
->fonts
[set
]);
190 FcMemFree (FC_MEM_CONFIG
, sizeof (FcConfig
));
194 * Scan the current list of directories in the configuration
195 * and build the set of available fonts. Update the
196 * per-user cache file to reflect the new configuration
200 FcConfigBuildFonts (FcConfig
*config
)
203 FcGlobalCache
*cache
;
207 fonts
= FcFontSetCreate ();
211 cache
= FcGlobalCacheCreate ();
216 FcGlobalCacheLoad (cache
, config
->cache
);
218 list
= FcConfigGetFontDirs (config
);
222 while ((dir
= FcStrListNext (list
)))
224 if (FcDebug () & FC_DBG_FONTSET
)
225 printf ("scan dir %s\n", dir
);
226 FcDirScanConfig (fonts
, config
->fontDirs
, cache
,
227 config
->blanks
, dir
, FcFalse
, config
);
230 FcStrListDone (list
);
232 if (FcDebug () & FC_DBG_FONTSET
)
233 FcFontSetPrint (fonts
);
236 FcGlobalCacheSave (cache
, config
->cache
);
237 FcGlobalCacheDestroy (cache
);
239 FcConfigSetFonts (config
, fonts
, FcSetSystem
);
243 FcFontSetDestroy (fonts
);
249 FcConfigSetCurrent (FcConfig
*config
)
252 if (!FcConfigBuildFonts (config
))
256 FcConfigDestroy (_fcConfig
);
262 FcConfigGetCurrent (void)
271 FcConfigAddConfigDir (FcConfig
*config
,
274 return FcStrSetAddFilename (config
->configDirs
, d
);
278 FcConfigGetConfigDirs (FcConfig
*config
)
282 config
= FcConfigGetCurrent ();
286 return FcStrListCreate (config
->configDirs
);
290 FcConfigAddFontDir (FcConfig
*config
,
293 return FcStrSetAddFilename (config
->fontDirs
, d
);
297 FcConfigAddDir (FcConfig
*config
,
300 return (FcConfigAddConfigDir (config
, d
) &&
301 FcConfigAddFontDir (config
, d
));
305 FcConfigGetFontDirs (FcConfig
*config
)
309 config
= FcConfigGetCurrent ();
313 return FcStrListCreate (config
->fontDirs
);
317 FcConfigAddConfigFile (FcConfig
*config
,
321 FcChar8
*file
= FcConfigFilename (f
);
326 ret
= FcStrSetAdd (config
->configFiles
, file
);
332 FcConfigGetConfigFiles (FcConfig
*config
)
336 config
= FcConfigGetCurrent ();
340 return FcStrListCreate (config
->configFiles
);
344 FcConfigSetCache (FcConfig
*config
,
347 FcChar8
*new = FcStrCopyFilename (c
);
352 FcStrFree (config
->cache
);
358 FcConfigGetCache (FcConfig
*config
)
362 config
= FcConfigGetCurrent ();
366 return config
->cache
;
370 FcConfigGetFonts (FcConfig
*config
,
375 config
= FcConfigGetCurrent ();
379 return config
->fonts
[set
];
383 FcConfigSetFonts (FcConfig
*config
,
387 if (config
->fonts
[set
])
388 FcFontSetDestroy (config
->fonts
[set
]);
389 config
->fonts
[set
] = fonts
;
395 FcConfigGetBlanks (FcConfig
*config
)
399 config
= FcConfigGetCurrent ();
403 return config
->blanks
;
407 FcConfigAddBlank (FcConfig
*config
,
415 b
= FcBlanksCreate ();
419 if (!FcBlanksAdd (b
, blank
))
426 FcConfigGetRescanInverval (FcConfig
*config
)
430 config
= FcConfigGetCurrent ();
434 return config
->rescanInterval
;
438 FcConfigSetRescanInverval (FcConfig
*config
, int rescanInterval
)
442 config
= FcConfigGetCurrent ();
446 config
->rescanInterval
= rescanInterval
;
451 FcConfigAddEdit (FcConfig
*config
,
456 FcSubst
*subst
, **prev
;
460 subst
= (FcSubst
*) malloc (sizeof (FcSubst
));
463 FcMemAlloc (FC_MEM_SUBST
, sizeof (FcSubst
));
464 if (kind
== FcMatchPattern
)
465 prev
= &config
->substPattern
;
467 prev
= &config
->substFont
;
468 for (; *prev
; prev
= &(*prev
)->next
);
474 for (t
= test
; t
; t
= t
->next
)
476 if (t
->kind
== FcMatchDefault
)
480 if (config
->maxObjects
< num
)
481 config
->maxObjects
= num
;
482 if (FcDebug () & FC_DBG_EDIT
)
484 printf ("Add Subst ");
485 FcSubstPrint (subst
);
490 typedef struct _FcSubState
{
496 FcConfigPromote (FcValue v
, FcValue u
)
498 if (v
.type
== FcTypeInteger
)
500 v
.type
= FcTypeDouble
;
501 v
.u
.d
= (double) v
.u
.i
;
503 else if (v
.type
== FcTypeVoid
&& u
.type
== FcTypeMatrix
)
505 v
.u
.m
= &FcIdentityMatrix
;
506 v
.type
= FcTypeMatrix
;
508 else if (v
.type
== FcTypeString
&& u
.type
== FcTypeLangSet
)
510 v
.u
.l
= FcLangSetPromote (v
.u
.s
);
511 v
.type
= FcTypeLangSet
;
517 FcConfigCompareValue (const FcValue left_o
,
519 const FcValue right_o
)
521 FcValue left
= left_o
;
522 FcValue right
= right_o
;
523 FcBool ret
= FcFalse
;
525 left
= FcConfigPromote (left
, right
);
526 right
= FcConfigPromote (right
, left
);
527 if (left
.type
== right
.type
)
531 break; /* FcConfigPromote prevents this from happening */
537 ret
= left
.u
.d
== right
.u
.d
;
540 case FcOpNotContains
:
541 ret
= left
.u
.d
!= right
.u
.d
;
544 ret
= left
.u
.d
< right
.u
.d
;
547 ret
= left
.u
.d
<= right
.u
.d
;
550 ret
= left
.u
.d
> right
.u
.d
;
553 ret
= left
.u
.d
>= right
.u
.d
;
564 ret
= left
.u
.b
== right
.u
.b
;
567 case FcOpNotContains
:
568 ret
= left
.u
.b
!= right
.u
.b
;
578 ret
= FcStrCmpIgnoreCase (left
.u
.s
, right
.u
.s
) == 0;
581 ret
= FcStrStrIgnoreCase (left
.u
.s
, right
.u
.s
) != 0;
584 case FcOpNotContains
:
585 ret
= FcStrCmpIgnoreCase (left
.u
.s
, right
.u
.s
) != 0;
596 ret
= FcMatrixEqual (left
.u
.m
, right
.u
.m
);
599 case FcOpNotContains
:
600 ret
= !FcMatrixEqual (left
.u
.m
, right
.u
.m
);
610 /* left contains right if right is a subset of left */
611 ret
= FcCharSetIsSubset (right
.u
.c
, left
.u
.c
);
613 case FcOpNotContains
:
614 /* left contains right if right is a subset of left */
615 ret
= !FcCharSetIsSubset (right
.u
.c
, left
.u
.c
);
618 ret
= FcCharSetEqual (left
.u
.c
, right
.u
.c
);
621 ret
= !FcCharSetEqual (left
.u
.c
, right
.u
.c
);
631 ret
= FcLangSetContains (left
.u
.l
, right
.u
.l
);
633 case FcOpNotContains
:
634 ret
= FcLangSetContains (left
.u
.l
, right
.u
.l
);
637 ret
= FcLangSetEqual (left
.u
.l
, right
.u
.l
);
640 ret
= !FcLangSetEqual (left
.u
.l
, right
.u
.l
);
662 ret
= left
.u
.f
== right
.u
.f
;
665 case FcOpNotContains
:
666 ret
= left
.u
.f
!= right
.u
.f
;
676 if (op
== FcOpNotEqual
|| op
== FcOpNotContains
)
683 #define _FcDoubleFloor(d) ((int) (d))
684 #define _FcDoubleCeil(d) ((double) (int) (d) == (d) ? (int) (d) : (int) ((d) + 1))
685 #define FcDoubleFloor(d) ((d) >= 0 ? _FcDoubleFloor(d) : -_FcDoubleCeil(-(d)))
686 #define FcDoubleCeil(d) ((d) >= 0 ? _FcDoubleCeil(d) : -_FcDoubleFloor(-(d)))
687 #define FcDoubleRound(d) FcDoubleFloor ((d) + 0.5)
688 #define FcDoubleTrunc(d) ((d) >= 0 ? _FcDoubleFloor (d) : -_FcDoubleFloor (-(d)))
691 FcConfigEvaluate (FcPattern
*p
, FcExpr
*e
)
699 v
.type
= FcTypeInteger
;
703 v
.type
= FcTypeDouble
;
707 v
.type
= FcTypeString
;
712 v
.type
= FcTypeMatrix
;
717 v
.type
= FcTypeCharSet
;
726 r
= FcPatternGet (p
, e
->u
.field
, 0, &v
);
727 if (r
!= FcResultMatch
)
731 if (FcNameConstant (e
->u
.constant
, &v
.u
.i
))
732 v
.type
= FcTypeInteger
;
737 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
738 if (vl
.type
== FcTypeBool
)
741 v
= FcConfigEvaluate (p
, e
->u
.tree
.right
->u
.tree
.left
);
743 v
= FcConfigEvaluate (p
, e
->u
.tree
.right
->u
.tree
.right
);
756 case FcOpNotContains
:
758 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
759 vr
= FcConfigEvaluate (p
, e
->u
.tree
.right
);
761 v
.u
.b
= FcConfigCompareValue (vl
, e
->op
, vr
);
771 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
772 vr
= FcConfigEvaluate (p
, e
->u
.tree
.right
);
773 vl
= FcConfigPromote (vl
, vr
);
774 vr
= FcConfigPromote (vr
, vl
);
775 if (vl
.type
== vr
.type
)
781 v
.type
= FcTypeDouble
;
782 v
.u
.d
= vl
.u
.d
+ vr
.u
.d
;
785 v
.type
= FcTypeDouble
;
786 v
.u
.d
= vl
.u
.d
- vr
.u
.d
;
789 v
.type
= FcTypeDouble
;
790 v
.u
.d
= vl
.u
.d
* vr
.u
.d
;
793 v
.type
= FcTypeDouble
;
794 v
.u
.d
= vl
.u
.d
/ vr
.u
.d
;
800 if (v
.type
== FcTypeDouble
&&
801 v
.u
.d
== (double) (int) v
.u
.d
)
803 v
.type
= FcTypeInteger
;
811 v
.u
.b
= vl
.u
.b
|| vr
.u
.b
;
815 v
.u
.b
= vl
.u
.b
&& vr
.u
.b
;
825 v
.type
= FcTypeString
;
826 v
.u
.s
= FcStrPlus (vl
.u
.s
, vr
.u
.s
);
838 v
.type
= FcTypeMatrix
;
839 m
= malloc (sizeof (FcMatrix
));
842 FcMemAlloc (FC_MEM_MATRIX
, sizeof (FcMatrix
));
843 FcMatrixMultiply (m
, vl
.u
.m
, vr
.u
.m
);
867 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
880 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
886 v
.type
= FcTypeInteger
;
887 v
.u
.i
= FcDoubleFloor (vl
.u
.d
);
896 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
902 v
.type
= FcTypeInteger
;
903 v
.u
.i
= FcDoubleCeil (vl
.u
.d
);
912 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
918 v
.type
= FcTypeInteger
;
919 v
.u
.i
= FcDoubleRound (vl
.u
.d
);
928 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
934 v
.type
= FcTypeInteger
;
935 v
.u
.i
= FcDoubleTrunc (vl
.u
.d
);
951 FcConfigMatchValueList (FcPattern
*p
,
955 FcValueList
*ret
= 0;
962 /* Compute the value of the match expression */
963 if (e
->op
== FcOpComma
)
965 value
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
970 value
= FcConfigEvaluate (p
, e
);
974 for (v
= values
; v
; v
= v
->next
)
976 /* Compare the pattern value to the match expression value */
977 if (FcConfigCompareValue (v
->value
, t
->op
, value
))
984 if (t
->qual
== FcQualAll
)
991 FcValueDestroy (value
);
997 FcConfigValues (FcPattern
*p
, FcExpr
*e
, FcValueBinding binding
)
1003 l
= (FcValueList
*) malloc (sizeof (FcValueList
));
1006 FcMemAlloc (FC_MEM_VALLIST
, sizeof (FcValueList
));
1007 if (e
->op
== FcOpComma
)
1009 l
->value
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
1010 l
->next
= FcConfigValues (p
, e
->u
.tree
.right
, binding
);
1014 l
->value
= FcConfigEvaluate (p
, e
);
1017 l
->binding
= binding
;
1018 while (l
&& l
->value
.type
== FcTypeVoid
)
1020 FcValueList
*next
= l
->next
;
1022 FcMemFree (FC_MEM_VALLIST
, sizeof (FcValueList
));
1030 FcConfigAdd (FcValueList
**head
,
1031 FcValueList
*position
,
1035 FcValueList
**prev
, *last
, *v
;
1036 FcValueBinding sameBinding
;
1039 sameBinding
= position
->binding
;
1041 sameBinding
= FcValueBindingWeak
;
1042 for (v
= new; v
; v
= v
->next
)
1043 if (v
->binding
== FcValueBindingSame
)
1044 v
->binding
= sameBinding
;
1048 prev
= &position
->next
;
1050 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1057 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1059 if (*prev
== position
)
1066 if (FcDebug () & FC_DBG_EDIT
)
1069 printf ("position not on list\n");
1073 if (FcDebug () & FC_DBG_EDIT
)
1075 printf ("%s list before ", append
? "Append" : "Prepend");
1076 FcValueListPrint (*head
);
1090 if (FcDebug () & FC_DBG_EDIT
)
1092 printf ("%s list after ", append
? "Append" : "Prepend");
1093 FcValueListPrint (*head
);
1101 FcConfigDel (FcValueList
**head
,
1102 FcValueList
*position
)
1106 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1108 if (*prev
== position
)
1110 *prev
= position
->next
;
1112 FcValueListDestroy (position
);
1119 FcConfigPatternAdd (FcPattern
*p
,
1126 FcPatternElt
*e
= FcPatternInsertElt (p
, object
);
1130 FcConfigAdd (&e
->values
, 0, append
, list
);
1135 * Delete all values associated with a field
1138 FcConfigPatternDel (FcPattern
*p
,
1141 FcPatternElt
*e
= FcPatternFindElt (p
, object
);
1145 FcConfigDel (&e
->values
, e
->values
);
1149 FcConfigPatternCanon (FcPattern
*p
,
1152 FcPatternElt
*e
= FcPatternFindElt (p
, object
);
1156 FcPatternDel (p
, object
);
1160 FcConfigSubstituteWithPat (FcConfig
*config
,
1175 config
= FcConfigGetCurrent ();
1180 st
= (FcSubState
*) malloc (config
->maxObjects
* sizeof (FcSubState
));
1181 if (!st
&& config
->maxObjects
)
1183 FcMemAlloc (FC_MEM_SUBSTATE
, config
->maxObjects
* sizeof (FcSubState
));
1185 if (FcDebug () & FC_DBG_EDIT
)
1187 printf ("FcConfigSubstitute ");
1190 if (kind
== FcMatchPattern
)
1191 s
= config
->substPattern
;
1193 s
= config
->substFont
;
1194 for (; s
; s
= s
->next
)
1197 * Check the tests to see if
1198 * they all match the pattern
1200 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1202 if (FcDebug () & FC_DBG_EDIT
)
1204 printf ("FcConfigSubstitute test ");
1208 if (kind
== FcMatchFont
&& t
->kind
== FcMatchPattern
)
1213 st
[i
].elt
= FcPatternFindElt (m
, t
->field
);
1217 * If there's no such field in the font,
1218 * then FcQualAll matches while FcQualAny does not
1222 if (t
->qual
== FcQualAll
)
1231 * Check to see if there is a match, mark the location
1232 * to apply match-relative edits
1234 st
[i
].value
= FcConfigMatchValueList (m
, t
, st
[i
].elt
->values
);
1237 if (t
->qual
== FcQualFirst
&& st
[i
].value
!= st
[i
].elt
->values
)
1239 if (t
->qual
== FcQualNotFirst
&& st
[i
].value
== st
[i
].elt
->values
)
1244 if (FcDebug () & FC_DBG_EDIT
)
1245 printf ("No match\n");
1248 if (FcDebug () & FC_DBG_EDIT
)
1250 printf ("Substitute ");
1253 for (e
= s
->edit
; e
; e
= e
->next
)
1256 * Evaluate the list of expressions
1258 l
= FcConfigValues (p
, e
->expr
, e
->binding
);
1260 * Locate any test associated with this field, skipping
1261 * tests associated with the pattern when substituting in
1264 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1266 if ((t
->kind
== FcMatchFont
|| kind
== FcMatchPattern
) &&
1267 !FcStrCmpIgnoreCase ((FcChar8
*) t
->field
,
1268 (FcChar8
*) e
->field
))
1271 * KLUDGE - the pattern may have been reallocated or
1272 * things may have been inserted or deleted above
1273 * this element by other edits. Go back and find
1276 if (e
!= s
->edit
&& st
[i
].elt
)
1277 st
[i
].elt
= FcPatternFindElt (p
, t
->field
);
1286 * If there was a test, then replace the matched
1287 * value with the new list of values
1291 FcValueList
*thisValue
= st
[i
].value
;
1292 FcValueList
*nextValue
= thisValue
? thisValue
->next
: 0;
1295 * Append the new list of values after the current value
1297 FcConfigAdd (&st
[i
].elt
->values
, thisValue
, FcTrue
, l
);
1299 * Delete the marked value
1301 FcConfigDel (&st
[i
].elt
->values
, thisValue
);
1303 * Adjust any pointers into the value list to ensure
1304 * future edits occur at the same place
1306 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1308 if (st
[i
].value
== thisValue
)
1309 st
[i
].value
= nextValue
;
1313 /* fall through ... */
1314 case FcOpAssignReplace
:
1316 * Delete all of the values and insert
1319 FcConfigPatternDel (p
, e
->field
);
1320 FcConfigPatternAdd (p
, e
->field
, l
, FcTrue
);
1322 * Adjust any pointers into the value list as they no
1323 * longer point to anything valid
1327 FcPatternElt
*thisElt
= st
[i
].elt
;
1328 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1330 if (st
[i
].elt
== thisElt
)
1338 FcConfigAdd (&st
[i
].elt
->values
, st
[i
].value
, FcFalse
, l
);
1341 /* fall through ... */
1342 case FcOpPrependFirst
:
1343 FcConfigPatternAdd (p
, e
->field
, l
, FcFalse
);
1348 FcConfigAdd (&st
[i
].elt
->values
, st
[i
].value
, FcTrue
, l
);
1351 /* fall through ... */
1352 case FcOpAppendLast
:
1353 FcConfigPatternAdd (p
, e
->field
, l
, FcTrue
);
1360 * Now go through the pattern and eliminate
1361 * any properties without data
1363 for (e
= s
->edit
; e
; e
= e
->next
)
1364 FcConfigPatternCanon (p
, e
->field
);
1366 if (FcDebug () & FC_DBG_EDIT
)
1368 printf ("FcConfigSubstitute edit");
1372 FcMemFree (FC_MEM_SUBSTATE
, config
->maxObjects
* sizeof (FcSubState
));
1374 if (FcDebug () & FC_DBG_EDIT
)
1376 printf ("FcConfigSubstitute done");
1383 FcConfigSubstitute (FcConfig
*config
,
1387 return FcConfigSubstituteWithPat (config
, p
, 0, kind
);
1390 #if defined (_WIN32) && (defined (PIC) || defined (DLL_EXPORT))
1392 static FcChar8 fontconfig_path
[1000] = "";
1395 DllMain (HINSTANCE hinstDLL
,
1401 switch (fdwReason
) {
1402 case DLL_PROCESS_ATTACH
:
1403 if (!GetModuleFileName ((HMODULE
) hinstDLL
, fontconfig_path
,
1404 sizeof (fontconfig_path
)))
1407 /* If the fontconfig DLL is in a "bin" or "lib" subfolder,
1408 * assume it's a Unix-style installation tree, and use
1409 * "etc/fonts" in there as FONTCONFIG_PATH. Otherwise use the
1410 * folder where the DLL is as FONTCONFIG_PATH.
1412 p
= strrchr (fontconfig_path
, '\\');
1416 p
= strrchr (fontconfig_path
, '\\');
1417 if (p
&& (FcStrCmpIgnoreCase (p
+ 1, "bin") == 0 ||
1418 FcStrCmpIgnoreCase (p
+ 1, "lib") == 0))
1420 strcat (fontconfig_path
, "\\etc\\fonts");
1423 fontconfig_path
[0] = '\0';
1431 #undef FONTCONFIG_PATH
1432 #define FONTCONFIG_PATH fontconfig_path
1434 #else /* !(_WIN32 && PIC) */
1436 #endif /* !(_WIN32 && PIC) */
1438 #ifndef FONTCONFIG_FILE
1439 #define FONTCONFIG_FILE "fonts.conf"
1443 FcConfigFileExists (const FcChar8
*dir
, const FcChar8
*file
)
1448 dir
= (FcChar8
*) "";
1449 path
= malloc (strlen ((char *) dir
) + 1 + strlen ((char *) file
) + 1);
1453 strcpy ((char *) path
, (const char *) dir
);
1454 /* make sure there's a single separator */
1456 if ((!path
[0] || (path
[strlen((char *) path
)-1] != '/' &&
1457 path
[strlen((char *) path
)-1] != '\\')) &&
1458 (file
[0] != '/' && file
[0] != '\\'))
1459 strcat ((char *) path
, "\\");
1461 if ((!path
[0] || path
[strlen((char *) path
)-1] != '/') && file
[0] != '/')
1462 strcat ((char *) path
, "/");
1464 strcat ((char *) path
, (char *) file
);
1466 FcMemAlloc (FC_MEM_STRING
, strlen ((char *) path
) + 1);
1467 if (access ((char *) path
, R_OK
) == 0)
1475 FcConfigGetPath (void)
1478 FcChar8
*env
, *e
, *colon
;
1483 npath
= 2; /* default dir + null */
1484 env
= (FcChar8
*) getenv ("FONTCONFIG_PATH");
1490 if (*e
++ == FC_SEARCH_PATH_SEPARATOR
)
1493 path
= calloc (npath
, sizeof (FcChar8
*));
1503 colon
= (FcChar8
*) strchr ((char *) e
, FC_SEARCH_PATH_SEPARATOR
);
1505 colon
= e
+ strlen ((char *) e
);
1506 path
[i
] = malloc (colon
- e
+ 1);
1509 strncpy ((char *) path
[i
], (const char *) e
, colon
- e
);
1510 path
[i
][colon
- e
] = '\0';
1519 dir
= (FcChar8
*) FONTCONFIG_PATH
;
1520 path
[i
] = malloc (strlen ((char *) dir
) + 1);
1523 strcpy ((char *) path
[i
], (const char *) dir
);
1527 for (i
= 0; path
[i
]; i
++)
1535 FcConfigFreePath (FcChar8
**path
)
1539 for (p
= path
; *p
; p
++)
1544 static FcBool _FcConfigHomeEnabled
= FcTrue
;
1549 if (_FcConfigHomeEnabled
)
1551 char *home
= getenv ("HOME");
1555 home
= getenv ("USERPROFILE");
1564 FcConfigEnableHome (FcBool enable
)
1566 FcBool prev
= _FcConfigHomeEnabled
;
1567 _FcConfigHomeEnabled
= enable
;
1572 FcConfigFilename (const FcChar8
*url
)
1574 FcChar8
*file
, *dir
, **path
, **p
;
1578 url
= (FcChar8
*) getenv ("FONTCONFIG_FILE");
1580 url
= (FcChar8
*) FONTCONFIG_FILE
;
1585 if (isalpha (*url
) &&
1587 (url
[2] == '/' || url
[2] == '\\'))
1593 dir
= FcConfigHome ();
1595 file
= FcConfigFileExists (dir
, url
+ 1);
1604 file
= FcConfigFileExists (0, url
);
1607 path
= FcConfigGetPath ();
1610 for (p
= path
; *p
; p
++)
1612 file
= FcConfigFileExists (*p
, url
);
1616 FcConfigFreePath (path
);
1623 * Manage the application-specific fonts
1627 FcConfigAppFontAddFile (FcConfig
*config
,
1628 const FcChar8
*file
)
1637 config
= FcConfigGetCurrent ();
1642 subdirs
= FcStrSetCreate ();
1646 set
= FcConfigGetFonts (config
, FcSetApplication
);
1649 set
= FcFontSetCreate ();
1652 FcStrSetDestroy (subdirs
);
1655 FcConfigSetFonts (config
, set
, FcSetApplication
);
1658 if (!FcFileScanConfig (set
, subdirs
, 0, config
->blanks
, file
, FcFalse
, config
))
1660 FcStrSetDestroy (subdirs
);
1663 if ((sublist
= FcStrListCreate (subdirs
)))
1665 while ((subdir
= FcStrListNext (sublist
)))
1667 FcConfigAppFontAddDir (config
, subdir
);
1669 FcStrListDone (sublist
);
1675 FcConfigAppFontAddDir (FcConfig
*config
,
1685 config
= FcConfigGetCurrent ();
1689 subdirs
= FcStrSetCreate ();
1693 set
= FcConfigGetFonts (config
, FcSetApplication
);
1696 set
= FcFontSetCreate ();
1699 FcStrSetDestroy (subdirs
);
1702 FcConfigSetFonts (config
, set
, FcSetApplication
);
1705 if (!FcDirScanConfig (set
, subdirs
, 0, config
->blanks
, dir
, FcFalse
, config
))
1707 FcStrSetDestroy (subdirs
);
1710 if ((sublist
= FcStrListCreate (subdirs
)))
1712 while ((subdir
= FcStrListNext (sublist
)))
1714 FcConfigAppFontAddDir (config
, subdir
);
1716 FcStrListDone (sublist
);
1722 FcConfigAppFontClear (FcConfig
*config
)
1724 FcConfigSetFonts (config
, 0, FcSetApplication
);
1728 * Manage filename-based font source selectors
1732 FcConfigGlobAdd (FcConfig
*config
,
1733 const FcChar8
*glob
,
1736 FcStrSet
*set
= accept
? config
->acceptGlobs
: config
->rejectGlobs
;
1738 return FcStrSetAdd (set
, glob
);
1742 FcConfigGlobMatch (const FcChar8
*glob
,
1743 const FcChar8
*string
)
1747 while ((c
= *glob
++))
1751 /* short circuit common case */
1754 /* short circuit another common case */
1755 if (strchr ((char *) glob
, '*') == 0)
1756 string
+= strlen ((char *) string
) - strlen ((char *) glob
);
1759 if (FcConfigGlobMatch (glob
, string
))
1765 if (*string
++ == '\0')
1774 return *string
== '\0';
1778 FcConfigGlobsMatch (const FcStrSet
*globs
,
1779 const FcChar8
*string
)
1783 for (i
= 0; i
< globs
->num
; i
++)
1784 if (FcConfigGlobMatch (globs
->strs
[i
], string
))
1790 FcConfigAcceptFilename (FcConfig
*config
,
1791 const FcChar8
*filename
)
1793 if (FcConfigGlobsMatch (config
->acceptGlobs
, filename
))
1795 if (FcConfigGlobsMatch (config
->rejectGlobs
, filename
))