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)
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
);
181 FcStrFree (config
->cache
);
183 FcSubstDestroy (config
->substPattern
);
184 FcSubstDestroy (config
->substFont
);
185 for (set
= FcSetSystem
; set
<= FcSetApplication
; set
++)
186 if (config
->fonts
[set
])
187 FcFontSetDestroy (config
->fonts
[set
]);
189 FcMemFree (FC_MEM_CONFIG
, sizeof (FcConfig
));
193 * Scan the current list of directories in the configuration
194 * and build the set of available fonts. Update the
195 * per-user cache file to reflect the new configuration
199 FcConfigBuildFonts (FcConfig
*config
)
202 FcGlobalCache
*cache
;
206 fonts
= FcFontSetCreate ();
210 cache
= FcGlobalCacheCreate ();
214 FcGlobalCacheLoad (cache
, config
->cache
);
216 list
= FcConfigGetFontDirs (config
);
220 while ((dir
= FcStrListNext (list
)))
222 if (FcDebug () & FC_DBG_FONTSET
)
223 printf ("scan dir %s\n", dir
);
224 FcDirScanConfig (fonts
, config
->fontDirs
, cache
,
225 config
->blanks
, dir
, FcFalse
, config
);
228 FcStrListDone (list
);
230 if (FcDebug () & FC_DBG_FONTSET
)
231 FcFontSetPrint (fonts
);
233 FcGlobalCacheSave (cache
, config
->cache
);
234 FcGlobalCacheDestroy (cache
);
236 FcConfigSetFonts (config
, fonts
, FcSetSystem
);
240 FcFontSetDestroy (fonts
);
246 FcConfigSetCurrent (FcConfig
*config
)
249 if (!FcConfigBuildFonts (config
))
253 FcConfigDestroy (_fcConfig
);
259 FcConfigGetCurrent (void)
268 FcConfigAddConfigDir (FcConfig
*config
,
271 return FcStrSetAddFilename (config
->configDirs
, d
);
275 FcConfigGetConfigDirs (FcConfig
*config
)
279 config
= FcConfigGetCurrent ();
283 return FcStrListCreate (config
->configDirs
);
287 FcConfigAddFontDir (FcConfig
*config
,
290 return FcStrSetAddFilename (config
->fontDirs
, d
);
294 FcConfigAddDir (FcConfig
*config
,
297 return (FcConfigAddConfigDir (config
, d
) &&
298 FcConfigAddFontDir (config
, d
));
302 FcConfigGetFontDirs (FcConfig
*config
)
306 config
= FcConfigGetCurrent ();
310 return FcStrListCreate (config
->fontDirs
);
314 FcConfigAddConfigFile (FcConfig
*config
,
318 FcChar8
*file
= FcConfigFilename (f
);
323 ret
= FcStrSetAdd (config
->configFiles
, file
);
329 FcConfigGetConfigFiles (FcConfig
*config
)
333 config
= FcConfigGetCurrent ();
337 return FcStrListCreate (config
->configFiles
);
341 FcConfigSetCache (FcConfig
*config
,
344 FcChar8
*new = FcStrCopyFilename (c
);
349 FcStrFree (config
->cache
);
355 FcConfigGetCache (FcConfig
*config
)
359 config
= FcConfigGetCurrent ();
363 return config
->cache
;
367 FcConfigGetFonts (FcConfig
*config
,
372 config
= FcConfigGetCurrent ();
376 return config
->fonts
[set
];
380 FcConfigSetFonts (FcConfig
*config
,
384 if (config
->fonts
[set
])
385 FcFontSetDestroy (config
->fonts
[set
]);
386 config
->fonts
[set
] = fonts
;
392 FcConfigGetBlanks (FcConfig
*config
)
396 config
= FcConfigGetCurrent ();
400 return config
->blanks
;
404 FcConfigAddBlank (FcConfig
*config
,
412 b
= FcBlanksCreate ();
416 if (!FcBlanksAdd (b
, blank
))
423 FcConfigGetRescanInverval (FcConfig
*config
)
427 config
= FcConfigGetCurrent ();
431 return config
->rescanInterval
;
435 FcConfigSetRescanInverval (FcConfig
*config
, int rescanInterval
)
439 config
= FcConfigGetCurrent ();
443 config
->rescanInterval
= rescanInterval
;
448 FcConfigAddEdit (FcConfig
*config
,
453 FcSubst
*subst
, **prev
;
457 subst
= (FcSubst
*) malloc (sizeof (FcSubst
));
460 FcMemAlloc (FC_MEM_SUBST
, sizeof (FcSubst
));
461 if (kind
== FcMatchPattern
)
462 prev
= &config
->substPattern
;
464 prev
= &config
->substFont
;
465 for (; *prev
; prev
= &(*prev
)->next
);
471 for (t
= test
; t
; t
= t
->next
)
473 if (t
->kind
== FcMatchDefault
)
477 if (config
->maxObjects
< num
)
478 config
->maxObjects
= num
;
479 if (FcDebug () & FC_DBG_EDIT
)
481 printf ("Add Subst ");
482 FcSubstPrint (subst
);
487 typedef struct _FcSubState
{
493 FcConfigPromote (FcValue v
, FcValue u
)
495 if (v
.type
== FcTypeInteger
)
497 v
.type
= FcTypeDouble
;
498 v
.u
.d
= (double) v
.u
.i
;
500 else if (v
.type
== FcTypeVoid
&& u
.type
== FcTypeMatrix
)
502 v
.u
.m
= &FcIdentityMatrix
;
503 v
.type
= FcTypeMatrix
;
505 else if (v
.type
== FcTypeString
&& u
.type
== FcTypeLangSet
)
507 v
.u
.l
= FcLangSetPromote (v
.u
.s
);
508 v
.type
= FcTypeLangSet
;
514 FcConfigCompareValue (const FcValue m_o
,
520 FcBool ret
= FcFalse
;
522 m
= FcConfigPromote (m
, v
);
523 v
= FcConfigPromote (v
, m
);
524 if (m
.type
== v
.type
)
528 break; /* FcConfigPromote prevents this from happening */
533 ret
= m
.u
.d
== v
.u
.d
;
536 case FcOpNotContains
:
537 ret
= m
.u
.d
!= v
.u
.d
;
543 ret
= m
.u
.d
<= v
.u
.d
;
549 ret
= m
.u
.d
>= v
.u
.d
;
559 ret
= m
.u
.b
== v
.u
.b
;
562 case FcOpNotContains
:
563 ret
= m
.u
.b
!= v
.u
.b
;
572 ret
= FcStrCmpIgnoreCase (m
.u
.s
, v
.u
.s
) == 0;
575 ret
= FcStrStrIgnoreCase (m
.u
.s
, v
.u
.s
) != 0;
578 ret
= FcStrCmpIgnoreCase (m
.u
.s
, v
.u
.s
) != 0;
580 case FcOpNotContains
:
581 ret
= FcStrStrIgnoreCase (m
.u
.s
, v
.u
.s
) == 0;
591 ret
= FcMatrixEqual (m
.u
.m
, v
.u
.m
);
594 case FcOpNotContains
:
595 ret
= !FcMatrixEqual (m
.u
.m
, v
.u
.m
);
604 /* v contains m if m is a subset of v */
605 ret
= FcCharSetIsSubset (m
.u
.c
, v
.u
.c
);
607 case FcOpNotContains
:
608 /* v contains m if m is a subset of v */
609 ret
= !FcCharSetIsSubset (m
.u
.c
, v
.u
.c
);
612 ret
= FcCharSetEqual (m
.u
.c
, v
.u
.c
);
615 ret
= !FcCharSetEqual (m
.u
.c
, v
.u
.c
);
624 ret
= FcLangSetContains (m
.u
.l
, v
.u
.l
);
626 case FcOpNotContains
:
627 ret
= FcLangSetContains (m
.u
.l
, v
.u
.l
);
630 ret
= FcLangSetEqual (m
.u
.l
, v
.u
.l
);
633 ret
= !FcLangSetEqual (m
.u
.l
, v
.u
.l
);
653 ret
= m
.u
.f
== v
.u
.f
;
656 case FcOpNotContains
:
657 ret
= m
.u
.f
!= v
.u
.f
;
667 if (op
== FcOpNotEqual
|| op
== FcOpNotContains
)
674 #define _FcDoubleFloor(d) ((int) (d))
675 #define _FcDoubleCeil(d) ((double) (int) (d) == (d) ? (int) (d) : (int) ((d) + 1))
676 #define FcDoubleFloor(d) ((d) >= 0 ? _FcDoubleFloor(d) : -_FcDoubleCeil(-(d)))
677 #define FcDoubleCeil(d) ((d) >= 0 ? _FcDoubleCeil(d) : -_FcDoubleFloor(-(d)))
678 #define FcDoubleRound(d) FcDoubleFloor ((d) + 0.5)
679 #define FcDoubleTrunc(d) ((d) >= 0 ? _FcDoubleFloor (d) : -_FcDoubleFloor (-(d)))
682 FcConfigEvaluate (FcPattern
*p
, FcExpr
*e
)
690 v
.type
= FcTypeInteger
;
694 v
.type
= FcTypeDouble
;
698 v
.type
= FcTypeString
;
703 v
.type
= FcTypeMatrix
;
708 v
.type
= FcTypeCharSet
;
717 r
= FcPatternGet (p
, e
->u
.field
, 0, &v
);
718 if (r
!= FcResultMatch
)
722 if (FcNameConstant (e
->u
.constant
, &v
.u
.i
))
723 v
.type
= FcTypeInteger
;
728 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
729 if (vl
.type
== FcTypeBool
)
732 v
= FcConfigEvaluate (p
, e
->u
.tree
.right
->u
.tree
.left
);
734 v
= FcConfigEvaluate (p
, e
->u
.tree
.right
->u
.tree
.right
);
747 case FcOpNotContains
:
748 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
749 vr
= FcConfigEvaluate (p
, e
->u
.tree
.right
);
751 v
.u
.b
= FcConfigCompareValue (vl
, e
->op
, vr
);
761 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
762 vr
= FcConfigEvaluate (p
, e
->u
.tree
.right
);
763 vl
= FcConfigPromote (vl
, vr
);
764 vr
= FcConfigPromote (vr
, vl
);
765 if (vl
.type
== vr
.type
)
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
;
783 v
.type
= FcTypeDouble
;
784 v
.u
.d
= vl
.u
.d
/ vr
.u
.d
;
790 if (v
.type
== FcTypeDouble
&&
791 v
.u
.d
== (double) (int) v
.u
.d
)
793 v
.type
= FcTypeInteger
;
801 v
.u
.b
= vl
.u
.b
|| vr
.u
.b
;
805 v
.u
.b
= vl
.u
.b
&& vr
.u
.b
;
815 v
.type
= FcTypeString
;
816 v
.u
.s
= FcStrPlus (vl
.u
.s
, vr
.u
.s
);
828 v
.type
= FcTypeMatrix
;
829 m
= malloc (sizeof (FcMatrix
));
832 FcMemAlloc (FC_MEM_MATRIX
, sizeof (FcMatrix
));
833 FcMatrixMultiply (m
, vl
.u
.m
, vr
.u
.m
);
857 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
870 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
876 v
.type
= FcTypeInteger
;
877 v
.u
.i
= FcDoubleFloor (vl
.u
.d
);
886 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
892 v
.type
= FcTypeInteger
;
893 v
.u
.i
= FcDoubleCeil (vl
.u
.d
);
902 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
908 v
.type
= FcTypeInteger
;
909 v
.u
.i
= FcDoubleRound (vl
.u
.d
);
918 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
924 v
.type
= FcTypeInteger
;
925 v
.u
.i
= FcDoubleTrunc (vl
.u
.d
);
941 FcConfigMatchValueList (FcPattern
*p
,
945 FcValueList
*ret
= 0;
952 if (e
->op
== FcOpComma
)
954 value
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
959 value
= FcConfigEvaluate (p
, e
);
963 for (v
= values
; v
; v
= v
->next
)
965 if (FcConfigCompareValue (v
->value
, t
->op
, value
))
972 if (t
->qual
== FcQualAll
)
979 FcValueDestroy (value
);
985 FcConfigValues (FcPattern
*p
, FcExpr
*e
, FcValueBinding binding
)
991 l
= (FcValueList
*) malloc (sizeof (FcValueList
));
994 FcMemAlloc (FC_MEM_VALLIST
, sizeof (FcValueList
));
995 if (e
->op
== FcOpComma
)
997 l
->value
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
998 l
->next
= FcConfigValues (p
, e
->u
.tree
.right
, binding
);
1002 l
->value
= FcConfigEvaluate (p
, e
);
1005 l
->binding
= binding
;
1006 while (l
&& l
->value
.type
== FcTypeVoid
)
1008 FcValueList
*next
= l
->next
;
1010 FcMemFree (FC_MEM_VALLIST
, sizeof (FcValueList
));
1018 FcConfigAdd (FcValueList
**head
,
1019 FcValueList
*position
,
1023 FcValueList
**prev
, *last
, *v
;
1024 FcValueBinding sameBinding
;
1027 sameBinding
= position
->binding
;
1029 sameBinding
= FcValueBindingWeak
;
1030 for (v
= new; v
; v
= v
->next
)
1031 if (v
->binding
== FcValueBindingSame
)
1032 v
->binding
= sameBinding
;
1036 prev
= &position
->next
;
1038 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1045 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1047 if (*prev
== position
)
1054 if (FcDebug () & FC_DBG_EDIT
)
1057 printf ("position not on list\n");
1061 if (FcDebug () & FC_DBG_EDIT
)
1063 printf ("%s list before ", append
? "Append" : "Prepend");
1064 FcValueListPrint (*head
);
1078 if (FcDebug () & FC_DBG_EDIT
)
1080 printf ("%s list after ", append
? "Append" : "Prepend");
1081 FcValueListPrint (*head
);
1089 FcConfigDel (FcValueList
**head
,
1090 FcValueList
*position
)
1094 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1096 if (*prev
== position
)
1098 *prev
= position
->next
;
1100 FcValueListDestroy (position
);
1107 FcConfigPatternAdd (FcPattern
*p
,
1114 FcPatternElt
*e
= FcPatternInsertElt (p
, object
);
1118 FcConfigAdd (&e
->values
, 0, append
, list
);
1123 * Delete all values associated with a field
1126 FcConfigPatternDel (FcPattern
*p
,
1129 FcPatternElt
*e
= FcPatternFindElt (p
, object
);
1133 FcConfigDel (&e
->values
, e
->values
);
1137 FcConfigPatternCanon (FcPattern
*p
,
1140 FcPatternElt
*e
= FcPatternFindElt (p
, object
);
1144 FcPatternDel (p
, object
);
1148 FcConfigSubstituteWithPat (FcConfig
*config
,
1163 config
= FcConfigGetCurrent ();
1168 st
= (FcSubState
*) malloc (config
->maxObjects
* sizeof (FcSubState
));
1169 if (!st
&& config
->maxObjects
)
1171 FcMemAlloc (FC_MEM_SUBSTATE
, config
->maxObjects
* sizeof (FcSubState
));
1173 if (FcDebug () & FC_DBG_EDIT
)
1175 printf ("FcConfigSubstitute ");
1178 if (kind
== FcMatchPattern
)
1179 s
= config
->substPattern
;
1181 s
= config
->substFont
;
1182 for (; s
; s
= s
->next
)
1185 * Check the tests to see if
1186 * they all match the pattern
1188 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1190 if (FcDebug () & FC_DBG_EDIT
)
1192 printf ("FcConfigSubstitute test ");
1196 if (kind
== FcMatchFont
&& t
->kind
== FcMatchPattern
)
1201 st
[i
].elt
= FcPatternFindElt (m
, t
->field
);
1205 * If there's no such field in the font,
1206 * then FcQualAll matches while FcQualAny does not
1210 if (t
->qual
== FcQualAll
)
1219 * Check to see if there is a match, mark the location
1220 * to apply match-relative edits
1222 st
[i
].value
= FcConfigMatchValueList (m
, t
, st
[i
].elt
->values
);
1225 if (t
->qual
== FcQualFirst
&& st
[i
].value
!= st
[i
].elt
->values
)
1227 if (t
->qual
== FcQualNotFirst
&& st
[i
].value
== st
[i
].elt
->values
)
1232 if (FcDebug () & FC_DBG_EDIT
)
1233 printf ("No match\n");
1236 if (FcDebug () & FC_DBG_EDIT
)
1238 printf ("Substitute ");
1241 for (e
= s
->edit
; e
; e
= e
->next
)
1244 * Evaluate the list of expressions
1246 l
= FcConfigValues (p
, e
->expr
, e
->binding
);
1248 * Locate any test associated with this field, skipping
1249 * tests associated with the pattern when substituting in
1252 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1254 if ((t
->kind
== FcMatchFont
|| kind
== FcMatchPattern
) &&
1255 !FcStrCmpIgnoreCase ((FcChar8
*) t
->field
,
1256 (FcChar8
*) e
->field
))
1259 * KLUDGE - the pattern may have been reallocated or
1260 * things may have been inserted or deleted above
1261 * this element by other edits. Go back and find
1264 if (e
!= s
->edit
&& st
[i
].elt
)
1265 st
[i
].elt
= FcPatternFindElt (p
, t
->field
);
1274 * If there was a test, then replace the matched
1275 * value with the new list of values
1279 FcValueList
*thisValue
= st
[i
].value
;
1280 FcValueList
*nextValue
= thisValue
? thisValue
->next
: 0;
1283 * Append the new list of values after the current value
1285 FcConfigAdd (&st
[i
].elt
->values
, thisValue
, FcTrue
, l
);
1287 * Delete the marked value
1289 FcConfigDel (&st
[i
].elt
->values
, thisValue
);
1291 * Adjust any pointers into the value list to ensure
1292 * future edits occur at the same place
1294 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1296 if (st
[i
].value
== thisValue
)
1297 st
[i
].value
= nextValue
;
1301 /* fall through ... */
1302 case FcOpAssignReplace
:
1304 * Delete all of the values and insert
1307 FcConfigPatternDel (p
, e
->field
);
1308 FcConfigPatternAdd (p
, e
->field
, l
, FcTrue
);
1310 * Adjust any pointers into the value list as they no
1311 * longer point to anything valid
1315 FcPatternElt
*thisElt
= st
[i
].elt
;
1316 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1318 if (st
[i
].elt
== thisElt
)
1326 FcConfigAdd (&st
[i
].elt
->values
, st
[i
].value
, FcFalse
, l
);
1329 /* fall through ... */
1330 case FcOpPrependFirst
:
1331 FcConfigPatternAdd (p
, e
->field
, l
, FcFalse
);
1336 FcConfigAdd (&st
[i
].elt
->values
, st
[i
].value
, FcTrue
, l
);
1339 /* fall through ... */
1340 case FcOpAppendLast
:
1341 FcConfigPatternAdd (p
, e
->field
, l
, FcTrue
);
1348 * Now go through the pattern and eliminate
1349 * any properties without data
1351 for (e
= s
->edit
; e
; e
= e
->next
)
1352 FcConfigPatternCanon (p
, e
->field
);
1354 if (FcDebug () & FC_DBG_EDIT
)
1356 printf ("FcConfigSubstitute edit");
1360 FcMemFree (FC_MEM_SUBSTATE
, config
->maxObjects
* sizeof (FcSubState
));
1362 if (FcDebug () & FC_DBG_EDIT
)
1364 printf ("FcConfigSubstitute done");
1371 FcConfigSubstitute (FcConfig
*config
,
1375 return FcConfigSubstituteWithPat (config
, p
, 0, kind
);
1378 #if defined (_WIN32) && (defined (PIC) || defined (DLL_EXPORT))
1380 static FcChar8 fontconfig_path
[1000] = "";
1383 DllMain (HINSTANCE hinstDLL
,
1389 switch (fdwReason
) {
1390 case DLL_PROCESS_ATTACH
:
1391 if (!GetModuleFileName ((HMODULE
) hinstDLL
, fontconfig_path
,
1392 sizeof (fontconfig_path
)))
1395 /* If the fontconfig DLL is in a "bin" or "lib" subfolder,
1396 * assume it's a Unix-style installation tree, and use
1397 * "etc/fonts" in there as FONTCONFIG_PATH. Otherwise use the
1398 * folder where the DLL is as FONTCONFIG_PATH.
1400 p
= strrchr (fontconfig_path
, '\\');
1404 p
= strrchr (fontconfig_path
, '\\');
1405 if (p
&& (FcStrCmpIgnoreCase (p
+ 1, "bin") == 0 ||
1406 FcStrCmpIgnoreCase (p
+ 1, "lib") == 0))
1408 strcat (fontconfig_path
, "\\etc\\fonts");
1411 fontconfig_path
[0] = '\0';
1419 #undef FONTCONFIG_PATH
1420 #define FONTCONFIG_PATH fontconfig_path
1422 #else /* !(_WIN32 && PIC) */
1424 #endif /* !(_WIN32 && PIC) */
1426 #ifndef FONTCONFIG_FILE
1427 #define FONTCONFIG_FILE "fonts.conf"
1431 FcConfigFileExists (const FcChar8
*dir
, const FcChar8
*file
)
1436 dir
= (FcChar8
*) "";
1437 path
= malloc (strlen ((char *) dir
) + 1 + strlen ((char *) file
) + 1);
1441 strcpy ((char *) path
, (const char *) dir
);
1442 /* make sure there's a single separator */
1444 if ((!path
[0] || (path
[strlen((char *) path
)-1] != '/' &&
1445 path
[strlen((char *) path
)-1] != '\\')) &&
1446 (file
[0] != '/' && file
[0] != '\\'))
1447 strcat ((char *) path
, "\\");
1449 if ((!path
[0] || path
[strlen((char *) path
)-1] != '/') && file
[0] != '/')
1450 strcat ((char *) path
, "/");
1452 strcat ((char *) path
, (char *) file
);
1454 FcMemAlloc (FC_MEM_STRING
, strlen ((char *) path
) + 1);
1455 if (access ((char *) path
, R_OK
) == 0)
1463 FcConfigGetPath (void)
1466 FcChar8
*env
, *e
, *colon
;
1471 npath
= 2; /* default dir + null */
1472 env
= (FcChar8
*) getenv ("FONTCONFIG_PATH");
1478 if (*e
++ == FC_SEARCH_PATH_SEPARATOR
)
1481 path
= calloc (npath
, sizeof (FcChar8
*));
1491 colon
= (FcChar8
*) strchr ((char *) e
, FC_SEARCH_PATH_SEPARATOR
);
1493 colon
= e
+ strlen ((char *) e
);
1494 path
[i
] = malloc (colon
- e
+ 1);
1497 strncpy ((char *) path
[i
], (const char *) e
, colon
- e
);
1498 path
[i
][colon
- e
] = '\0';
1507 dir
= (FcChar8
*) FONTCONFIG_PATH
;
1508 path
[i
] = malloc (strlen ((char *) dir
) + 1);
1511 strcpy ((char *) path
[i
], (const char *) dir
);
1515 for (i
= 0; path
[i
]; i
++)
1523 FcConfigFreePath (FcChar8
**path
)
1527 for (p
= path
; *p
; p
++)
1532 static FcBool _FcConfigHomeEnabled
= FcTrue
;
1537 if (_FcConfigHomeEnabled
)
1539 char *home
= getenv ("HOME");
1543 home
= getenv ("USERPROFILE");
1552 FcConfigEnableHome (FcBool enable
)
1554 FcBool prev
= _FcConfigHomeEnabled
;
1555 _FcConfigHomeEnabled
= enable
;
1560 FcConfigFilename (const FcChar8
*url
)
1562 FcChar8
*file
, *dir
, **path
, **p
;
1566 url
= (FcChar8
*) getenv ("FONTCONFIG_FILE");
1568 url
= (FcChar8
*) FONTCONFIG_FILE
;
1573 if (isalpha (*url
) &&
1575 (url
[2] == '/' || url
[2] == '\\'))
1581 dir
= FcConfigHome ();
1583 file
= FcConfigFileExists (dir
, url
+ 1);
1592 file
= FcConfigFileExists (0, url
);
1595 path
= FcConfigGetPath ();
1598 for (p
= path
; *p
; p
++)
1600 file
= FcConfigFileExists (*p
, url
);
1604 FcConfigFreePath (path
);
1611 * Manage the application-specific fonts
1615 FcConfigAppFontAddFile (FcConfig
*config
,
1616 const FcChar8
*file
)
1625 config
= FcConfigGetCurrent ();
1630 subdirs
= FcStrSetCreate ();
1634 set
= FcConfigGetFonts (config
, FcSetApplication
);
1637 set
= FcFontSetCreate ();
1640 FcStrSetDestroy (subdirs
);
1643 FcConfigSetFonts (config
, set
, FcSetApplication
);
1646 if (!FcFileScanConfig (set
, subdirs
, 0, config
->blanks
, file
, FcFalse
, config
))
1648 FcStrSetDestroy (subdirs
);
1651 if ((sublist
= FcStrListCreate (subdirs
)))
1653 while ((subdir
= FcStrListNext (sublist
)))
1655 FcConfigAppFontAddDir (config
, subdir
);
1657 FcStrListDone (sublist
);
1663 FcConfigAppFontAddDir (FcConfig
*config
,
1673 config
= FcConfigGetCurrent ();
1677 subdirs
= FcStrSetCreate ();
1681 set
= FcConfigGetFonts (config
, FcSetApplication
);
1684 set
= FcFontSetCreate ();
1687 FcStrSetDestroy (subdirs
);
1690 FcConfigSetFonts (config
, set
, FcSetApplication
);
1693 if (!FcDirScanConfig (set
, subdirs
, 0, config
->blanks
, dir
, FcFalse
, config
))
1695 FcStrSetDestroy (subdirs
);
1698 if ((sublist
= FcStrListCreate (subdirs
)))
1700 while ((subdir
= FcStrListNext (sublist
)))
1702 FcConfigAppFontAddDir (config
, subdir
);
1704 FcStrListDone (sublist
);
1710 FcConfigAppFontClear (FcConfig
*config
)
1712 FcConfigSetFonts (config
, 0, FcSetApplication
);
1716 * Manage filename-based font source selectors
1720 FcConfigGlobAdd (FcConfig
*config
,
1721 const FcChar8
*glob
,
1724 FcStrSet
*set
= accept
? config
->acceptGlobs
: config
->rejectGlobs
;
1726 return FcStrSetAdd (set
, glob
);
1730 FcConfigGlobMatch (const FcChar8
*glob
,
1731 const FcChar8
*string
)
1735 while ((c
= *glob
++))
1739 /* short circuit common case */
1742 /* short circuit another common case */
1743 if (strchr ((char *) glob
, '*') == 0)
1744 string
+= strlen ((char *) string
) - strlen ((char *) glob
);
1747 if (FcConfigGlobMatch (glob
, string
))
1753 if (*string
++ == '\0')
1762 return *string
== '\0';
1766 FcConfigGlobsMatch (const FcStrSet
*globs
,
1767 const FcChar8
*string
)
1771 for (i
= 0; i
< globs
->num
; i
++)
1772 if (FcConfigGlobMatch (globs
->strs
[i
], string
))
1778 FcConfigAcceptFilename (FcConfig
*config
,
1779 const FcChar8
*filename
)
1781 if (FcConfigGlobsMatch (config
->acceptGlobs
, filename
))
1783 if (FcConfigGlobsMatch (config
->rejectGlobs
, filename
))