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)
41 config
= malloc (sizeof (FcConfig
));
44 FcMemAlloc (FC_MEM_CONFIG
, sizeof (FcConfig
));
46 config
->configDirs
= FcStrSetCreate ();
47 if (!config
->configDirs
)
50 config
->configFiles
= FcStrSetCreate ();
51 if (!config
->configFiles
)
54 config
->fontDirs
= FcStrSetCreate ();
55 if (!config
->fontDirs
)
58 config
->acceptGlobs
= FcStrSetCreate ();
59 if (!config
->acceptGlobs
)
62 config
->rejectGlobs
= FcStrSetCreate ();
63 if (!config
->rejectGlobs
)
68 if (!FcConfigSetCache (config
, (FcChar8
*) ("~/" FC_USER_CACHE_FILE
)))
73 config
->substPattern
= 0;
74 config
->substFont
= 0;
75 config
->maxObjects
= 0;
76 for (set
= FcSetSystem
; set
<= FcSetApplication
; set
++)
77 config
->fonts
[set
] = 0;
79 config
->rescanTime
= time(0);
80 config
->rescanInterval
= 30;
85 FcStrSetDestroy (config
->rejectGlobs
);
87 FcStrSetDestroy (config
->acceptGlobs
);
89 FcStrSetDestroy (config
->fontDirs
);
91 FcStrSetDestroy (config
->configFiles
);
93 FcStrSetDestroy (config
->configDirs
);
96 FcMemFree (FC_MEM_CONFIG
, sizeof (FcConfig
));
101 typedef struct _FcFileTime
{
107 FcConfigNewestFile (FcStrSet
*files
)
109 FcStrList
*list
= FcStrListCreate (files
);
110 FcFileTime newest
= { 0, FcFalse
};
116 while ((file
= FcStrListNext (list
)))
117 if (stat ((char *) file
, &statb
) == 0)
118 if (!newest
.set
|| statb
.st_mtime
- newest
.time
> 0)
119 newest
.time
= statb
.st_mtime
;
120 FcStrListDone (list
);
126 FcConfigUptoDate (FcConfig
*config
)
128 FcFileTime config_time
, font_time
;
129 time_t now
= time(0);
132 config
= FcConfigGetCurrent ();
136 config_time
= FcConfigNewestFile (config
->configFiles
);
137 font_time
= FcConfigNewestFile (config
->configDirs
);
138 if ((config_time
.set
&& config_time
.time
- config
->rescanTime
> 0) ||
139 (font_time
.set
&& font_time
.time
- config
->rescanTime
) > 0)
143 config
->rescanTime
= now
;
148 FcSubstDestroy (FcSubst
*s
)
156 FcTestDestroy (s
->test
);
158 FcEditDestroy (s
->edit
);
164 FcConfigDestroy (FcConfig
*config
)
168 if (config
== _fcConfig
)
171 FcStrSetDestroy (config
->configDirs
);
172 FcStrSetDestroy (config
->fontDirs
);
173 FcStrSetDestroy (config
->configFiles
);
174 FcStrSetDestroy (config
->acceptGlobs
);
175 FcStrSetDestroy (config
->rejectGlobs
);
177 FcStrFree (config
->cache
);
179 FcSubstDestroy (config
->substPattern
);
180 FcSubstDestroy (config
->substFont
);
181 for (set
= FcSetSystem
; set
<= FcSetApplication
; set
++)
182 if (config
->fonts
[set
])
183 FcFontSetDestroy (config
->fonts
[set
]);
185 FcMemFree (FC_MEM_CONFIG
, sizeof (FcConfig
));
189 * Scan the current list of directories in the configuration
190 * and build the set of available fonts. Update the
191 * per-user cache file to reflect the new configuration
195 FcConfigBuildFonts (FcConfig
*config
)
198 FcGlobalCache
*cache
;
202 fonts
= FcFontSetCreate ();
206 cache
= FcGlobalCacheCreate ();
210 FcGlobalCacheLoad (cache
, config
->cache
);
212 list
= FcConfigGetFontDirs (config
);
216 while ((dir
= FcStrListNext (list
)))
218 if (FcDebug () & FC_DBG_FONTSET
)
219 printf ("scan dir %s\n", dir
);
220 FcDirScanConfig (fonts
, config
->fontDirs
, cache
,
221 config
->blanks
, dir
, FcFalse
, config
);
224 FcStrListDone (list
);
226 if (FcDebug () & FC_DBG_FONTSET
)
227 FcFontSetPrint (fonts
);
229 FcGlobalCacheSave (cache
, config
->cache
);
230 FcGlobalCacheDestroy (cache
);
232 FcConfigSetFonts (config
, fonts
, FcSetSystem
);
236 FcFontSetDestroy (fonts
);
242 FcConfigSetCurrent (FcConfig
*config
)
245 if (!FcConfigBuildFonts (config
))
249 FcConfigDestroy (_fcConfig
);
255 FcConfigGetCurrent (void)
264 FcConfigAddConfigDir (FcConfig
*config
,
267 return FcStrSetAddFilename (config
->configDirs
, d
);
271 FcConfigGetConfigDirs (FcConfig
*config
)
275 config
= FcConfigGetCurrent ();
279 return FcStrListCreate (config
->configDirs
);
283 FcConfigAddFontDir (FcConfig
*config
,
286 return FcStrSetAddFilename (config
->fontDirs
, d
);
290 FcConfigAddDir (FcConfig
*config
,
293 return (FcConfigAddConfigDir (config
, d
) &&
294 FcConfigAddFontDir (config
, d
));
298 FcConfigGetFontDirs (FcConfig
*config
)
302 config
= FcConfigGetCurrent ();
306 return FcStrListCreate (config
->fontDirs
);
310 FcConfigAddConfigFile (FcConfig
*config
,
314 FcChar8
*file
= FcConfigFilename (f
);
319 ret
= FcStrSetAdd (config
->configFiles
, file
);
325 FcConfigGetConfigFiles (FcConfig
*config
)
329 config
= FcConfigGetCurrent ();
333 return FcStrListCreate (config
->configFiles
);
337 FcConfigSetCache (FcConfig
*config
,
340 FcChar8
*new = FcStrCopyFilename (c
);
345 FcStrFree (config
->cache
);
351 FcConfigGetCache (FcConfig
*config
)
355 config
= FcConfigGetCurrent ();
359 return config
->cache
;
363 FcConfigGetFonts (FcConfig
*config
,
368 config
= FcConfigGetCurrent ();
372 return config
->fonts
[set
];
376 FcConfigSetFonts (FcConfig
*config
,
380 if (config
->fonts
[set
])
381 FcFontSetDestroy (config
->fonts
[set
]);
382 config
->fonts
[set
] = fonts
;
388 FcConfigGetBlanks (FcConfig
*config
)
392 config
= FcConfigGetCurrent ();
396 return config
->blanks
;
400 FcConfigAddBlank (FcConfig
*config
,
408 b
= FcBlanksCreate ();
412 if (!FcBlanksAdd (b
, blank
))
419 FcConfigGetRescanInverval (FcConfig
*config
)
423 config
= FcConfigGetCurrent ();
427 return config
->rescanInterval
;
431 FcConfigSetRescanInverval (FcConfig
*config
, int rescanInterval
)
435 config
= FcConfigGetCurrent ();
439 config
->rescanInterval
= rescanInterval
;
444 FcConfigAddEdit (FcConfig
*config
,
449 FcSubst
*subst
, **prev
;
453 subst
= (FcSubst
*) malloc (sizeof (FcSubst
));
456 FcMemAlloc (FC_MEM_SUBST
, sizeof (FcSubst
));
457 if (kind
== FcMatchPattern
)
458 prev
= &config
->substPattern
;
460 prev
= &config
->substFont
;
461 for (; *prev
; prev
= &(*prev
)->next
);
467 for (t
= test
; t
; t
= t
->next
)
469 if (t
->kind
== FcMatchDefault
)
473 if (config
->maxObjects
< num
)
474 config
->maxObjects
= num
;
475 if (FcDebug () & FC_DBG_EDIT
)
477 printf ("Add Subst ");
478 FcSubstPrint (subst
);
483 typedef struct _FcSubState
{
489 FcConfigPromote (FcValue v
, FcValue u
)
491 if (v
.type
== FcTypeInteger
)
493 v
.type
= FcTypeDouble
;
494 v
.u
.d
= (double) v
.u
.i
;
496 else if (v
.type
== FcTypeVoid
&& u
.type
== FcTypeMatrix
)
498 v
.u
.m
= &FcIdentityMatrix
;
499 v
.type
= FcTypeMatrix
;
501 else if (v
.type
== FcTypeString
&& u
.type
== FcTypeLangSet
)
503 v
.u
.l
= FcLangSetPromote (v
.u
.s
);
504 v
.type
= FcTypeLangSet
;
510 FcConfigCompareValue (const FcValue m_o
,
516 FcBool ret
= FcFalse
;
518 m
= FcConfigPromote (m
, v
);
519 v
= FcConfigPromote (v
, m
);
520 if (m
.type
== v
.type
)
524 break; /* FcConfigPromote prevents this from happening */
529 ret
= m
.u
.d
== v
.u
.d
;
532 case FcOpNotContains
:
533 ret
= m
.u
.d
!= v
.u
.d
;
539 ret
= m
.u
.d
<= v
.u
.d
;
545 ret
= m
.u
.d
>= v
.u
.d
;
555 ret
= m
.u
.b
== v
.u
.b
;
558 case FcOpNotContains
:
559 ret
= m
.u
.b
!= v
.u
.b
;
568 ret
= FcStrCmpIgnoreCase (m
.u
.s
, v
.u
.s
) == 0;
571 ret
= FcStrStrIgnoreCase (m
.u
.s
, v
.u
.s
) != 0;
574 ret
= FcStrCmpIgnoreCase (m
.u
.s
, v
.u
.s
) != 0;
576 case FcOpNotContains
:
577 ret
= FcStrStrIgnoreCase (m
.u
.s
, v
.u
.s
) == 0;
587 ret
= FcMatrixEqual (m
.u
.m
, v
.u
.m
);
590 case FcOpNotContains
:
591 ret
= !FcMatrixEqual (m
.u
.m
, v
.u
.m
);
600 /* v contains m if m is a subset of v */
601 ret
= FcCharSetIsSubset (m
.u
.c
, v
.u
.c
);
603 case FcOpNotContains
:
604 /* v contains m if m is a subset of v */
605 ret
= !FcCharSetIsSubset (m
.u
.c
, v
.u
.c
);
608 ret
= FcCharSetEqual (m
.u
.c
, v
.u
.c
);
611 ret
= !FcCharSetEqual (m
.u
.c
, v
.u
.c
);
620 ret
= FcLangSetContains (m
.u
.l
, v
.u
.l
);
622 case FcOpNotContains
:
623 ret
= FcLangSetContains (m
.u
.l
, v
.u
.l
);
626 ret
= FcLangSetEqual (m
.u
.l
, v
.u
.l
);
629 ret
= !FcLangSetEqual (m
.u
.l
, v
.u
.l
);
649 ret
= m
.u
.f
== v
.u
.f
;
652 case FcOpNotContains
:
653 ret
= m
.u
.f
!= v
.u
.f
;
663 if (op
== FcOpNotEqual
|| op
== FcOpNotContains
)
670 #define _FcDoubleFloor(d) ((int) (d))
671 #define _FcDoubleCeil(d) ((double) (int) (d) == (d) ? (int) (d) : (int) ((d) + 1))
672 #define FcDoubleFloor(d) ((d) >= 0 ? _FcDoubleFloor(d) : -_FcDoubleCeil(-(d)))
673 #define FcDoubleCeil(d) ((d) >= 0 ? _FcDoubleCeil(d) : -_FcDoubleFloor(-(d)))
674 #define FcDoubleRound(d) FcDoubleFloor ((d) + 0.5)
675 #define FcDoubleTrunc(d) ((d) >= 0 ? _FcDoubleFloor (d) : -_FcDoubleFloor (-(d)))
678 FcConfigEvaluate (FcPattern
*p
, FcExpr
*e
)
686 v
.type
= FcTypeInteger
;
690 v
.type
= FcTypeDouble
;
694 v
.type
= FcTypeString
;
699 v
.type
= FcTypeMatrix
;
704 v
.type
= FcTypeCharSet
;
713 r
= FcPatternGet (p
, e
->u
.field
, 0, &v
);
714 if (r
!= FcResultMatch
)
718 if (FcNameConstant (e
->u
.constant
, &v
.u
.i
))
719 v
.type
= FcTypeInteger
;
724 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
725 if (vl
.type
== FcTypeBool
)
728 v
= FcConfigEvaluate (p
, e
->u
.tree
.right
->u
.tree
.left
);
730 v
= FcConfigEvaluate (p
, e
->u
.tree
.right
->u
.tree
.right
);
743 case FcOpNotContains
:
744 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
745 vr
= FcConfigEvaluate (p
, e
->u
.tree
.right
);
747 v
.u
.b
= FcConfigCompareValue (vl
, e
->op
, vr
);
757 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
758 vr
= FcConfigEvaluate (p
, e
->u
.tree
.right
);
759 vl
= FcConfigPromote (vl
, vr
);
760 vr
= FcConfigPromote (vr
, vl
);
761 if (vl
.type
== vr
.type
)
767 v
.type
= FcTypeDouble
;
768 v
.u
.d
= vl
.u
.d
+ vr
.u
.d
;
771 v
.type
= FcTypeDouble
;
772 v
.u
.d
= vl
.u
.d
- vr
.u
.d
;
775 v
.type
= FcTypeDouble
;
776 v
.u
.d
= vl
.u
.d
* vr
.u
.d
;
779 v
.type
= FcTypeDouble
;
780 v
.u
.d
= vl
.u
.d
/ vr
.u
.d
;
786 if (v
.type
== FcTypeDouble
&&
787 v
.u
.d
== (double) (int) v
.u
.d
)
789 v
.type
= FcTypeInteger
;
797 v
.u
.b
= vl
.u
.b
|| vr
.u
.b
;
801 v
.u
.b
= vl
.u
.b
&& vr
.u
.b
;
811 v
.type
= FcTypeString
;
812 v
.u
.s
= FcStrPlus (vl
.u
.s
, vr
.u
.s
);
824 v
.type
= FcTypeMatrix
;
825 m
= malloc (sizeof (FcMatrix
));
828 FcMemAlloc (FC_MEM_MATRIX
, sizeof (FcMatrix
));
829 FcMatrixMultiply (m
, vl
.u
.m
, vr
.u
.m
);
853 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
866 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
872 v
.type
= FcTypeInteger
;
873 v
.u
.i
= FcDoubleFloor (vl
.u
.d
);
882 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
888 v
.type
= FcTypeInteger
;
889 v
.u
.i
= FcDoubleCeil (vl
.u
.d
);
898 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
904 v
.type
= FcTypeInteger
;
905 v
.u
.i
= FcDoubleRound (vl
.u
.d
);
914 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
920 v
.type
= FcTypeInteger
;
921 v
.u
.i
= FcDoubleTrunc (vl
.u
.d
);
937 FcConfigMatchValueList (FcPattern
*p
,
941 FcValueList
*ret
= 0;
948 if (e
->op
== FcOpComma
)
950 value
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
955 value
= FcConfigEvaluate (p
, e
);
959 for (v
= values
; v
; v
= v
->next
)
961 if (FcConfigCompareValue (v
->value
, t
->op
, value
))
968 if (t
->qual
== FcQualAll
)
975 FcValueDestroy (value
);
981 FcConfigValues (FcPattern
*p
, FcExpr
*e
, FcValueBinding binding
)
987 l
= (FcValueList
*) malloc (sizeof (FcValueList
));
990 FcMemAlloc (FC_MEM_VALLIST
, sizeof (FcValueList
));
991 if (e
->op
== FcOpComma
)
993 l
->value
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
994 l
->next
= FcConfigValues (p
, e
->u
.tree
.right
, binding
);
998 l
->value
= FcConfigEvaluate (p
, e
);
1001 l
->binding
= binding
;
1002 while (l
&& l
->value
.type
== FcTypeVoid
)
1004 FcValueList
*next
= l
->next
;
1006 FcMemFree (FC_MEM_VALLIST
, sizeof (FcValueList
));
1014 FcConfigAdd (FcValueList
**head
,
1015 FcValueList
*position
,
1019 FcValueList
**prev
, *last
, *v
;
1020 FcValueBinding sameBinding
;
1023 sameBinding
= position
->binding
;
1025 sameBinding
= FcValueBindingWeak
;
1026 for (v
= new; v
; v
= v
->next
)
1027 if (v
->binding
== FcValueBindingSame
)
1028 v
->binding
= sameBinding
;
1032 prev
= &position
->next
;
1034 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1041 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1043 if (*prev
== position
)
1050 if (FcDebug () & FC_DBG_EDIT
)
1053 printf ("position not on list\n");
1057 if (FcDebug () & FC_DBG_EDIT
)
1059 printf ("%s list before ", append
? "Append" : "Prepend");
1060 FcValueListPrint (*head
);
1074 if (FcDebug () & FC_DBG_EDIT
)
1076 printf ("%s list after ", append
? "Append" : "Prepend");
1077 FcValueListPrint (*head
);
1085 FcConfigDel (FcValueList
**head
,
1086 FcValueList
*position
)
1090 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1092 if (*prev
== position
)
1094 *prev
= position
->next
;
1096 FcValueListDestroy (position
);
1103 FcConfigPatternAdd (FcPattern
*p
,
1110 FcPatternElt
*e
= FcPatternInsertElt (p
, object
);
1114 FcConfigAdd (&e
->values
, 0, append
, list
);
1119 * Delete all values associated with a field
1122 FcConfigPatternDel (FcPattern
*p
,
1125 FcPatternElt
*e
= FcPatternFindElt (p
, object
);
1129 FcConfigDel (&e
->values
, e
->values
);
1133 FcConfigPatternCanon (FcPattern
*p
,
1136 FcPatternElt
*e
= FcPatternFindElt (p
, object
);
1140 FcPatternDel (p
, object
);
1144 FcConfigSubstituteWithPat (FcConfig
*config
,
1159 config
= FcConfigGetCurrent ();
1164 st
= (FcSubState
*) malloc (config
->maxObjects
* sizeof (FcSubState
));
1165 if (!st
&& config
->maxObjects
)
1167 FcMemAlloc (FC_MEM_SUBSTATE
, config
->maxObjects
* sizeof (FcSubState
));
1169 if (FcDebug () & FC_DBG_EDIT
)
1171 printf ("FcConfigSubstitute ");
1174 if (kind
== FcMatchPattern
)
1175 s
= config
->substPattern
;
1177 s
= config
->substFont
;
1178 for (; s
; s
= s
->next
)
1181 * Check the tests to see if
1182 * they all match the pattern
1184 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1186 if (FcDebug () & FC_DBG_EDIT
)
1188 printf ("FcConfigSubstitute test ");
1192 if (kind
== FcMatchFont
&& t
->kind
== FcMatchPattern
)
1197 st
[i
].elt
= FcPatternFindElt (m
, t
->field
);
1201 * If there's no such field in the font,
1202 * then FcQualAll matches while FcQualAny does not
1206 if (t
->qual
== FcQualAll
)
1215 * Check to see if there is a match, mark the location
1216 * to apply match-relative edits
1218 st
[i
].value
= FcConfigMatchValueList (m
, t
, st
[i
].elt
->values
);
1221 if (t
->qual
== FcQualFirst
&& st
[i
].value
!= st
[i
].elt
->values
)
1223 if (t
->qual
== FcQualNotFirst
&& st
[i
].value
== st
[i
].elt
->values
)
1228 if (FcDebug () & FC_DBG_EDIT
)
1229 printf ("No match\n");
1232 if (FcDebug () & FC_DBG_EDIT
)
1234 printf ("Substitute ");
1237 for (e
= s
->edit
; e
; e
= e
->next
)
1240 * Evaluate the list of expressions
1242 l
= FcConfigValues (p
, e
->expr
, e
->binding
);
1244 * Locate any test associated with this field, skipping
1245 * tests associated with the pattern when substituting in
1248 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1250 if ((t
->kind
== FcMatchFont
|| kind
== FcMatchPattern
) &&
1251 !FcStrCmpIgnoreCase ((FcChar8
*) t
->field
,
1252 (FcChar8
*) e
->field
))
1255 * KLUDGE - the pattern may have been reallocated or
1256 * things may have been inserted or deleted above
1257 * this element by other edits. Go back and find
1260 if (e
!= s
->edit
&& st
[i
].elt
)
1261 st
[i
].elt
= FcPatternFindElt (p
, t
->field
);
1270 * If there was a test, then replace the matched
1271 * value with the new list of values
1275 FcValueList
*thisValue
= st
[i
].value
;
1276 FcValueList
*nextValue
= thisValue
? thisValue
->next
: 0;
1279 * Append the new list of values after the current value
1281 FcConfigAdd (&st
[i
].elt
->values
, thisValue
, FcTrue
, l
);
1283 * Delete the marked value
1285 FcConfigDel (&st
[i
].elt
->values
, thisValue
);
1287 * Adjust any pointers into the value list to ensure
1288 * future edits occur at the same place
1290 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1292 if (st
[i
].value
== thisValue
)
1293 st
[i
].value
= nextValue
;
1297 /* fall through ... */
1298 case FcOpAssignReplace
:
1300 * Delete all of the values and insert
1303 FcConfigPatternDel (p
, e
->field
);
1304 FcConfigPatternAdd (p
, e
->field
, l
, FcTrue
);
1306 * Adjust any pointers into the value list as they no
1307 * longer point to anything valid
1311 FcPatternElt
*thisElt
= st
[i
].elt
;
1312 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1314 if (st
[i
].elt
== thisElt
)
1322 FcConfigAdd (&st
[i
].elt
->values
, st
[i
].value
, FcFalse
, l
);
1325 /* fall through ... */
1326 case FcOpPrependFirst
:
1327 FcConfigPatternAdd (p
, e
->field
, l
, FcFalse
);
1332 FcConfigAdd (&st
[i
].elt
->values
, st
[i
].value
, FcTrue
, l
);
1335 /* fall through ... */
1336 case FcOpAppendLast
:
1337 FcConfigPatternAdd (p
, e
->field
, l
, FcTrue
);
1344 * Now go through the pattern and eliminate
1345 * any properties without data
1347 for (e
= s
->edit
; e
; e
= e
->next
)
1348 FcConfigPatternCanon (p
, e
->field
);
1350 if (FcDebug () & FC_DBG_EDIT
)
1352 printf ("FcConfigSubstitute edit");
1356 FcMemFree (FC_MEM_SUBSTATE
, config
->maxObjects
* sizeof (FcSubState
));
1358 if (FcDebug () & FC_DBG_EDIT
)
1360 printf ("FcConfigSubstitute done");
1367 FcConfigSubstitute (FcConfig
*config
,
1371 return FcConfigSubstituteWithPat (config
, p
, 0, kind
);
1374 #if defined (_WIN32) && defined (PIC)
1376 static FcChar8 fontconfig_path
[1000] = "";
1379 DllMain (HINSTANCE hinstDLL
,
1385 switch (fdwReason
) {
1386 case DLL_PROCESS_ATTACH
:
1387 if (!GetModuleFileName ((HMODULE
) hinstDLL
, fontconfig_path
,
1388 sizeof (fontconfig_path
)))
1391 /* If the fontconfig DLL is in a "bin" or "lib" subfolder,
1392 * assume it's a Unix-style installation tree, and use
1393 * "etc/fonts" in there as FONTCONFIG_PATH. Otherwise use the
1394 * folder where the DLL is as FONTCONFIG_PATH.
1396 p
= strrchr (fontconfig_path
, '\\');
1400 p
= strrchr (fontconfig_path
, '\\');
1401 if (p
&& (FcStrCmpIgnoreCase (p
+ 1, "bin") == 0 ||
1402 FcStrCmpIgnoreCase (p
+ 1, "lib") == 0))
1404 strcat (fontconfig_path
, "\\etc\\fonts");
1407 fontconfig_path
[0] = '\0';
1415 #undef FONTCONFIG_PATH
1416 #define FONTCONFIG_PATH fontconfig_path
1418 #else /* !(_WIN32 && PIC) */
1420 #endif /* !(_WIN32 && PIC) */
1422 #ifndef FONTCONFIG_FILE
1423 #define FONTCONFIG_FILE "fonts.conf"
1427 FcConfigFileExists (const FcChar8
*dir
, const FcChar8
*file
)
1432 dir
= (FcChar8
*) "";
1433 path
= malloc (strlen ((char *) dir
) + 1 + strlen ((char *) file
) + 1);
1437 strcpy ((char *) path
, (const char *) dir
);
1438 /* make sure there's a single separator */
1440 if ((!path
[0] || (path
[strlen((char *) path
)-1] != '/' &&
1441 path
[strlen((char *) path
)-1] != '\\')) &&
1442 (file
[0] != '/' && file
[0] != '\\'))
1443 strcat ((char *) path
, "\\");
1445 if ((!path
[0] || path
[strlen((char *) path
)-1] != '/') && file
[0] != '/')
1446 strcat ((char *) path
, "/");
1448 strcat ((char *) path
, (char *) file
);
1450 FcMemAlloc (FC_MEM_STRING
, strlen ((char *) path
) + 1);
1451 if (access ((char *) path
, R_OK
) == 0)
1459 FcConfigGetPath (void)
1462 FcChar8
*env
, *e
, *colon
;
1467 npath
= 2; /* default dir + null */
1468 env
= (FcChar8
*) getenv ("FONTCONFIG_PATH");
1474 if (*e
++ == FC_SEARCH_PATH_SEPARATOR
)
1477 path
= calloc (npath
, sizeof (FcChar8
*));
1487 colon
= (FcChar8
*) strchr ((char *) e
, FC_SEARCH_PATH_SEPARATOR
);
1489 colon
= e
+ strlen ((char *) e
);
1490 path
[i
] = malloc (colon
- e
+ 1);
1493 strncpy ((char *) path
[i
], (const char *) e
, colon
- e
);
1494 path
[i
][colon
- e
] = '\0';
1503 dir
= (FcChar8
*) FONTCONFIG_PATH
;
1504 path
[i
] = malloc (strlen ((char *) dir
) + 1);
1507 strcpy ((char *) path
[i
], (const char *) dir
);
1511 for (i
= 0; path
[i
]; i
++)
1519 FcConfigFreePath (FcChar8
**path
)
1523 for (p
= path
; *p
; p
++)
1528 static FcBool _FcConfigHomeEnabled
= FcTrue
;
1533 if (_FcConfigHomeEnabled
)
1535 char *home
= getenv ("HOME");
1539 home
= getenv ("USERPROFILE");
1548 FcConfigEnableHome (FcBool enable
)
1550 FcBool prev
= _FcConfigHomeEnabled
;
1551 _FcConfigHomeEnabled
= enable
;
1556 FcConfigFilename (const FcChar8
*url
)
1558 FcChar8
*file
, *dir
, **path
, **p
;
1562 url
= (FcChar8
*) getenv ("FONTCONFIG_FILE");
1564 url
= (FcChar8
*) FONTCONFIG_FILE
;
1569 if (isalpha (*url
) &&
1571 (url
[2] == '/' || url
[2] == '\\'))
1577 dir
= FcConfigHome ();
1579 file
= FcConfigFileExists (dir
, url
+ 1);
1588 file
= FcConfigFileExists (0, url
);
1591 path
= FcConfigGetPath ();
1594 for (p
= path
; *p
; p
++)
1596 file
= FcConfigFileExists (*p
, url
);
1600 FcConfigFreePath (path
);
1607 * Manage the application-specific fonts
1611 FcConfigAppFontAddFile (FcConfig
*config
,
1612 const FcChar8
*file
)
1621 config
= FcConfigGetCurrent ();
1626 subdirs
= FcStrSetCreate ();
1630 set
= FcConfigGetFonts (config
, FcSetApplication
);
1633 set
= FcFontSetCreate ();
1636 FcStrSetDestroy (subdirs
);
1639 FcConfigSetFonts (config
, set
, FcSetApplication
);
1642 if (!FcFileScanConfig (set
, subdirs
, 0, config
->blanks
, file
, FcFalse
, config
))
1644 FcStrSetDestroy (subdirs
);
1647 if ((sublist
= FcStrListCreate (subdirs
)))
1649 while ((subdir
= FcStrListNext (sublist
)))
1651 FcConfigAppFontAddDir (config
, subdir
);
1653 FcStrListDone (sublist
);
1659 FcConfigAppFontAddDir (FcConfig
*config
,
1669 config
= FcConfigGetCurrent ();
1673 subdirs
= FcStrSetCreate ();
1677 set
= FcConfigGetFonts (config
, FcSetApplication
);
1680 set
= FcFontSetCreate ();
1683 FcStrSetDestroy (subdirs
);
1686 FcConfigSetFonts (config
, set
, FcSetApplication
);
1689 if (!FcDirScanConfig (set
, subdirs
, 0, config
->blanks
, dir
, FcFalse
, config
))
1691 FcStrSetDestroy (subdirs
);
1694 if ((sublist
= FcStrListCreate (subdirs
)))
1696 while ((subdir
= FcStrListNext (sublist
)))
1698 FcConfigAppFontAddDir (config
, subdir
);
1700 FcStrListDone (sublist
);
1706 FcConfigAppFontClear (FcConfig
*config
)
1708 FcConfigSetFonts (config
, 0, FcSetApplication
);
1712 * Manage filename-based font source selectors
1716 FcConfigGlobAdd (FcConfig
*config
,
1717 const FcChar8
*glob
,
1720 FcStrSet
*set
= accept
? config
->acceptGlobs
: config
->rejectGlobs
;
1722 return FcStrSetAdd (set
, glob
);
1726 FcConfigGlobMatch (const FcChar8
*glob
,
1727 const FcChar8
*string
)
1731 while ((c
= *glob
++))
1735 /* short circuit common case */
1738 /* short circuit another common case */
1739 if (strchr ((char *) glob
, '*') == 0)
1740 string
+= strlen ((char *) string
) - strlen ((char *) glob
);
1743 if (FcConfigGlobMatch (glob
, string
))
1749 if (*string
++ == '\0')
1758 return *string
== '\0';
1762 FcConfigGlobsMatch (const FcStrSet
*globs
,
1763 const FcChar8
*string
)
1767 for (i
= 0; i
< globs
->num
; i
++)
1768 if (FcConfigGlobMatch (globs
->strs
[i
], string
))
1774 FcConfigAcceptFilename (FcConfig
*config
,
1775 const FcChar8
*filename
)
1777 if (FcConfigGlobsMatch (config
->acceptGlobs
, filename
))
1779 if (FcConfigGlobsMatch (config
->rejectGlobs
, filename
))