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
)
60 if (!FcConfigSetCache (config
, (FcChar8
*) ("~/" FC_USER_CACHE_FILE
)))
65 config
->substPattern
= 0;
66 config
->substFont
= 0;
67 config
->maxObjects
= 0;
68 for (set
= FcSetSystem
; set
<= FcSetApplication
; set
++)
69 config
->fonts
[set
] = 0;
71 config
->rescanTime
= time(0);
72 config
->rescanInterval
= 30;
77 FcStrSetDestroy (config
->fontDirs
);
79 FcStrSetDestroy (config
->configFiles
);
81 FcStrSetDestroy (config
->configDirs
);
84 FcMemFree (FC_MEM_CONFIG
, sizeof (FcConfig
));
89 typedef struct _FcFileTime
{
95 FcConfigNewestFile (FcStrSet
*files
)
97 FcStrList
*list
= FcStrListCreate (files
);
98 FcFileTime newest
= { 0, FcFalse
};
104 while ((file
= FcStrListNext (list
)))
105 if (stat ((char *) file
, &statb
) == 0)
106 if (!newest
.set
|| statb
.st_mtime
- newest
.time
> 0)
107 newest
.time
= statb
.st_mtime
;
108 FcStrListDone (list
);
114 FcConfigUptoDate (FcConfig
*config
)
116 FcFileTime config_time
, font_time
;
117 time_t now
= time(0);
120 config
= FcConfigGetCurrent ();
124 config_time
= FcConfigNewestFile (config
->configFiles
);
125 font_time
= FcConfigNewestFile (config
->configDirs
);
126 if ((config_time
.set
&& config_time
.time
- config
->rescanTime
> 0) ||
127 (font_time
.set
&& font_time
.time
- config
->rescanTime
) > 0)
131 config
->rescanTime
= now
;
136 FcSubstDestroy (FcSubst
*s
)
144 FcTestDestroy (s
->test
);
146 FcEditDestroy (s
->edit
);
152 FcConfigDestroy (FcConfig
*config
)
156 if (config
== _fcConfig
)
159 FcStrSetDestroy (config
->configDirs
);
160 FcStrSetDestroy (config
->fontDirs
);
161 FcStrSetDestroy (config
->configFiles
);
163 FcStrFree (config
->cache
);
165 FcSubstDestroy (config
->substPattern
);
166 FcSubstDestroy (config
->substFont
);
167 for (set
= FcSetSystem
; set
<= FcSetApplication
; set
++)
168 if (config
->fonts
[set
])
169 FcFontSetDestroy (config
->fonts
[set
]);
171 FcMemFree (FC_MEM_CONFIG
, sizeof (FcConfig
));
175 * Scan the current list of directories in the configuration
176 * and build the set of available fonts. Update the
177 * per-user cache file to reflect the new configuration
181 FcConfigBuildFonts (FcConfig
*config
)
184 FcGlobalCache
*cache
;
188 fonts
= FcFontSetCreate ();
192 cache
= FcGlobalCacheCreate ();
196 FcGlobalCacheLoad (cache
, config
->cache
);
198 list
= FcConfigGetFontDirs (config
);
202 while ((dir
= FcStrListNext (list
)))
204 if (FcDebug () & FC_DBG_FONTSET
)
205 printf ("scan dir %s\n", dir
);
206 FcDirScan (fonts
, config
->fontDirs
, cache
, config
->blanks
, dir
, FcFalse
);
209 FcStrListDone (list
);
211 if (FcDebug () & FC_DBG_FONTSET
)
212 FcFontSetPrint (fonts
);
214 FcGlobalCacheSave (cache
, config
->cache
);
215 FcGlobalCacheDestroy (cache
);
217 FcConfigSetFonts (config
, fonts
, FcSetSystem
);
221 FcFontSetDestroy (fonts
);
227 FcConfigSetCurrent (FcConfig
*config
)
230 if (!FcConfigBuildFonts (config
))
234 FcConfigDestroy (_fcConfig
);
240 FcConfigGetCurrent (void)
249 FcConfigAddConfigDir (FcConfig
*config
,
252 return FcStrSetAddFilename (config
->configDirs
, d
);
256 FcConfigGetConfigDirs (FcConfig
*config
)
260 config
= FcConfigGetCurrent ();
264 return FcStrListCreate (config
->configDirs
);
268 FcConfigAddFontDir (FcConfig
*config
,
271 return FcStrSetAddFilename (config
->fontDirs
, d
);
275 FcConfigAddDir (FcConfig
*config
,
278 return (FcConfigAddConfigDir (config
, d
) &&
279 FcConfigAddFontDir (config
, d
));
283 FcConfigGetFontDirs (FcConfig
*config
)
287 config
= FcConfigGetCurrent ();
291 return FcStrListCreate (config
->fontDirs
);
295 FcConfigAddConfigFile (FcConfig
*config
,
299 FcChar8
*file
= FcConfigFilename (f
);
304 ret
= FcStrSetAdd (config
->configFiles
, file
);
310 FcConfigGetConfigFiles (FcConfig
*config
)
314 config
= FcConfigGetCurrent ();
318 return FcStrListCreate (config
->configFiles
);
322 FcConfigSetCache (FcConfig
*config
,
325 FcChar8
*new = FcStrCopyFilename (c
);
330 FcStrFree (config
->cache
);
336 FcConfigGetCache (FcConfig
*config
)
340 config
= FcConfigGetCurrent ();
344 return config
->cache
;
348 FcConfigGetFonts (FcConfig
*config
,
353 config
= FcConfigGetCurrent ();
357 return config
->fonts
[set
];
361 FcConfigSetFonts (FcConfig
*config
,
365 if (config
->fonts
[set
])
366 FcFontSetDestroy (config
->fonts
[set
]);
367 config
->fonts
[set
] = fonts
;
373 FcConfigGetBlanks (FcConfig
*config
)
377 config
= FcConfigGetCurrent ();
381 return config
->blanks
;
385 FcConfigAddBlank (FcConfig
*config
,
393 b
= FcBlanksCreate ();
397 if (!FcBlanksAdd (b
, blank
))
404 FcConfigGetRescanInverval (FcConfig
*config
)
408 config
= FcConfigGetCurrent ();
412 return config
->rescanInterval
;
416 FcConfigSetRescanInverval (FcConfig
*config
, int rescanInterval
)
420 config
= FcConfigGetCurrent ();
424 config
->rescanInterval
= rescanInterval
;
429 FcConfigAddEdit (FcConfig
*config
,
434 FcSubst
*subst
, **prev
;
438 subst
= (FcSubst
*) malloc (sizeof (FcSubst
));
441 FcMemAlloc (FC_MEM_SUBST
, sizeof (FcSubst
));
442 if (kind
== FcMatchPattern
)
443 prev
= &config
->substPattern
;
445 prev
= &config
->substFont
;
446 for (; *prev
; prev
= &(*prev
)->next
);
452 for (t
= test
; t
; t
= t
->next
)
454 if (t
->kind
== FcMatchDefault
)
458 if (config
->maxObjects
< num
)
459 config
->maxObjects
= num
;
460 if (FcDebug () & FC_DBG_EDIT
)
462 printf ("Add Subst ");
463 FcSubstPrint (subst
);
468 typedef struct _FcSubState
{
474 FcConfigPromote (FcValue v
, FcValue u
)
476 if (v
.type
== FcTypeInteger
)
478 v
.type
= FcTypeDouble
;
479 v
.u
.d
= (double) v
.u
.i
;
481 else if (v
.type
== FcTypeVoid
&& u
.type
== FcTypeMatrix
)
483 v
.u
.m
= &FcIdentityMatrix
;
484 v
.type
= FcTypeMatrix
;
486 else if (v
.type
== FcTypeString
&& u
.type
== FcTypeLangSet
)
488 v
.u
.l
= FcLangSetPromote (v
.u
.s
);
489 v
.type
= FcTypeLangSet
;
495 FcConfigCompareValue (const FcValue m_o
,
501 FcBool ret
= FcFalse
;
503 m
= FcConfigPromote (m
, v
);
504 v
= FcConfigPromote (v
, m
);
505 if (m
.type
== v
.type
)
509 break; /* FcConfigPromote prevents this from happening */
514 ret
= m
.u
.d
== v
.u
.d
;
517 case FcOpNotContains
:
518 ret
= m
.u
.d
!= v
.u
.d
;
524 ret
= m
.u
.d
<= v
.u
.d
;
530 ret
= m
.u
.d
>= v
.u
.d
;
540 ret
= m
.u
.b
== v
.u
.b
;
543 case FcOpNotContains
:
544 ret
= m
.u
.b
!= v
.u
.b
;
554 ret
= FcStrCmpIgnoreCase (m
.u
.s
, v
.u
.s
) == 0;
557 case FcOpNotContains
:
558 ret
= FcStrCmpIgnoreCase (m
.u
.s
, v
.u
.s
) != 0;
568 ret
= FcMatrixEqual (m
.u
.m
, v
.u
.m
);
571 case FcOpNotContains
:
572 ret
= !FcMatrixEqual (m
.u
.m
, v
.u
.m
);
581 /* m contains v if v is a subset of m */
582 ret
= FcCharSetIsSubset (v
.u
.c
, m
.u
.c
);
584 case FcOpNotContains
:
585 /* m contains v if v is a subset of m */
586 ret
= !FcCharSetIsSubset (v
.u
.c
, m
.u
.c
);
589 ret
= FcCharSetEqual (m
.u
.c
, v
.u
.c
);
592 ret
= !FcCharSetEqual (m
.u
.c
, v
.u
.c
);
601 ret
= FcLangSetContains (v
.u
.l
, m
.u
.l
);
603 case FcOpNotContains
:
604 ret
= FcLangSetContains (v
.u
.l
, m
.u
.l
);
607 ret
= FcLangSetEqual (v
.u
.l
, m
.u
.l
);
610 ret
= !FcLangSetEqual (v
.u
.l
, m
.u
.l
);
630 ret
= m
.u
.f
== v
.u
.f
;
633 case FcOpNotContains
:
634 ret
= m
.u
.f
!= v
.u
.f
;
644 if (op
== FcOpNotEqual
|| op
== FcOpNotContains
)
651 #define _FcDoubleFloor(d) ((int) (d))
652 #define _FcDoubleCeil(d) ((double) (int) (d) == (d) ? (int) (d) : (int) ((d) + 1))
653 #define FcDoubleFloor(d) ((d) >= 0 ? _FcDoubleFloor(d) : -_FcDoubleCeil(-(d)))
654 #define FcDoubleCeil(d) ((d) >= 0 ? _FcDoubleCeil(d) : -_FcDoubleFloor(-(d)))
655 #define FcDoubleRound(d) FcDoubleFloor ((d) + 0.5)
656 #define FcDoubleTrunc(d) ((d) >= 0 ? _FcDoubleFloor (d) : -_FcDoubleFloor (-(d)))
659 FcConfigEvaluate (FcPattern
*p
, FcExpr
*e
)
667 v
.type
= FcTypeInteger
;
671 v
.type
= FcTypeDouble
;
675 v
.type
= FcTypeString
;
680 v
.type
= FcTypeMatrix
;
685 v
.type
= FcTypeCharSet
;
694 r
= FcPatternGet (p
, e
->u
.field
, 0, &v
);
695 if (r
!= FcResultMatch
)
699 if (FcNameConstant (e
->u
.constant
, &v
.u
.i
))
700 v
.type
= FcTypeInteger
;
705 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
706 if (vl
.type
== FcTypeBool
)
709 v
= FcConfigEvaluate (p
, e
->u
.tree
.right
->u
.tree
.left
);
711 v
= FcConfigEvaluate (p
, e
->u
.tree
.right
->u
.tree
.right
);
724 case FcOpNotContains
:
725 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
726 vr
= FcConfigEvaluate (p
, e
->u
.tree
.right
);
728 v
.u
.b
= FcConfigCompareValue (vl
, e
->op
, vr
);
738 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
739 vr
= FcConfigEvaluate (p
, e
->u
.tree
.right
);
740 vl
= FcConfigPromote (vl
, vr
);
741 vr
= FcConfigPromote (vr
, vl
);
742 if (vl
.type
== vr
.type
)
748 v
.type
= FcTypeDouble
;
749 v
.u
.d
= vl
.u
.d
+ vr
.u
.d
;
752 v
.type
= FcTypeDouble
;
753 v
.u
.d
= vl
.u
.d
- vr
.u
.d
;
756 v
.type
= FcTypeDouble
;
757 v
.u
.d
= vl
.u
.d
* vr
.u
.d
;
760 v
.type
= FcTypeDouble
;
761 v
.u
.d
= vl
.u
.d
/ vr
.u
.d
;
767 if (v
.type
== FcTypeDouble
&&
768 v
.u
.d
== (double) (int) v
.u
.d
)
770 v
.type
= FcTypeInteger
;
778 v
.u
.b
= vl
.u
.b
|| vr
.u
.b
;
782 v
.u
.b
= vl
.u
.b
&& vr
.u
.b
;
792 v
.type
= FcTypeString
;
793 v
.u
.s
= FcStrPlus (vl
.u
.s
, vr
.u
.s
);
805 v
.type
= FcTypeMatrix
;
806 m
= malloc (sizeof (FcMatrix
));
809 FcMemAlloc (FC_MEM_MATRIX
, sizeof (FcMatrix
));
810 FcMatrixMultiply (m
, vl
.u
.m
, vr
.u
.m
);
834 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
847 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
853 v
.type
= FcTypeInteger
;
854 v
.u
.i
= FcDoubleFloor (vl
.u
.d
);
863 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
869 v
.type
= FcTypeInteger
;
870 v
.u
.i
= FcDoubleCeil (vl
.u
.d
);
879 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
885 v
.type
= FcTypeInteger
;
886 v
.u
.i
= FcDoubleRound (vl
.u
.d
);
895 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
901 v
.type
= FcTypeInteger
;
902 v
.u
.i
= FcDoubleTrunc (vl
.u
.d
);
918 FcConfigMatchValueList (FcPattern
*p
,
922 FcValueList
*ret
= 0;
929 if (e
->op
== FcOpComma
)
931 value
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
936 value
= FcConfigEvaluate (p
, e
);
940 for (v
= values
; v
; v
= v
->next
)
942 if (FcConfigCompareValue (v
->value
, t
->op
, value
))
949 if (t
->qual
== FcQualAll
)
956 FcValueDestroy (value
);
962 FcConfigValues (FcPattern
*p
, FcExpr
*e
, FcValueBinding binding
)
968 l
= (FcValueList
*) malloc (sizeof (FcValueList
));
971 FcMemAlloc (FC_MEM_VALLIST
, sizeof (FcValueList
));
972 if (e
->op
== FcOpComma
)
974 l
->value
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
975 l
->next
= FcConfigValues (p
, e
->u
.tree
.right
, binding
);
979 l
->value
= FcConfigEvaluate (p
, e
);
982 l
->binding
= binding
;
983 while (l
&& l
->value
.type
== FcTypeVoid
)
985 FcValueList
*next
= l
->next
;
987 FcMemFree (FC_MEM_VALLIST
, sizeof (FcValueList
));
995 FcConfigAdd (FcValueList
**head
,
996 FcValueList
*position
,
1000 FcValueList
**prev
, *last
, *v
;
1001 FcValueBinding sameBinding
;
1004 sameBinding
= position
->binding
;
1006 sameBinding
= FcValueBindingWeak
;
1007 for (v
= new; v
; v
= v
->next
)
1008 if (v
->binding
== FcValueBindingSame
)
1009 v
->binding
= sameBinding
;
1013 prev
= &position
->next
;
1015 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1022 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1024 if (*prev
== position
)
1031 if (FcDebug () & FC_DBG_EDIT
)
1034 printf ("position not on list\n");
1038 if (FcDebug () & FC_DBG_EDIT
)
1040 printf ("%s list before ", append
? "Append" : "Prepend");
1041 FcValueListPrint (*head
);
1055 if (FcDebug () & FC_DBG_EDIT
)
1057 printf ("%s list after ", append
? "Append" : "Prepend");
1058 FcValueListPrint (*head
);
1066 FcConfigDel (FcValueList
**head
,
1067 FcValueList
*position
)
1071 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1073 if (*prev
== position
)
1075 *prev
= position
->next
;
1077 FcValueListDestroy (position
);
1084 FcConfigPatternAdd (FcPattern
*p
,
1091 FcPatternElt
*e
= FcPatternInsertElt (p
, object
);
1095 FcConfigAdd (&e
->values
, 0, append
, list
);
1100 * Delete all values associated with a field
1103 FcConfigPatternDel (FcPattern
*p
,
1106 FcPatternElt
*e
= FcPatternFindElt (p
, object
);
1110 FcConfigDel (&e
->values
, e
->values
);
1114 FcConfigPatternCanon (FcPattern
*p
,
1117 FcPatternElt
*e
= FcPatternFindElt (p
, object
);
1121 FcPatternDel (p
, object
);
1125 FcConfigSubstituteWithPat (FcConfig
*config
,
1140 config
= FcConfigGetCurrent ();
1145 st
= (FcSubState
*) malloc (config
->maxObjects
* sizeof (FcSubState
));
1146 if (!st
&& config
->maxObjects
)
1148 FcMemAlloc (FC_MEM_SUBSTATE
, config
->maxObjects
* sizeof (FcSubState
));
1150 if (FcDebug () & FC_DBG_EDIT
)
1152 printf ("FcConfigSubstitute ");
1155 if (kind
== FcMatchPattern
)
1156 s
= config
->substPattern
;
1158 s
= config
->substFont
;
1159 for (; s
; s
= s
->next
)
1162 * Check the tests to see if
1163 * they all match the pattern
1165 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1167 if (FcDebug () & FC_DBG_EDIT
)
1169 printf ("FcConfigSubstitute test ");
1173 if (kind
== FcMatchFont
&& t
->kind
== FcMatchPattern
)
1178 st
[i
].elt
= FcPatternFindElt (m
, t
->field
);
1182 * If there's no such field in the font,
1183 * then FcQualAll matches while FcQualAny does not
1187 if (t
->qual
== FcQualAll
)
1196 * Check to see if there is a match, mark the location
1197 * to apply match-relative edits
1199 st
[i
].value
= FcConfigMatchValueList (m
, t
, st
[i
].elt
->values
);
1202 if (t
->qual
== FcQualFirst
&& st
[i
].value
!= st
[i
].elt
->values
)
1204 if (t
->qual
== FcQualNotFirst
&& st
[i
].value
== st
[i
].elt
->values
)
1209 if (FcDebug () & FC_DBG_EDIT
)
1210 printf ("No match\n");
1213 if (FcDebug () & FC_DBG_EDIT
)
1215 printf ("Substitute ");
1218 for (e
= s
->edit
; e
; e
= e
->next
)
1221 * Evaluate the list of expressions
1223 l
= FcConfigValues (p
, e
->expr
, e
->binding
);
1225 * Locate any test associated with this field, skipping
1226 * tests associated with the pattern when substituting in
1229 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1231 if ((t
->kind
== FcMatchFont
|| kind
== FcMatchPattern
) &&
1232 !FcStrCmpIgnoreCase ((FcChar8
*) t
->field
,
1233 (FcChar8
*) e
->field
))
1236 * KLUDGE - the pattern may have been reallocated or
1237 * things may have been inserted or deleted above
1238 * this element by other edits. Go back and find
1241 if (e
!= s
->edit
&& st
[i
].elt
)
1242 st
[i
].elt
= FcPatternFindElt (p
, t
->field
);
1251 * If there was a test, then replace the matched
1252 * value with the new list of values
1256 FcValueList
*thisValue
= st
[i
].value
;
1257 FcValueList
*nextValue
= thisValue
? thisValue
->next
: 0;
1260 * Append the new list of values after the current value
1262 FcConfigAdd (&st
[i
].elt
->values
, thisValue
, FcTrue
, l
);
1264 * Delete the marked value
1266 FcConfigDel (&st
[i
].elt
->values
, thisValue
);
1268 * Adjust any pointers into the value list to ensure
1269 * future edits occur at the same place
1271 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1273 if (st
[i
].value
== thisValue
)
1274 st
[i
].value
= nextValue
;
1278 /* fall through ... */
1279 case FcOpAssignReplace
:
1281 * Delete all of the values and insert
1284 FcConfigPatternDel (p
, e
->field
);
1285 FcConfigPatternAdd (p
, e
->field
, l
, FcTrue
);
1287 * Adjust any pointers into the value list as they no
1288 * longer point to anything valid
1292 FcPatternElt
*thisElt
= st
[i
].elt
;
1293 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1295 if (st
[i
].elt
== thisElt
)
1303 FcConfigAdd (&st
[i
].elt
->values
, st
[i
].value
, FcFalse
, l
);
1306 /* fall through ... */
1307 case FcOpPrependFirst
:
1308 FcConfigPatternAdd (p
, e
->field
, l
, FcFalse
);
1313 FcConfigAdd (&st
[i
].elt
->values
, st
[i
].value
, FcTrue
, l
);
1316 /* fall through ... */
1317 case FcOpAppendLast
:
1318 FcConfigPatternAdd (p
, e
->field
, l
, FcTrue
);
1325 * Now go through the pattern and eliminate
1326 * any properties without data
1328 for (e
= s
->edit
; e
; e
= e
->next
)
1329 FcConfigPatternCanon (p
, e
->field
);
1331 if (FcDebug () & FC_DBG_EDIT
)
1333 printf ("FcConfigSubstitute edit");
1337 FcMemFree (FC_MEM_SUBSTATE
, config
->maxObjects
* sizeof (FcSubState
));
1339 if (FcDebug () & FC_DBG_EDIT
)
1341 printf ("FcConfigSubstitute done");
1348 FcConfigSubstitute (FcConfig
*config
,
1352 return FcConfigSubstituteWithPat (config
, p
, 0, kind
);
1355 #if defined (_WIN32) && defined (PIC)
1357 static FcChar8 fontconfig_path
[1000] = "";
1360 DllMain (HINSTANCE hinstDLL
,
1366 switch (fdwReason
) {
1367 case DLL_PROCESS_ATTACH
:
1368 if (!GetModuleFileName ((HMODULE
) hinstDLL
, fontconfig_path
,
1369 sizeof (fontconfig_path
)))
1372 /* If the fontconfig DLL is in a "bin" or "lib" subfolder,
1373 * assume it's a Unix-style installation tree, and use
1374 * "etc/fonts" in there as FONTCONFIG_PATH. Otherwise use the
1375 * folder where the DLL is as FONTCONFIG_PATH.
1377 p
= strrchr (fontconfig_path
, '\\');
1381 p
= strrchr (fontconfig_path
, '\\');
1382 if (p
&& (FcStrCmpIgnoreCase (p
+ 1, "bin") == 0 ||
1383 FcStrCmpIgnoreCase (p
+ 1, "lib") == 0))
1385 strcat (fontconfig_path
, "\\etc\\fonts");
1388 fontconfig_path
[0] = '\0';
1396 #undef FONTCONFIG_PATH
1397 #define FONTCONFIG_PATH fontconfig_path
1399 #else /* !(_WIN32 && PIC) */
1401 #endif /* !(_WIN32 && PIC) */
1403 #ifndef FONTCONFIG_FILE
1404 #define FONTCONFIG_FILE "fonts.conf"
1408 FcConfigFileExists (const FcChar8
*dir
, const FcChar8
*file
)
1413 dir
= (FcChar8
*) "";
1414 path
= malloc (strlen ((char *) dir
) + 1 + strlen ((char *) file
) + 1);
1418 strcpy ((char *) path
, (const char *) dir
);
1419 /* make sure there's a single separator */
1421 if ((!path
[0] || (path
[strlen((char *) path
)-1] != '/' &&
1422 path
[strlen((char *) path
)-1] != '\\')) &&
1423 (file
[0] != '/' && file
[0] != '\\'))
1424 strcat ((char *) path
, "\\");
1426 if ((!path
[0] || path
[strlen((char *) path
)-1] != '/') && file
[0] != '/')
1427 strcat ((char *) path
, "/");
1429 strcat ((char *) path
, (char *) file
);
1431 FcMemAlloc (FC_MEM_STRING
, strlen ((char *) path
) + 1);
1432 if (access ((char *) path
, R_OK
) == 0)
1440 FcConfigGetPath (void)
1443 FcChar8
*env
, *e
, *colon
;
1448 npath
= 2; /* default dir + null */
1449 env
= (FcChar8
*) getenv ("FONTCONFIG_PATH");
1455 if (*e
++ == FC_SEARCH_PATH_SEPARATOR
)
1458 path
= calloc (npath
, sizeof (FcChar8
*));
1468 colon
= (FcChar8
*) strchr ((char *) e
, FC_SEARCH_PATH_SEPARATOR
);
1470 colon
= e
+ strlen ((char *) e
);
1471 path
[i
] = malloc (colon
- e
+ 1);
1474 strncpy ((char *) path
[i
], (const char *) e
, colon
- e
);
1475 path
[i
][colon
- e
] = '\0';
1484 dir
= (FcChar8
*) FONTCONFIG_PATH
;
1485 path
[i
] = malloc (strlen ((char *) dir
) + 1);
1488 strcpy ((char *) path
[i
], (const char *) dir
);
1492 for (i
= 0; path
[i
]; i
++)
1500 FcConfigFreePath (FcChar8
**path
)
1504 for (p
= path
; *p
; p
++)
1509 static FcBool _FcConfigHomeEnabled
= FcTrue
;
1514 if (_FcConfigHomeEnabled
)
1516 char *home
= getenv ("HOME");
1520 home
= getenv ("USERPROFILE");
1529 FcConfigEnableHome (FcBool enable
)
1531 FcBool prev
= _FcConfigHomeEnabled
;
1532 _FcConfigHomeEnabled
= enable
;
1537 FcConfigFilename (const FcChar8
*url
)
1539 FcChar8
*file
, *dir
, **path
, **p
;
1543 url
= (FcChar8
*) getenv ("FONTCONFIG_FILE");
1545 url
= (FcChar8
*) FONTCONFIG_FILE
;
1550 if (isalpha (*url
) &&
1552 (url
[2] == '/' || url
[2] == '\\'))
1558 dir
= FcConfigHome ();
1560 file
= FcConfigFileExists (dir
, url
+ 1);
1569 file
= FcConfigFileExists (0, url
);
1572 path
= FcConfigGetPath ();
1575 for (p
= path
; *p
; p
++)
1577 file
= FcConfigFileExists (*p
, url
);
1581 FcConfigFreePath (path
);
1588 * Manage the application-specific fonts
1592 FcConfigAppFontAddFile (FcConfig
*config
,
1593 const FcChar8
*file
)
1602 config
= FcConfigGetCurrent ();
1607 subdirs
= FcStrSetCreate ();
1611 set
= FcConfigGetFonts (config
, FcSetApplication
);
1614 set
= FcFontSetCreate ();
1617 FcStrSetDestroy (subdirs
);
1620 FcConfigSetFonts (config
, set
, FcSetApplication
);
1623 if (!FcFileScan (set
, subdirs
, 0, config
->blanks
, file
, FcFalse
))
1625 FcStrSetDestroy (subdirs
);
1628 if ((sublist
= FcStrListCreate (subdirs
)))
1630 while ((subdir
= FcStrListNext (sublist
)))
1632 FcConfigAppFontAddDir (config
, subdir
);
1634 FcStrListDone (sublist
);
1640 FcConfigAppFontAddDir (FcConfig
*config
,
1650 config
= FcConfigGetCurrent ();
1654 subdirs
= FcStrSetCreate ();
1658 set
= FcConfigGetFonts (config
, FcSetApplication
);
1661 set
= FcFontSetCreate ();
1664 FcStrSetDestroy (subdirs
);
1667 FcConfigSetFonts (config
, set
, FcSetApplication
);
1670 if (!FcDirScan (set
, subdirs
, 0, config
->blanks
, dir
, FcFalse
))
1672 FcStrSetDestroy (subdirs
);
1675 if ((sublist
= FcStrListCreate (subdirs
)))
1677 while ((subdir
= FcStrListNext (sublist
)))
1679 FcConfigAppFontAddDir (config
, subdir
);
1681 FcStrListDone (sublist
);
1687 FcConfigAppFontClear (FcConfig
*config
)
1689 FcConfigSetFonts (config
, 0, FcSetApplication
);