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
;
569 ret
= FcStrCmpIgnoreCase (m
.u
.s
, v
.u
.s
) == 0;
572 case FcOpNotContains
:
573 ret
= FcStrCmpIgnoreCase (m
.u
.s
, v
.u
.s
) != 0;
583 ret
= FcMatrixEqual (m
.u
.m
, v
.u
.m
);
586 case FcOpNotContains
:
587 ret
= !FcMatrixEqual (m
.u
.m
, v
.u
.m
);
596 /* v contains m if m is a subset of v */
597 ret
= FcCharSetIsSubset (m
.u
.c
, v
.u
.c
);
599 case FcOpNotContains
:
600 /* v contains m if m is a subset of v */
601 ret
= !FcCharSetIsSubset (m
.u
.c
, v
.u
.c
);
604 ret
= FcCharSetEqual (m
.u
.c
, v
.u
.c
);
607 ret
= !FcCharSetEqual (m
.u
.c
, v
.u
.c
);
616 ret
= FcLangSetContains (v
.u
.l
, m
.u
.l
);
618 case FcOpNotContains
:
619 ret
= FcLangSetContains (v
.u
.l
, m
.u
.l
);
622 ret
= FcLangSetEqual (v
.u
.l
, m
.u
.l
);
625 ret
= !FcLangSetEqual (v
.u
.l
, m
.u
.l
);
645 ret
= m
.u
.f
== v
.u
.f
;
648 case FcOpNotContains
:
649 ret
= m
.u
.f
!= v
.u
.f
;
659 if (op
== FcOpNotEqual
|| op
== FcOpNotContains
)
666 #define _FcDoubleFloor(d) ((int) (d))
667 #define _FcDoubleCeil(d) ((double) (int) (d) == (d) ? (int) (d) : (int) ((d) + 1))
668 #define FcDoubleFloor(d) ((d) >= 0 ? _FcDoubleFloor(d) : -_FcDoubleCeil(-(d)))
669 #define FcDoubleCeil(d) ((d) >= 0 ? _FcDoubleCeil(d) : -_FcDoubleFloor(-(d)))
670 #define FcDoubleRound(d) FcDoubleFloor ((d) + 0.5)
671 #define FcDoubleTrunc(d) ((d) >= 0 ? _FcDoubleFloor (d) : -_FcDoubleFloor (-(d)))
674 FcConfigEvaluate (FcPattern
*p
, FcExpr
*e
)
682 v
.type
= FcTypeInteger
;
686 v
.type
= FcTypeDouble
;
690 v
.type
= FcTypeString
;
695 v
.type
= FcTypeMatrix
;
700 v
.type
= FcTypeCharSet
;
709 r
= FcPatternGet (p
, e
->u
.field
, 0, &v
);
710 if (r
!= FcResultMatch
)
714 if (FcNameConstant (e
->u
.constant
, &v
.u
.i
))
715 v
.type
= FcTypeInteger
;
720 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
721 if (vl
.type
== FcTypeBool
)
724 v
= FcConfigEvaluate (p
, e
->u
.tree
.right
->u
.tree
.left
);
726 v
= FcConfigEvaluate (p
, e
->u
.tree
.right
->u
.tree
.right
);
739 case FcOpNotContains
:
740 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
741 vr
= FcConfigEvaluate (p
, e
->u
.tree
.right
);
743 v
.u
.b
= FcConfigCompareValue (vl
, e
->op
, vr
);
753 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
754 vr
= FcConfigEvaluate (p
, e
->u
.tree
.right
);
755 vl
= FcConfigPromote (vl
, vr
);
756 vr
= FcConfigPromote (vr
, vl
);
757 if (vl
.type
== vr
.type
)
763 v
.type
= FcTypeDouble
;
764 v
.u
.d
= vl
.u
.d
+ vr
.u
.d
;
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
;
782 if (v
.type
== FcTypeDouble
&&
783 v
.u
.d
== (double) (int) v
.u
.d
)
785 v
.type
= FcTypeInteger
;
793 v
.u
.b
= vl
.u
.b
|| vr
.u
.b
;
797 v
.u
.b
= vl
.u
.b
&& vr
.u
.b
;
807 v
.type
= FcTypeString
;
808 v
.u
.s
= FcStrPlus (vl
.u
.s
, vr
.u
.s
);
820 v
.type
= FcTypeMatrix
;
821 m
= malloc (sizeof (FcMatrix
));
824 FcMemAlloc (FC_MEM_MATRIX
, sizeof (FcMatrix
));
825 FcMatrixMultiply (m
, vl
.u
.m
, vr
.u
.m
);
849 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
862 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
868 v
.type
= FcTypeInteger
;
869 v
.u
.i
= FcDoubleFloor (vl
.u
.d
);
878 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
884 v
.type
= FcTypeInteger
;
885 v
.u
.i
= FcDoubleCeil (vl
.u
.d
);
894 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
900 v
.type
= FcTypeInteger
;
901 v
.u
.i
= FcDoubleRound (vl
.u
.d
);
910 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
916 v
.type
= FcTypeInteger
;
917 v
.u
.i
= FcDoubleTrunc (vl
.u
.d
);
933 FcConfigMatchValueList (FcPattern
*p
,
937 FcValueList
*ret
= 0;
944 if (e
->op
== FcOpComma
)
946 value
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
951 value
= FcConfigEvaluate (p
, e
);
955 for (v
= values
; v
; v
= v
->next
)
957 if (FcConfigCompareValue (v
->value
, t
->op
, value
))
964 if (t
->qual
== FcQualAll
)
971 FcValueDestroy (value
);
977 FcConfigValues (FcPattern
*p
, FcExpr
*e
, FcValueBinding binding
)
983 l
= (FcValueList
*) malloc (sizeof (FcValueList
));
986 FcMemAlloc (FC_MEM_VALLIST
, sizeof (FcValueList
));
987 if (e
->op
== FcOpComma
)
989 l
->value
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
990 l
->next
= FcConfigValues (p
, e
->u
.tree
.right
, binding
);
994 l
->value
= FcConfigEvaluate (p
, e
);
997 l
->binding
= binding
;
998 while (l
&& l
->value
.type
== FcTypeVoid
)
1000 FcValueList
*next
= l
->next
;
1002 FcMemFree (FC_MEM_VALLIST
, sizeof (FcValueList
));
1010 FcConfigAdd (FcValueList
**head
,
1011 FcValueList
*position
,
1015 FcValueList
**prev
, *last
, *v
;
1016 FcValueBinding sameBinding
;
1019 sameBinding
= position
->binding
;
1021 sameBinding
= FcValueBindingWeak
;
1022 for (v
= new; v
; v
= v
->next
)
1023 if (v
->binding
== FcValueBindingSame
)
1024 v
->binding
= sameBinding
;
1028 prev
= &position
->next
;
1030 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1037 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1039 if (*prev
== position
)
1046 if (FcDebug () & FC_DBG_EDIT
)
1049 printf ("position not on list\n");
1053 if (FcDebug () & FC_DBG_EDIT
)
1055 printf ("%s list before ", append
? "Append" : "Prepend");
1056 FcValueListPrint (*head
);
1070 if (FcDebug () & FC_DBG_EDIT
)
1072 printf ("%s list after ", append
? "Append" : "Prepend");
1073 FcValueListPrint (*head
);
1081 FcConfigDel (FcValueList
**head
,
1082 FcValueList
*position
)
1086 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1088 if (*prev
== position
)
1090 *prev
= position
->next
;
1092 FcValueListDestroy (position
);
1099 FcConfigPatternAdd (FcPattern
*p
,
1106 FcPatternElt
*e
= FcPatternInsertElt (p
, object
);
1110 FcConfigAdd (&e
->values
, 0, append
, list
);
1115 * Delete all values associated with a field
1118 FcConfigPatternDel (FcPattern
*p
,
1121 FcPatternElt
*e
= FcPatternFindElt (p
, object
);
1125 FcConfigDel (&e
->values
, e
->values
);
1129 FcConfigPatternCanon (FcPattern
*p
,
1132 FcPatternElt
*e
= FcPatternFindElt (p
, object
);
1136 FcPatternDel (p
, object
);
1140 FcConfigSubstituteWithPat (FcConfig
*config
,
1155 config
= FcConfigGetCurrent ();
1160 st
= (FcSubState
*) malloc (config
->maxObjects
* sizeof (FcSubState
));
1161 if (!st
&& config
->maxObjects
)
1163 FcMemAlloc (FC_MEM_SUBSTATE
, config
->maxObjects
* sizeof (FcSubState
));
1165 if (FcDebug () & FC_DBG_EDIT
)
1167 printf ("FcConfigSubstitute ");
1170 if (kind
== FcMatchPattern
)
1171 s
= config
->substPattern
;
1173 s
= config
->substFont
;
1174 for (; s
; s
= s
->next
)
1177 * Check the tests to see if
1178 * they all match the pattern
1180 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1182 if (FcDebug () & FC_DBG_EDIT
)
1184 printf ("FcConfigSubstitute test ");
1188 if (kind
== FcMatchFont
&& t
->kind
== FcMatchPattern
)
1193 st
[i
].elt
= FcPatternFindElt (m
, t
->field
);
1197 * If there's no such field in the font,
1198 * then FcQualAll matches while FcQualAny does not
1202 if (t
->qual
== FcQualAll
)
1211 * Check to see if there is a match, mark the location
1212 * to apply match-relative edits
1214 st
[i
].value
= FcConfigMatchValueList (m
, t
, st
[i
].elt
->values
);
1217 if (t
->qual
== FcQualFirst
&& st
[i
].value
!= st
[i
].elt
->values
)
1219 if (t
->qual
== FcQualNotFirst
&& st
[i
].value
== st
[i
].elt
->values
)
1224 if (FcDebug () & FC_DBG_EDIT
)
1225 printf ("No match\n");
1228 if (FcDebug () & FC_DBG_EDIT
)
1230 printf ("Substitute ");
1233 for (e
= s
->edit
; e
; e
= e
->next
)
1236 * Evaluate the list of expressions
1238 l
= FcConfigValues (p
, e
->expr
, e
->binding
);
1240 * Locate any test associated with this field, skipping
1241 * tests associated with the pattern when substituting in
1244 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1246 if ((t
->kind
== FcMatchFont
|| kind
== FcMatchPattern
) &&
1247 !FcStrCmpIgnoreCase ((FcChar8
*) t
->field
,
1248 (FcChar8
*) e
->field
))
1251 * KLUDGE - the pattern may have been reallocated or
1252 * things may have been inserted or deleted above
1253 * this element by other edits. Go back and find
1256 if (e
!= s
->edit
&& st
[i
].elt
)
1257 st
[i
].elt
= FcPatternFindElt (p
, t
->field
);
1266 * If there was a test, then replace the matched
1267 * value with the new list of values
1271 FcValueList
*thisValue
= st
[i
].value
;
1272 FcValueList
*nextValue
= thisValue
? thisValue
->next
: 0;
1275 * Append the new list of values after the current value
1277 FcConfigAdd (&st
[i
].elt
->values
, thisValue
, FcTrue
, l
);
1279 * Delete the marked value
1281 FcConfigDel (&st
[i
].elt
->values
, thisValue
);
1283 * Adjust any pointers into the value list to ensure
1284 * future edits occur at the same place
1286 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1288 if (st
[i
].value
== thisValue
)
1289 st
[i
].value
= nextValue
;
1293 /* fall through ... */
1294 case FcOpAssignReplace
:
1296 * Delete all of the values and insert
1299 FcConfigPatternDel (p
, e
->field
);
1300 FcConfigPatternAdd (p
, e
->field
, l
, FcTrue
);
1302 * Adjust any pointers into the value list as they no
1303 * longer point to anything valid
1307 FcPatternElt
*thisElt
= st
[i
].elt
;
1308 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1310 if (st
[i
].elt
== thisElt
)
1318 FcConfigAdd (&st
[i
].elt
->values
, st
[i
].value
, FcFalse
, l
);
1321 /* fall through ... */
1322 case FcOpPrependFirst
:
1323 FcConfigPatternAdd (p
, e
->field
, l
, FcFalse
);
1328 FcConfigAdd (&st
[i
].elt
->values
, st
[i
].value
, FcTrue
, l
);
1331 /* fall through ... */
1332 case FcOpAppendLast
:
1333 FcConfigPatternAdd (p
, e
->field
, l
, FcTrue
);
1340 * Now go through the pattern and eliminate
1341 * any properties without data
1343 for (e
= s
->edit
; e
; e
= e
->next
)
1344 FcConfigPatternCanon (p
, e
->field
);
1346 if (FcDebug () & FC_DBG_EDIT
)
1348 printf ("FcConfigSubstitute edit");
1352 FcMemFree (FC_MEM_SUBSTATE
, config
->maxObjects
* sizeof (FcSubState
));
1354 if (FcDebug () & FC_DBG_EDIT
)
1356 printf ("FcConfigSubstitute done");
1363 FcConfigSubstitute (FcConfig
*config
,
1367 return FcConfigSubstituteWithPat (config
, p
, 0, kind
);
1370 #if defined (_WIN32) && defined (PIC)
1372 static FcChar8 fontconfig_path
[1000] = "";
1375 DllMain (HINSTANCE hinstDLL
,
1381 switch (fdwReason
) {
1382 case DLL_PROCESS_ATTACH
:
1383 if (!GetModuleFileName ((HMODULE
) hinstDLL
, fontconfig_path
,
1384 sizeof (fontconfig_path
)))
1387 /* If the fontconfig DLL is in a "bin" or "lib" subfolder,
1388 * assume it's a Unix-style installation tree, and use
1389 * "etc/fonts" in there as FONTCONFIG_PATH. Otherwise use the
1390 * folder where the DLL is as FONTCONFIG_PATH.
1392 p
= strrchr (fontconfig_path
, '\\');
1396 p
= strrchr (fontconfig_path
, '\\');
1397 if (p
&& (FcStrCmpIgnoreCase (p
+ 1, "bin") == 0 ||
1398 FcStrCmpIgnoreCase (p
+ 1, "lib") == 0))
1400 strcat (fontconfig_path
, "\\etc\\fonts");
1403 fontconfig_path
[0] = '\0';
1411 #undef FONTCONFIG_PATH
1412 #define FONTCONFIG_PATH fontconfig_path
1414 #else /* !(_WIN32 && PIC) */
1416 #endif /* !(_WIN32 && PIC) */
1418 #ifndef FONTCONFIG_FILE
1419 #define FONTCONFIG_FILE "fonts.conf"
1423 FcConfigFileExists (const FcChar8
*dir
, const FcChar8
*file
)
1428 dir
= (FcChar8
*) "";
1429 path
= malloc (strlen ((char *) dir
) + 1 + strlen ((char *) file
) + 1);
1433 strcpy ((char *) path
, (const char *) dir
);
1434 /* make sure there's a single separator */
1436 if ((!path
[0] || (path
[strlen((char *) path
)-1] != '/' &&
1437 path
[strlen((char *) path
)-1] != '\\')) &&
1438 (file
[0] != '/' && file
[0] != '\\'))
1439 strcat ((char *) path
, "\\");
1441 if ((!path
[0] || path
[strlen((char *) path
)-1] != '/') && file
[0] != '/')
1442 strcat ((char *) path
, "/");
1444 strcat ((char *) path
, (char *) file
);
1446 FcMemAlloc (FC_MEM_STRING
, strlen ((char *) path
) + 1);
1447 if (access ((char *) path
, R_OK
) == 0)
1455 FcConfigGetPath (void)
1458 FcChar8
*env
, *e
, *colon
;
1463 npath
= 2; /* default dir + null */
1464 env
= (FcChar8
*) getenv ("FONTCONFIG_PATH");
1470 if (*e
++ == FC_SEARCH_PATH_SEPARATOR
)
1473 path
= calloc (npath
, sizeof (FcChar8
*));
1483 colon
= (FcChar8
*) strchr ((char *) e
, FC_SEARCH_PATH_SEPARATOR
);
1485 colon
= e
+ strlen ((char *) e
);
1486 path
[i
] = malloc (colon
- e
+ 1);
1489 strncpy ((char *) path
[i
], (const char *) e
, colon
- e
);
1490 path
[i
][colon
- e
] = '\0';
1499 dir
= (FcChar8
*) FONTCONFIG_PATH
;
1500 path
[i
] = malloc (strlen ((char *) dir
) + 1);
1503 strcpy ((char *) path
[i
], (const char *) dir
);
1507 for (i
= 0; path
[i
]; i
++)
1515 FcConfigFreePath (FcChar8
**path
)
1519 for (p
= path
; *p
; p
++)
1524 static FcBool _FcConfigHomeEnabled
= FcTrue
;
1529 if (_FcConfigHomeEnabled
)
1531 char *home
= getenv ("HOME");
1535 home
= getenv ("USERPROFILE");
1544 FcConfigEnableHome (FcBool enable
)
1546 FcBool prev
= _FcConfigHomeEnabled
;
1547 _FcConfigHomeEnabled
= enable
;
1552 FcConfigFilename (const FcChar8
*url
)
1554 FcChar8
*file
, *dir
, **path
, **p
;
1558 url
= (FcChar8
*) getenv ("FONTCONFIG_FILE");
1560 url
= (FcChar8
*) FONTCONFIG_FILE
;
1565 if (isalpha (*url
) &&
1567 (url
[2] == '/' || url
[2] == '\\'))
1573 dir
= FcConfigHome ();
1575 file
= FcConfigFileExists (dir
, url
+ 1);
1584 file
= FcConfigFileExists (0, url
);
1587 path
= FcConfigGetPath ();
1590 for (p
= path
; *p
; p
++)
1592 file
= FcConfigFileExists (*p
, url
);
1596 FcConfigFreePath (path
);
1603 * Manage the application-specific fonts
1607 FcConfigAppFontAddFile (FcConfig
*config
,
1608 const FcChar8
*file
)
1617 config
= FcConfigGetCurrent ();
1622 subdirs
= FcStrSetCreate ();
1626 set
= FcConfigGetFonts (config
, FcSetApplication
);
1629 set
= FcFontSetCreate ();
1632 FcStrSetDestroy (subdirs
);
1635 FcConfigSetFonts (config
, set
, FcSetApplication
);
1638 if (!FcFileScanConfig (set
, subdirs
, 0, config
->blanks
, file
, FcFalse
, config
))
1640 FcStrSetDestroy (subdirs
);
1643 if ((sublist
= FcStrListCreate (subdirs
)))
1645 while ((subdir
= FcStrListNext (sublist
)))
1647 FcConfigAppFontAddDir (config
, subdir
);
1649 FcStrListDone (sublist
);
1655 FcConfigAppFontAddDir (FcConfig
*config
,
1665 config
= FcConfigGetCurrent ();
1669 subdirs
= FcStrSetCreate ();
1673 set
= FcConfigGetFonts (config
, FcSetApplication
);
1676 set
= FcFontSetCreate ();
1679 FcStrSetDestroy (subdirs
);
1682 FcConfigSetFonts (config
, set
, FcSetApplication
);
1685 if (!FcDirScanConfig (set
, subdirs
, 0, config
->blanks
, dir
, FcFalse
, config
))
1687 FcStrSetDestroy (subdirs
);
1690 if ((sublist
= FcStrListCreate (subdirs
)))
1692 while ((subdir
= FcStrListNext (sublist
)))
1694 FcConfigAppFontAddDir (config
, subdir
);
1696 FcStrListDone (sublist
);
1702 FcConfigAppFontClear (FcConfig
*config
)
1704 FcConfigSetFonts (config
, 0, FcSetApplication
);
1708 * Manage filename-based font source selectors
1712 FcConfigGlobAdd (FcConfig
*config
,
1713 const FcChar8
*glob
,
1716 FcStrSet
*set
= accept
? config
->acceptGlobs
: config
->rejectGlobs
;
1718 return FcStrSetAdd (set
, glob
);
1722 FcConfigGlobMatch (const FcChar8
*glob
,
1723 const FcChar8
*string
)
1727 while ((c
= *glob
++))
1731 /* short circuit common case */
1734 /* short circuit another common case */
1735 if (strchr ((char *) glob
, '*') == 0)
1736 string
+= strlen ((char *) string
) - strlen ((char *) glob
);
1739 if (FcConfigGlobMatch (glob
, string
))
1745 if (*string
++ == '\0')
1754 return *string
== '\0';
1758 FcConfigGlobsMatch (const FcStrSet
*globs
,
1759 const FcChar8
*string
)
1763 for (i
= 0; i
< globs
->num
; i
++)
1764 if (FcConfigGlobMatch (globs
->strs
[i
], string
))
1770 FcConfigAcceptFilename (FcConfig
*config
,
1771 const FcChar8
*filename
)
1773 if (FcConfigGlobsMatch (config
->acceptGlobs
, filename
))
1775 if (FcConfigGlobsMatch (config
->rejectGlobs
, filename
))