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
);
164 FcMemFree (FC_MEM_SUBST
, sizeof (FcSubst
));
170 FcConfigDestroy (FcConfig
*config
)
174 if (config
== _fcConfig
)
177 FcStrSetDestroy (config
->configDirs
);
178 FcStrSetDestroy (config
->fontDirs
);
179 FcStrSetDestroy (config
->configFiles
);
180 FcStrSetDestroy (config
->acceptGlobs
);
181 FcStrSetDestroy (config
->rejectGlobs
);
184 FcBlanksDestroy (config
->blanks
);
187 FcStrFree (config
->cache
);
189 FcSubstDestroy (config
->substPattern
);
190 FcSubstDestroy (config
->substFont
);
191 for (set
= FcSetSystem
; set
<= FcSetApplication
; set
++)
192 if (config
->fonts
[set
])
193 FcFontSetDestroy (config
->fonts
[set
]);
196 FcMemFree (FC_MEM_CONFIG
, sizeof (FcConfig
));
200 * Scan the current list of directories in the configuration
201 * and build the set of available fonts. Update the
202 * per-user cache file to reflect the new configuration
206 FcConfigBuildFonts (FcConfig
*config
)
209 FcGlobalCache
*cache
;
213 fonts
= FcFontSetCreate ();
217 cache
= FcGlobalCacheCreate ();
222 FcGlobalCacheLoad (cache
, config
->cache
);
224 list
= FcConfigGetFontDirs (config
);
228 while ((dir
= FcStrListNext (list
)))
230 if (FcDebug () & FC_DBG_FONTSET
)
231 printf ("scan dir %s\n", dir
);
232 FcDirScanConfig (fonts
, config
->fontDirs
, cache
,
233 config
->blanks
, dir
, FcFalse
, config
);
236 FcStrListDone (list
);
238 if (FcDebug () & FC_DBG_FONTSET
)
239 FcFontSetPrint (fonts
);
242 FcGlobalCacheSave (cache
, config
->cache
);
243 FcGlobalCacheDestroy (cache
);
245 FcConfigSetFonts (config
, fonts
, FcSetSystem
);
249 FcFontSetDestroy (fonts
);
255 FcConfigSetCurrent (FcConfig
*config
)
258 if (!FcConfigBuildFonts (config
))
262 FcConfigDestroy (_fcConfig
);
268 FcConfigGetCurrent (void)
277 FcConfigAddConfigDir (FcConfig
*config
,
280 return FcStrSetAddFilename (config
->configDirs
, d
);
284 FcConfigGetConfigDirs (FcConfig
*config
)
288 config
= FcConfigGetCurrent ();
292 return FcStrListCreate (config
->configDirs
);
296 FcConfigAddFontDir (FcConfig
*config
,
299 return FcStrSetAddFilename (config
->fontDirs
, d
);
303 FcConfigAddDir (FcConfig
*config
,
306 return (FcConfigAddConfigDir (config
, d
) &&
307 FcConfigAddFontDir (config
, d
));
311 FcConfigGetFontDirs (FcConfig
*config
)
315 config
= FcConfigGetCurrent ();
319 return FcStrListCreate (config
->fontDirs
);
323 FcConfigAddConfigFile (FcConfig
*config
,
327 FcChar8
*file
= FcConfigFilename (f
);
332 ret
= FcStrSetAdd (config
->configFiles
, file
);
338 FcConfigGetConfigFiles (FcConfig
*config
)
342 config
= FcConfigGetCurrent ();
346 return FcStrListCreate (config
->configFiles
);
350 FcConfigSetCache (FcConfig
*config
,
353 FcChar8
*new = FcStrCopyFilename (c
);
358 FcStrFree (config
->cache
);
364 FcConfigGetCache (FcConfig
*config
)
368 config
= FcConfigGetCurrent ();
372 return config
->cache
;
376 FcConfigGetFonts (FcConfig
*config
,
381 config
= FcConfigGetCurrent ();
385 return config
->fonts
[set
];
389 FcConfigSetFonts (FcConfig
*config
,
393 if (config
->fonts
[set
])
394 FcFontSetDestroy (config
->fonts
[set
]);
395 config
->fonts
[set
] = fonts
;
401 FcConfigGetBlanks (FcConfig
*config
)
405 config
= FcConfigGetCurrent ();
409 return config
->blanks
;
413 FcConfigAddBlank (FcConfig
*config
,
421 b
= FcBlanksCreate ();
425 if (!FcBlanksAdd (b
, blank
))
432 FcConfigGetRescanInverval (FcConfig
*config
)
436 config
= FcConfigGetCurrent ();
440 return config
->rescanInterval
;
444 FcConfigSetRescanInverval (FcConfig
*config
, int rescanInterval
)
448 config
= FcConfigGetCurrent ();
452 config
->rescanInterval
= rescanInterval
;
457 FcConfigAddEdit (FcConfig
*config
,
462 FcSubst
*subst
, **prev
;
466 subst
= (FcSubst
*) malloc (sizeof (FcSubst
));
469 FcMemAlloc (FC_MEM_SUBST
, sizeof (FcSubst
));
470 if (kind
== FcMatchPattern
)
471 prev
= &config
->substPattern
;
473 prev
= &config
->substFont
;
474 for (; *prev
; prev
= &(*prev
)->next
);
480 for (t
= test
; t
; t
= t
->next
)
482 if (t
->kind
== FcMatchDefault
)
486 if (config
->maxObjects
< num
)
487 config
->maxObjects
= num
;
488 if (FcDebug () & FC_DBG_EDIT
)
490 printf ("Add Subst ");
491 FcSubstPrint (subst
);
496 typedef struct _FcSubState
{
502 FcConfigPromote (FcValue v
, FcValue u
)
504 if (v
.type
== FcTypeInteger
)
506 v
.type
= FcTypeDouble
;
507 v
.u
.d
= (double) v
.u
.i
;
509 else if (v
.type
== FcTypeVoid
&& u
.type
== FcTypeMatrix
)
511 v
.u
.m
= &FcIdentityMatrix
;
512 v
.type
= FcTypeMatrix
;
514 else if (v
.type
== FcTypeString
&& u
.type
== FcTypeLangSet
)
516 v
.u
.l
= FcLangSetPromote (v
.u
.s
);
517 v
.type
= FcTypeLangSet
;
523 FcConfigCompareValue (const FcValue left_o
,
525 const FcValue right_o
)
527 FcValue left
= left_o
;
528 FcValue right
= right_o
;
529 FcBool ret
= FcFalse
;
531 left
= FcConfigPromote (left
, right
);
532 right
= FcConfigPromote (right
, left
);
533 if (left
.type
== right
.type
)
537 break; /* FcConfigPromote prevents this from happening */
543 ret
= left
.u
.d
== right
.u
.d
;
546 case FcOpNotContains
:
547 ret
= left
.u
.d
!= right
.u
.d
;
550 ret
= left
.u
.d
< right
.u
.d
;
553 ret
= left
.u
.d
<= right
.u
.d
;
556 ret
= left
.u
.d
> right
.u
.d
;
559 ret
= left
.u
.d
>= right
.u
.d
;
570 ret
= left
.u
.b
== right
.u
.b
;
573 case FcOpNotContains
:
574 ret
= left
.u
.b
!= right
.u
.b
;
584 ret
= FcStrCmpIgnoreCase (left
.u
.s
, right
.u
.s
) == 0;
587 ret
= FcStrStrIgnoreCase (left
.u
.s
, right
.u
.s
) != 0;
590 case FcOpNotContains
:
591 ret
= FcStrCmpIgnoreCase (left
.u
.s
, right
.u
.s
) != 0;
602 ret
= FcMatrixEqual (left
.u
.m
, right
.u
.m
);
605 case FcOpNotContains
:
606 ret
= !FcMatrixEqual (left
.u
.m
, right
.u
.m
);
616 /* left contains right if right is a subset of left */
617 ret
= FcCharSetIsSubset (right
.u
.c
, left
.u
.c
);
619 case FcOpNotContains
:
620 /* left contains right if right is a subset of left */
621 ret
= !FcCharSetIsSubset (right
.u
.c
, left
.u
.c
);
624 ret
= FcCharSetEqual (left
.u
.c
, right
.u
.c
);
627 ret
= !FcCharSetEqual (left
.u
.c
, right
.u
.c
);
637 ret
= FcLangSetContains (left
.u
.l
, right
.u
.l
);
639 case FcOpNotContains
:
640 ret
= FcLangSetContains (left
.u
.l
, right
.u
.l
);
643 ret
= FcLangSetEqual (left
.u
.l
, right
.u
.l
);
646 ret
= !FcLangSetEqual (left
.u
.l
, right
.u
.l
);
668 ret
= left
.u
.f
== right
.u
.f
;
671 case FcOpNotContains
:
672 ret
= left
.u
.f
!= right
.u
.f
;
682 if (op
== FcOpNotEqual
|| op
== FcOpNotContains
)
689 #define _FcDoubleFloor(d) ((int) (d))
690 #define _FcDoubleCeil(d) ((double) (int) (d) == (d) ? (int) (d) : (int) ((d) + 1))
691 #define FcDoubleFloor(d) ((d) >= 0 ? _FcDoubleFloor(d) : -_FcDoubleCeil(-(d)))
692 #define FcDoubleCeil(d) ((d) >= 0 ? _FcDoubleCeil(d) : -_FcDoubleFloor(-(d)))
693 #define FcDoubleRound(d) FcDoubleFloor ((d) + 0.5)
694 #define FcDoubleTrunc(d) ((d) >= 0 ? _FcDoubleFloor (d) : -_FcDoubleFloor (-(d)))
697 FcConfigEvaluate (FcPattern
*p
, FcExpr
*e
)
705 v
.type
= FcTypeInteger
;
709 v
.type
= FcTypeDouble
;
713 v
.type
= FcTypeString
;
718 v
.type
= FcTypeMatrix
;
723 v
.type
= FcTypeCharSet
;
732 r
= FcPatternGet (p
, e
->u
.field
, 0, &v
);
733 if (r
!= FcResultMatch
)
737 if (FcNameConstant (e
->u
.constant
, &v
.u
.i
))
738 v
.type
= FcTypeInteger
;
743 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
744 if (vl
.type
== FcTypeBool
)
747 v
= FcConfigEvaluate (p
, e
->u
.tree
.right
->u
.tree
.left
);
749 v
= FcConfigEvaluate (p
, e
->u
.tree
.right
->u
.tree
.right
);
762 case FcOpNotContains
:
764 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
765 vr
= FcConfigEvaluate (p
, e
->u
.tree
.right
);
767 v
.u
.b
= FcConfigCompareValue (vl
, e
->op
, vr
);
777 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
778 vr
= FcConfigEvaluate (p
, e
->u
.tree
.right
);
779 vl
= FcConfigPromote (vl
, vr
);
780 vr
= FcConfigPromote (vr
, vl
);
781 if (vl
.type
== vr
.type
)
787 v
.type
= FcTypeDouble
;
788 v
.u
.d
= vl
.u
.d
+ vr
.u
.d
;
791 v
.type
= FcTypeDouble
;
792 v
.u
.d
= vl
.u
.d
- vr
.u
.d
;
795 v
.type
= FcTypeDouble
;
796 v
.u
.d
= vl
.u
.d
* vr
.u
.d
;
799 v
.type
= FcTypeDouble
;
800 v
.u
.d
= vl
.u
.d
/ vr
.u
.d
;
806 if (v
.type
== FcTypeDouble
&&
807 v
.u
.d
== (double) (int) v
.u
.d
)
809 v
.type
= FcTypeInteger
;
817 v
.u
.b
= vl
.u
.b
|| vr
.u
.b
;
821 v
.u
.b
= vl
.u
.b
&& vr
.u
.b
;
831 v
.type
= FcTypeString
;
832 v
.u
.s
= FcStrPlus (vl
.u
.s
, vr
.u
.s
);
844 v
.type
= FcTypeMatrix
;
845 m
= malloc (sizeof (FcMatrix
));
848 FcMemAlloc (FC_MEM_MATRIX
, sizeof (FcMatrix
));
849 FcMatrixMultiply (m
, vl
.u
.m
, vr
.u
.m
);
873 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
886 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
892 v
.type
= FcTypeInteger
;
893 v
.u
.i
= FcDoubleFloor (vl
.u
.d
);
902 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
908 v
.type
= FcTypeInteger
;
909 v
.u
.i
= FcDoubleCeil (vl
.u
.d
);
918 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
924 v
.type
= FcTypeInteger
;
925 v
.u
.i
= FcDoubleRound (vl
.u
.d
);
934 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
940 v
.type
= FcTypeInteger
;
941 v
.u
.i
= FcDoubleTrunc (vl
.u
.d
);
957 FcConfigMatchValueList (FcPattern
*p
,
961 FcValueList
*ret
= 0;
968 /* Compute the value of the match expression */
969 if (e
->op
== FcOpComma
)
971 value
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
976 value
= FcConfigEvaluate (p
, e
);
980 for (v
= values
; v
; v
= v
->next
)
982 /* Compare the pattern value to the match expression value */
983 if (FcConfigCompareValue (v
->value
, t
->op
, value
))
990 if (t
->qual
== FcQualAll
)
997 FcValueDestroy (value
);
1002 static FcValueList
*
1003 FcConfigValues (FcPattern
*p
, FcExpr
*e
, FcValueBinding binding
)
1009 l
= (FcValueList
*) malloc (sizeof (FcValueList
));
1012 FcMemAlloc (FC_MEM_VALLIST
, sizeof (FcValueList
));
1013 if (e
->op
== FcOpComma
)
1015 l
->value
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
1016 l
->next
= FcConfigValues (p
, e
->u
.tree
.right
, binding
);
1020 l
->value
= FcConfigEvaluate (p
, e
);
1023 l
->binding
= binding
;
1024 while (l
&& l
->value
.type
== FcTypeVoid
)
1026 FcValueList
*next
= l
->next
;
1028 FcMemFree (FC_MEM_VALLIST
, sizeof (FcValueList
));
1036 FcConfigAdd (FcValueList
**head
,
1037 FcValueList
*position
,
1041 FcValueList
**prev
, *last
, *v
;
1042 FcValueBinding sameBinding
;
1045 sameBinding
= position
->binding
;
1047 sameBinding
= FcValueBindingWeak
;
1048 for (v
= new; v
; v
= v
->next
)
1049 if (v
->binding
== FcValueBindingSame
)
1050 v
->binding
= sameBinding
;
1054 prev
= &position
->next
;
1056 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1063 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1065 if (*prev
== position
)
1072 if (FcDebug () & FC_DBG_EDIT
)
1075 printf ("position not on list\n");
1079 if (FcDebug () & FC_DBG_EDIT
)
1081 printf ("%s list before ", append
? "Append" : "Prepend");
1082 FcValueListPrint (*head
);
1096 if (FcDebug () & FC_DBG_EDIT
)
1098 printf ("%s list after ", append
? "Append" : "Prepend");
1099 FcValueListPrint (*head
);
1107 FcConfigDel (FcValueList
**head
,
1108 FcValueList
*position
)
1112 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1114 if (*prev
== position
)
1116 *prev
= position
->next
;
1118 FcValueListDestroy (position
);
1125 FcConfigPatternAdd (FcPattern
*p
,
1132 FcPatternElt
*e
= FcPatternInsertElt (p
, object
);
1136 FcConfigAdd (&e
->values
, 0, append
, list
);
1141 * Delete all values associated with a field
1144 FcConfigPatternDel (FcPattern
*p
,
1147 FcPatternElt
*e
= FcPatternFindElt (p
, object
);
1151 FcConfigDel (&e
->values
, e
->values
);
1155 FcConfigPatternCanon (FcPattern
*p
,
1158 FcPatternElt
*e
= FcPatternFindElt (p
, object
);
1162 FcPatternDel (p
, object
);
1166 FcConfigSubstituteWithPat (FcConfig
*config
,
1181 config
= FcConfigGetCurrent ();
1186 st
= (FcSubState
*) malloc (config
->maxObjects
* sizeof (FcSubState
));
1187 if (!st
&& config
->maxObjects
)
1189 FcMemAlloc (FC_MEM_SUBSTATE
, config
->maxObjects
* sizeof (FcSubState
));
1191 if (FcDebug () & FC_DBG_EDIT
)
1193 printf ("FcConfigSubstitute ");
1196 if (kind
== FcMatchPattern
)
1197 s
= config
->substPattern
;
1199 s
= config
->substFont
;
1200 for (; s
; s
= s
->next
)
1203 * Check the tests to see if
1204 * they all match the pattern
1206 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1208 if (FcDebug () & FC_DBG_EDIT
)
1210 printf ("FcConfigSubstitute test ");
1214 if (kind
== FcMatchFont
&& t
->kind
== FcMatchPattern
)
1219 st
[i
].elt
= FcPatternFindElt (m
, t
->field
);
1223 * If there's no such field in the font,
1224 * then FcQualAll matches while FcQualAny does not
1228 if (t
->qual
== FcQualAll
)
1237 * Check to see if there is a match, mark the location
1238 * to apply match-relative edits
1240 st
[i
].value
= FcConfigMatchValueList (m
, t
, st
[i
].elt
->values
);
1243 if (t
->qual
== FcQualFirst
&& st
[i
].value
!= st
[i
].elt
->values
)
1245 if (t
->qual
== FcQualNotFirst
&& st
[i
].value
== st
[i
].elt
->values
)
1250 if (FcDebug () & FC_DBG_EDIT
)
1251 printf ("No match\n");
1254 if (FcDebug () & FC_DBG_EDIT
)
1256 printf ("Substitute ");
1259 for (e
= s
->edit
; e
; e
= e
->next
)
1262 * Evaluate the list of expressions
1264 l
= FcConfigValues (p
, e
->expr
, e
->binding
);
1266 * Locate any test associated with this field, skipping
1267 * tests associated with the pattern when substituting in
1270 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1272 if ((t
->kind
== FcMatchFont
|| kind
== FcMatchPattern
) &&
1273 !FcStrCmpIgnoreCase ((FcChar8
*) t
->field
,
1274 (FcChar8
*) e
->field
))
1277 * KLUDGE - the pattern may have been reallocated or
1278 * things may have been inserted or deleted above
1279 * this element by other edits. Go back and find
1282 if (e
!= s
->edit
&& st
[i
].elt
)
1283 st
[i
].elt
= FcPatternFindElt (p
, t
->field
);
1292 * If there was a test, then replace the matched
1293 * value with the new list of values
1297 FcValueList
*thisValue
= st
[i
].value
;
1298 FcValueList
*nextValue
= thisValue
? thisValue
->next
: 0;
1301 * Append the new list of values after the current value
1303 FcConfigAdd (&st
[i
].elt
->values
, thisValue
, FcTrue
, l
);
1305 * Delete the marked value
1307 FcConfigDel (&st
[i
].elt
->values
, thisValue
);
1309 * Adjust any pointers into the value list to ensure
1310 * future edits occur at the same place
1312 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1314 if (st
[i
].value
== thisValue
)
1315 st
[i
].value
= nextValue
;
1319 /* fall through ... */
1320 case FcOpAssignReplace
:
1322 * Delete all of the values and insert
1325 FcConfigPatternDel (p
, e
->field
);
1326 FcConfigPatternAdd (p
, e
->field
, l
, FcTrue
);
1328 * Adjust any pointers into the value list as they no
1329 * longer point to anything valid
1333 FcPatternElt
*thisElt
= st
[i
].elt
;
1334 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1336 if (st
[i
].elt
== thisElt
)
1344 FcConfigAdd (&st
[i
].elt
->values
, st
[i
].value
, FcFalse
, l
);
1347 /* fall through ... */
1348 case FcOpPrependFirst
:
1349 FcConfigPatternAdd (p
, e
->field
, l
, FcFalse
);
1354 FcConfigAdd (&st
[i
].elt
->values
, st
[i
].value
, FcTrue
, l
);
1357 /* fall through ... */
1358 case FcOpAppendLast
:
1359 FcConfigPatternAdd (p
, e
->field
, l
, FcTrue
);
1366 * Now go through the pattern and eliminate
1367 * any properties without data
1369 for (e
= s
->edit
; e
; e
= e
->next
)
1370 FcConfigPatternCanon (p
, e
->field
);
1372 if (FcDebug () & FC_DBG_EDIT
)
1374 printf ("FcConfigSubstitute edit");
1378 FcMemFree (FC_MEM_SUBSTATE
, config
->maxObjects
* sizeof (FcSubState
));
1380 if (FcDebug () & FC_DBG_EDIT
)
1382 printf ("FcConfigSubstitute done");
1389 FcConfigSubstitute (FcConfig
*config
,
1393 return FcConfigSubstituteWithPat (config
, p
, 0, kind
);
1396 #if defined (_WIN32) && (defined (PIC) || defined (DLL_EXPORT))
1398 static FcChar8 fontconfig_path
[1000] = "";
1401 DllMain (HINSTANCE hinstDLL
,
1407 switch (fdwReason
) {
1408 case DLL_PROCESS_ATTACH
:
1409 if (!GetModuleFileName ((HMODULE
) hinstDLL
, fontconfig_path
,
1410 sizeof (fontconfig_path
)))
1413 /* If the fontconfig DLL is in a "bin" or "lib" subfolder,
1414 * assume it's a Unix-style installation tree, and use
1415 * "etc/fonts" in there as FONTCONFIG_PATH. Otherwise use the
1416 * folder where the DLL is as FONTCONFIG_PATH.
1418 p
= strrchr (fontconfig_path
, '\\');
1422 p
= strrchr (fontconfig_path
, '\\');
1423 if (p
&& (FcStrCmpIgnoreCase (p
+ 1, "bin") == 0 ||
1424 FcStrCmpIgnoreCase (p
+ 1, "lib") == 0))
1426 strcat (fontconfig_path
, "\\etc\\fonts");
1429 fontconfig_path
[0] = '\0';
1437 #undef FONTCONFIG_PATH
1438 #define FONTCONFIG_PATH fontconfig_path
1440 #else /* !(_WIN32 && PIC) */
1442 #endif /* !(_WIN32 && PIC) */
1444 #ifndef FONTCONFIG_FILE
1445 #define FONTCONFIG_FILE "fonts.conf"
1449 FcConfigFileExists (const FcChar8
*dir
, const FcChar8
*file
)
1454 dir
= (FcChar8
*) "";
1455 path
= malloc (strlen ((char *) dir
) + 1 + strlen ((char *) file
) + 1);
1459 strcpy ((char *) path
, (const char *) dir
);
1460 /* make sure there's a single separator */
1462 if ((!path
[0] || (path
[strlen((char *) path
)-1] != '/' &&
1463 path
[strlen((char *) path
)-1] != '\\')) &&
1464 (file
[0] != '/' && file
[0] != '\\'))
1465 strcat ((char *) path
, "\\");
1467 if ((!path
[0] || path
[strlen((char *) path
)-1] != '/') && file
[0] != '/')
1468 strcat ((char *) path
, "/");
1470 strcat ((char *) path
, (char *) file
);
1472 FcMemAlloc (FC_MEM_STRING
, strlen ((char *) path
) + 1);
1473 if (access ((char *) path
, R_OK
) == 0)
1481 FcConfigGetPath (void)
1484 FcChar8
*env
, *e
, *colon
;
1489 npath
= 2; /* default dir + null */
1490 env
= (FcChar8
*) getenv ("FONTCONFIG_PATH");
1496 if (*e
++ == FC_SEARCH_PATH_SEPARATOR
)
1499 path
= calloc (npath
, sizeof (FcChar8
*));
1509 colon
= (FcChar8
*) strchr ((char *) e
, FC_SEARCH_PATH_SEPARATOR
);
1511 colon
= e
+ strlen ((char *) e
);
1512 path
[i
] = malloc (colon
- e
+ 1);
1515 strncpy ((char *) path
[i
], (const char *) e
, colon
- e
);
1516 path
[i
][colon
- e
] = '\0';
1525 dir
= (FcChar8
*) FONTCONFIG_PATH
;
1526 path
[i
] = malloc (strlen ((char *) dir
) + 1);
1529 strcpy ((char *) path
[i
], (const char *) dir
);
1533 for (i
= 0; path
[i
]; i
++)
1541 FcConfigFreePath (FcChar8
**path
)
1545 for (p
= path
; *p
; p
++)
1550 static FcBool _FcConfigHomeEnabled
= FcTrue
;
1555 if (_FcConfigHomeEnabled
)
1557 char *home
= getenv ("HOME");
1561 home
= getenv ("USERPROFILE");
1570 FcConfigEnableHome (FcBool enable
)
1572 FcBool prev
= _FcConfigHomeEnabled
;
1573 _FcConfigHomeEnabled
= enable
;
1578 FcConfigFilename (const FcChar8
*url
)
1580 FcChar8
*file
, *dir
, **path
, **p
;
1584 url
= (FcChar8
*) getenv ("FONTCONFIG_FILE");
1586 url
= (FcChar8
*) FONTCONFIG_FILE
;
1591 if (isalpha (*url
) &&
1593 (url
[2] == '/' || url
[2] == '\\'))
1599 dir
= FcConfigHome ();
1601 file
= FcConfigFileExists (dir
, url
+ 1);
1610 file
= FcConfigFileExists (0, url
);
1613 path
= FcConfigGetPath ();
1616 for (p
= path
; *p
; p
++)
1618 file
= FcConfigFileExists (*p
, url
);
1622 FcConfigFreePath (path
);
1629 * Manage the application-specific fonts
1633 FcConfigAppFontAddFile (FcConfig
*config
,
1634 const FcChar8
*file
)
1643 config
= FcConfigGetCurrent ();
1648 subdirs
= FcStrSetCreate ();
1652 set
= FcConfigGetFonts (config
, FcSetApplication
);
1655 set
= FcFontSetCreate ();
1658 FcStrSetDestroy (subdirs
);
1661 FcConfigSetFonts (config
, set
, FcSetApplication
);
1664 if (!FcFileScanConfig (set
, subdirs
, 0, config
->blanks
, file
, FcFalse
, config
))
1666 FcStrSetDestroy (subdirs
);
1669 if ((sublist
= FcStrListCreate (subdirs
)))
1671 while ((subdir
= FcStrListNext (sublist
)))
1673 FcConfigAppFontAddDir (config
, subdir
);
1675 FcStrListDone (sublist
);
1681 FcConfigAppFontAddDir (FcConfig
*config
,
1691 config
= FcConfigGetCurrent ();
1695 subdirs
= FcStrSetCreate ();
1699 set
= FcConfigGetFonts (config
, FcSetApplication
);
1702 set
= FcFontSetCreate ();
1705 FcStrSetDestroy (subdirs
);
1708 FcConfigSetFonts (config
, set
, FcSetApplication
);
1711 if (!FcDirScanConfig (set
, subdirs
, 0, config
->blanks
, dir
, FcFalse
, config
))
1713 FcStrSetDestroy (subdirs
);
1716 if ((sublist
= FcStrListCreate (subdirs
)))
1718 while ((subdir
= FcStrListNext (sublist
)))
1720 FcConfigAppFontAddDir (config
, subdir
);
1722 FcStrListDone (sublist
);
1728 FcConfigAppFontClear (FcConfig
*config
)
1732 config
= FcConfigGetCurrent ();
1737 FcConfigSetFonts (config
, 0, FcSetApplication
);
1741 * Manage filename-based font source selectors
1745 FcConfigGlobAdd (FcConfig
*config
,
1746 const FcChar8
*glob
,
1749 FcStrSet
*set
= accept
? config
->acceptGlobs
: config
->rejectGlobs
;
1751 return FcStrSetAdd (set
, glob
);
1755 FcConfigGlobMatch (const FcChar8
*glob
,
1756 const FcChar8
*string
)
1760 while ((c
= *glob
++))
1764 /* short circuit common case */
1767 /* short circuit another common case */
1768 if (strchr ((char *) glob
, '*') == 0)
1769 string
+= strlen ((char *) string
) - strlen ((char *) glob
);
1772 if (FcConfigGlobMatch (glob
, string
))
1778 if (*string
++ == '\0')
1787 return *string
== '\0';
1791 FcConfigGlobsMatch (const FcStrSet
*globs
,
1792 const FcChar8
*string
)
1796 for (i
= 0; i
< globs
->num
; i
++)
1797 if (FcConfigGlobMatch (globs
->strs
[i
], string
))
1803 FcConfigAcceptFilename (FcConfig
*config
,
1804 const FcChar8
*filename
)
1806 if (FcConfigGlobsMatch (config
->acceptGlobs
, filename
))
1808 if (FcConfigGlobsMatch (config
->rejectGlobs
, filename
))