2 * $RCSId: xc/lib/fontconfig/src/fccfg.c,v 1.23 2002/08/31 22:17:32 keithp Exp $
4 * Copyright © 2000 Keith Packard
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of Keith Packard not be used in
11 * advertising or publicity pertaining to distribution of the software without
12 * specific, written prior permission. Keith Packard makes no
13 * representations about the suitability of this software for any purpose. It
14 * is provided "as is" without express or implied warranty.
16 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22 * PERFORMANCE OF THIS SOFTWARE.
27 #if defined (_WIN32) && (defined (PIC) || defined (DLL_EXPORT))
33 #if defined (_WIN32) && !defined (R_OK)
45 config
= malloc (sizeof (FcConfig
));
48 FcMemAlloc (FC_MEM_CONFIG
, sizeof (FcConfig
));
50 config
->configDirs
= FcStrSetCreate ();
51 if (!config
->configDirs
)
54 config
->configFiles
= FcStrSetCreate ();
55 if (!config
->configFiles
)
58 config
->fontDirs
= FcStrSetCreate ();
59 if (!config
->fontDirs
)
62 config
->acceptGlobs
= FcStrSetCreate ();
63 if (!config
->acceptGlobs
)
66 config
->rejectGlobs
= FcStrSetCreate ();
67 if (!config
->rejectGlobs
)
72 if (!FcConfigSetCache (config
, (FcChar8
*) ("~/" FC_USER_CACHE_FILE
)))
76 if (config
->cache
== 0)
78 /* If no home, use the temp folder. */
80 int templen
= GetTempPath (1, dummy
);
81 FcChar8
*temp
= malloc (templen
+ 1);
87 GetTempPath (templen
+ 1, temp
);
88 cache_dir
= FcStrPlus (temp
, FC_USER_CACHE_FILE
);
90 if (!FcConfigSetCache (config
, cache_dir
))
92 FcStrFree (cache_dir
);
95 FcStrFree (cache_dir
);
102 config
->substPattern
= 0;
103 config
->substFont
= 0;
104 config
->maxObjects
= 0;
105 for (set
= FcSetSystem
; set
<= FcSetApplication
; set
++)
106 config
->fonts
[set
] = 0;
108 config
->rescanTime
= time(0);
109 config
->rescanInterval
= 30;
114 FcStrSetDestroy (config
->rejectGlobs
);
116 FcStrSetDestroy (config
->acceptGlobs
);
118 FcStrSetDestroy (config
->fontDirs
);
120 FcStrSetDestroy (config
->configFiles
);
122 FcStrSetDestroy (config
->configDirs
);
125 FcMemFree (FC_MEM_CONFIG
, sizeof (FcConfig
));
130 typedef struct _FcFileTime
{
136 FcConfigNewestFile (FcStrSet
*files
)
138 FcStrList
*list
= FcStrListCreate (files
);
139 FcFileTime newest
= { 0, FcFalse
};
145 while ((file
= FcStrListNext (list
)))
146 if (stat ((char *) file
, &statb
) == 0)
147 if (!newest
.set
|| statb
.st_mtime
- newest
.time
> 0)
150 newest
.time
= statb
.st_mtime
;
152 FcStrListDone (list
);
158 FcConfigUptoDate (FcConfig
*config
)
160 FcFileTime config_time
, font_time
;
161 time_t now
= time(0);
164 config
= FcConfigGetCurrent ();
168 config_time
= FcConfigNewestFile (config
->configFiles
);
169 font_time
= FcConfigNewestFile (config
->configDirs
);
170 if ((config_time
.set
&& config_time
.time
- config
->rescanTime
> 0) ||
171 (font_time
.set
&& font_time
.time
- config
->rescanTime
) > 0)
175 config
->rescanTime
= now
;
180 FcSubstDestroy (FcSubst
*s
)
188 FcTestDestroy (s
->test
);
190 FcEditDestroy (s
->edit
);
192 FcMemFree (FC_MEM_SUBST
, sizeof (FcSubst
));
198 FcConfigDestroy (FcConfig
*config
)
202 if (config
== _fcConfig
)
205 FcStrSetDestroy (config
->configDirs
);
206 FcStrSetDestroy (config
->fontDirs
);
207 FcStrSetDestroy (config
->configFiles
);
208 FcStrSetDestroy (config
->acceptGlobs
);
209 FcStrSetDestroy (config
->rejectGlobs
);
212 FcBlanksDestroy (config
->blanks
);
215 FcStrFree (config
->cache
);
217 FcSubstDestroy (config
->substPattern
);
218 FcSubstDestroy (config
->substFont
);
219 for (set
= FcSetSystem
; set
<= FcSetApplication
; set
++)
220 if (config
->fonts
[set
])
221 FcFontSetDestroy (config
->fonts
[set
]);
224 FcMemFree (FC_MEM_CONFIG
, sizeof (FcConfig
));
228 * Scan the current list of directories in the configuration
229 * and build the set of available fonts. Update the
230 * per-user cache file to reflect the new configuration
234 FcConfigBuildFonts (FcConfig
*config
)
237 FcGlobalCache
*cache
;
241 fonts
= FcFontSetCreate ();
245 cache
= FcGlobalCacheCreate ();
250 FcGlobalCacheLoad (cache
, config
->cache
);
252 list
= FcConfigGetFontDirs (config
);
256 while ((dir
= FcStrListNext (list
)))
258 if (FcDebug () & FC_DBG_FONTSET
)
259 printf ("scan dir %s\n", dir
);
260 FcDirScanConfig (fonts
, config
->fontDirs
, cache
,
261 config
->blanks
, dir
, FcFalse
, config
);
264 FcStrListDone (list
);
266 if (FcDebug () & FC_DBG_FONTSET
)
267 FcFontSetPrint (fonts
);
270 FcGlobalCacheSave (cache
, config
->cache
);
271 FcGlobalCacheDestroy (cache
);
273 FcConfigSetFonts (config
, fonts
, FcSetSystem
);
277 FcFontSetDestroy (fonts
);
283 FcConfigSetCurrent (FcConfig
*config
)
286 if (!FcConfigBuildFonts (config
))
290 FcConfigDestroy (_fcConfig
);
296 FcConfigGetCurrent (void)
305 FcConfigAddConfigDir (FcConfig
*config
,
308 return FcStrSetAddFilename (config
->configDirs
, d
);
312 FcConfigGetConfigDirs (FcConfig
*config
)
316 config
= FcConfigGetCurrent ();
320 return FcStrListCreate (config
->configDirs
);
324 FcConfigAddFontDir (FcConfig
*config
,
327 return FcStrSetAddFilename (config
->fontDirs
, d
);
331 FcConfigAddDir (FcConfig
*config
,
334 return (FcConfigAddConfigDir (config
, d
) &&
335 FcConfigAddFontDir (config
, d
));
339 FcConfigGetFontDirs (FcConfig
*config
)
343 config
= FcConfigGetCurrent ();
347 return FcStrListCreate (config
->fontDirs
);
351 FcConfigAddConfigFile (FcConfig
*config
,
355 FcChar8
*file
= FcConfigFilename (f
);
360 ret
= FcStrSetAdd (config
->configFiles
, file
);
366 FcConfigGetConfigFiles (FcConfig
*config
)
370 config
= FcConfigGetCurrent ();
374 return FcStrListCreate (config
->configFiles
);
378 FcConfigSetCache (FcConfig
*config
,
381 FcChar8
*new = FcStrCopyFilename (c
);
386 FcStrFree (config
->cache
);
392 FcConfigGetCache (FcConfig
*config
)
396 config
= FcConfigGetCurrent ();
400 return config
->cache
;
404 FcConfigGetFonts (FcConfig
*config
,
409 config
= FcConfigGetCurrent ();
413 return config
->fonts
[set
];
417 FcConfigSetFonts (FcConfig
*config
,
421 if (config
->fonts
[set
])
422 FcFontSetDestroy (config
->fonts
[set
]);
423 config
->fonts
[set
] = fonts
;
429 FcConfigGetBlanks (FcConfig
*config
)
433 config
= FcConfigGetCurrent ();
437 return config
->blanks
;
441 FcConfigAddBlank (FcConfig
*config
,
449 b
= FcBlanksCreate ();
453 if (!FcBlanksAdd (b
, blank
))
460 FcConfigGetRescanInverval (FcConfig
*config
)
464 config
= FcConfigGetCurrent ();
468 return config
->rescanInterval
;
472 FcConfigSetRescanInverval (FcConfig
*config
, int rescanInterval
)
476 config
= FcConfigGetCurrent ();
480 config
->rescanInterval
= rescanInterval
;
485 FcConfigAddEdit (FcConfig
*config
,
490 FcSubst
*subst
, **prev
;
494 subst
= (FcSubst
*) malloc (sizeof (FcSubst
));
497 FcMemAlloc (FC_MEM_SUBST
, sizeof (FcSubst
));
498 if (kind
== FcMatchPattern
)
499 prev
= &config
->substPattern
;
501 prev
= &config
->substFont
;
502 for (; *prev
; prev
= &(*prev
)->next
);
508 for (t
= test
; t
; t
= t
->next
)
510 if (t
->kind
== FcMatchDefault
)
514 if (config
->maxObjects
< num
)
515 config
->maxObjects
= num
;
516 if (FcDebug () & FC_DBG_EDIT
)
518 printf ("Add Subst ");
519 FcSubstPrint (subst
);
524 typedef struct _FcSubState
{
530 FcConfigPromote (FcValue v
, FcValue u
)
532 if (v
.type
== FcTypeInteger
)
534 v
.type
= FcTypeDouble
;
535 v
.u
.d
= (double) v
.u
.i
;
537 else if (v
.type
== FcTypeVoid
&& u
.type
== FcTypeMatrix
)
539 v
.u
.m
= &FcIdentityMatrix
;
540 v
.type
= FcTypeMatrix
;
542 else if (v
.type
== FcTypeString
&& u
.type
== FcTypeLangSet
)
544 v
.u
.l
= FcLangSetPromote (v
.u
.s
);
545 v
.type
= FcTypeLangSet
;
551 FcConfigCompareValue (const FcValue left_o
,
553 const FcValue right_o
)
555 FcValue left
= left_o
;
556 FcValue right
= right_o
;
557 FcBool ret
= FcFalse
;
559 left
= FcConfigPromote (left
, right
);
560 right
= FcConfigPromote (right
, left
);
561 if (left
.type
== right
.type
)
565 break; /* FcConfigPromote prevents this from happening */
571 ret
= left
.u
.d
== right
.u
.d
;
574 case FcOpNotContains
:
575 ret
= left
.u
.d
!= right
.u
.d
;
578 ret
= left
.u
.d
< right
.u
.d
;
581 ret
= left
.u
.d
<= right
.u
.d
;
584 ret
= left
.u
.d
> right
.u
.d
;
587 ret
= left
.u
.d
>= right
.u
.d
;
598 ret
= left
.u
.b
== right
.u
.b
;
601 case FcOpNotContains
:
602 ret
= left
.u
.b
!= right
.u
.b
;
612 ret
= FcStrCmpIgnoreCase (left
.u
.s
, right
.u
.s
) == 0;
615 ret
= FcStrStrIgnoreCase (left
.u
.s
, right
.u
.s
) != 0;
618 case FcOpNotContains
:
619 ret
= FcStrCmpIgnoreCase (left
.u
.s
, right
.u
.s
) != 0;
630 ret
= FcMatrixEqual (left
.u
.m
, right
.u
.m
);
633 case FcOpNotContains
:
634 ret
= !FcMatrixEqual (left
.u
.m
, right
.u
.m
);
644 /* left contains right if right is a subset of left */
645 ret
= FcCharSetIsSubset (right
.u
.c
, left
.u
.c
);
647 case FcOpNotContains
:
648 /* left contains right if right is a subset of left */
649 ret
= !FcCharSetIsSubset (right
.u
.c
, left
.u
.c
);
652 ret
= FcCharSetEqual (left
.u
.c
, right
.u
.c
);
655 ret
= !FcCharSetEqual (left
.u
.c
, right
.u
.c
);
665 ret
= FcLangSetContains (left
.u
.l
, right
.u
.l
);
667 case FcOpNotContains
:
668 ret
= FcLangSetContains (left
.u
.l
, right
.u
.l
);
671 ret
= FcLangSetEqual (left
.u
.l
, right
.u
.l
);
674 ret
= !FcLangSetEqual (left
.u
.l
, right
.u
.l
);
696 ret
= left
.u
.f
== right
.u
.f
;
699 case FcOpNotContains
:
700 ret
= left
.u
.f
!= right
.u
.f
;
710 if (op
== FcOpNotEqual
|| op
== FcOpNotContains
)
717 #define _FcDoubleFloor(d) ((int) (d))
718 #define _FcDoubleCeil(d) ((double) (int) (d) == (d) ? (int) (d) : (int) ((d) + 1))
719 #define FcDoubleFloor(d) ((d) >= 0 ? _FcDoubleFloor(d) : -_FcDoubleCeil(-(d)))
720 #define FcDoubleCeil(d) ((d) >= 0 ? _FcDoubleCeil(d) : -_FcDoubleFloor(-(d)))
721 #define FcDoubleRound(d) FcDoubleFloor ((d) + 0.5)
722 #define FcDoubleTrunc(d) ((d) >= 0 ? _FcDoubleFloor (d) : -_FcDoubleFloor (-(d)))
725 FcConfigEvaluate (FcPattern
*p
, FcExpr
*e
)
733 v
.type
= FcTypeInteger
;
737 v
.type
= FcTypeDouble
;
741 v
.type
= FcTypeString
;
746 v
.type
= FcTypeMatrix
;
751 v
.type
= FcTypeCharSet
;
760 r
= FcPatternGet (p
, e
->u
.field
, 0, &v
);
761 if (r
!= FcResultMatch
)
765 if (FcNameConstant (e
->u
.constant
, &v
.u
.i
))
766 v
.type
= FcTypeInteger
;
771 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
772 if (vl
.type
== FcTypeBool
)
775 v
= FcConfigEvaluate (p
, e
->u
.tree
.right
->u
.tree
.left
);
777 v
= FcConfigEvaluate (p
, e
->u
.tree
.right
->u
.tree
.right
);
790 case FcOpNotContains
:
792 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
793 vr
= FcConfigEvaluate (p
, e
->u
.tree
.right
);
795 v
.u
.b
= FcConfigCompareValue (vl
, e
->op
, vr
);
805 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
806 vr
= FcConfigEvaluate (p
, e
->u
.tree
.right
);
807 vl
= FcConfigPromote (vl
, vr
);
808 vr
= FcConfigPromote (vr
, vl
);
809 if (vl
.type
== vr
.type
)
815 v
.type
= FcTypeDouble
;
816 v
.u
.d
= vl
.u
.d
+ vr
.u
.d
;
819 v
.type
= FcTypeDouble
;
820 v
.u
.d
= vl
.u
.d
- vr
.u
.d
;
823 v
.type
= FcTypeDouble
;
824 v
.u
.d
= vl
.u
.d
* vr
.u
.d
;
827 v
.type
= FcTypeDouble
;
828 v
.u
.d
= vl
.u
.d
/ vr
.u
.d
;
834 if (v
.type
== FcTypeDouble
&&
835 v
.u
.d
== (double) (int) v
.u
.d
)
837 v
.type
= FcTypeInteger
;
845 v
.u
.b
= vl
.u
.b
|| vr
.u
.b
;
849 v
.u
.b
= vl
.u
.b
&& vr
.u
.b
;
859 v
.type
= FcTypeString
;
860 v
.u
.s
= FcStrPlus (vl
.u
.s
, vr
.u
.s
);
872 v
.type
= FcTypeMatrix
;
873 m
= malloc (sizeof (FcMatrix
));
876 FcMemAlloc (FC_MEM_MATRIX
, sizeof (FcMatrix
));
877 FcMatrixMultiply (m
, vl
.u
.m
, vr
.u
.m
);
901 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
914 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
920 v
.type
= FcTypeInteger
;
921 v
.u
.i
= FcDoubleFloor (vl
.u
.d
);
930 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
936 v
.type
= FcTypeInteger
;
937 v
.u
.i
= FcDoubleCeil (vl
.u
.d
);
946 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
952 v
.type
= FcTypeInteger
;
953 v
.u
.i
= FcDoubleRound (vl
.u
.d
);
962 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
968 v
.type
= FcTypeInteger
;
969 v
.u
.i
= FcDoubleTrunc (vl
.u
.d
);
985 FcConfigMatchValueList (FcPattern
*p
,
989 FcValueList
*ret
= 0;
996 /* Compute the value of the match expression */
997 if (e
->op
== FcOpComma
)
999 value
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
1000 e
= e
->u
.tree
.right
;
1004 value
= FcConfigEvaluate (p
, e
);
1008 for (v
= values
; v
; v
= v
->next
)
1010 /* Compare the pattern value to the match expression value */
1011 if (FcConfigCompareValue (v
->value
, t
->op
, value
))
1018 if (t
->qual
== FcQualAll
)
1025 FcValueDestroy (value
);
1030 static FcValueList
*
1031 FcConfigValues (FcPattern
*p
, FcExpr
*e
, FcValueBinding binding
)
1037 l
= (FcValueList
*) malloc (sizeof (FcValueList
));
1040 FcMemAlloc (FC_MEM_VALLIST
, sizeof (FcValueList
));
1041 if (e
->op
== FcOpComma
)
1043 l
->value
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
1044 l
->next
= FcConfigValues (p
, e
->u
.tree
.right
, binding
);
1048 l
->value
= FcConfigEvaluate (p
, e
);
1051 l
->binding
= binding
;
1052 while (l
&& l
->value
.type
== FcTypeVoid
)
1054 FcValueList
*next
= l
->next
;
1056 FcMemFree (FC_MEM_VALLIST
, sizeof (FcValueList
));
1064 FcConfigAdd (FcValueList
**head
,
1065 FcValueList
*position
,
1069 FcValueList
**prev
, *last
, *v
;
1070 FcValueBinding sameBinding
;
1073 sameBinding
= position
->binding
;
1075 sameBinding
= FcValueBindingWeak
;
1076 for (v
= new; v
; v
= v
->next
)
1077 if (v
->binding
== FcValueBindingSame
)
1078 v
->binding
= sameBinding
;
1082 prev
= &position
->next
;
1084 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1091 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1093 if (*prev
== position
)
1100 if (FcDebug () & FC_DBG_EDIT
)
1103 printf ("position not on list\n");
1107 if (FcDebug () & FC_DBG_EDIT
)
1109 printf ("%s list before ", append
? "Append" : "Prepend");
1110 FcValueListPrint (*head
);
1124 if (FcDebug () & FC_DBG_EDIT
)
1126 printf ("%s list after ", append
? "Append" : "Prepend");
1127 FcValueListPrint (*head
);
1135 FcConfigDel (FcValueList
**head
,
1136 FcValueList
*position
)
1140 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1142 if (*prev
== position
)
1144 *prev
= position
->next
;
1146 FcValueListDestroy (position
);
1153 FcConfigPatternAdd (FcPattern
*p
,
1160 FcPatternElt
*e
= FcPatternInsertElt (p
, object
);
1164 FcConfigAdd (&e
->values
, 0, append
, list
);
1169 * Delete all values associated with a field
1172 FcConfigPatternDel (FcPattern
*p
,
1175 FcPatternElt
*e
= FcPatternFindElt (p
, object
);
1179 FcConfigDel (&e
->values
, e
->values
);
1183 FcConfigPatternCanon (FcPattern
*p
,
1186 FcPatternElt
*e
= FcPatternFindElt (p
, object
);
1190 FcPatternDel (p
, object
);
1194 FcConfigSubstituteWithPat (FcConfig
*config
,
1209 config
= FcConfigGetCurrent ();
1214 st
= (FcSubState
*) malloc (config
->maxObjects
* sizeof (FcSubState
));
1215 if (!st
&& config
->maxObjects
)
1217 FcMemAlloc (FC_MEM_SUBSTATE
, config
->maxObjects
* sizeof (FcSubState
));
1219 if (FcDebug () & FC_DBG_EDIT
)
1221 printf ("FcConfigSubstitute ");
1224 if (kind
== FcMatchPattern
)
1225 s
= config
->substPattern
;
1227 s
= config
->substFont
;
1228 for (; s
; s
= s
->next
)
1231 * Check the tests to see if
1232 * they all match the pattern
1234 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1236 if (FcDebug () & FC_DBG_EDIT
)
1238 printf ("FcConfigSubstitute test ");
1242 if (kind
== FcMatchFont
&& t
->kind
== FcMatchPattern
)
1247 st
[i
].elt
= FcPatternFindElt (m
, t
->field
);
1251 * If there's no such field in the font,
1252 * then FcQualAll matches while FcQualAny does not
1256 if (t
->qual
== FcQualAll
)
1265 * Check to see if there is a match, mark the location
1266 * to apply match-relative edits
1268 st
[i
].value
= FcConfigMatchValueList (m
, t
, st
[i
].elt
->values
);
1271 if (t
->qual
== FcQualFirst
&& st
[i
].value
!= st
[i
].elt
->values
)
1273 if (t
->qual
== FcQualNotFirst
&& st
[i
].value
== st
[i
].elt
->values
)
1278 if (FcDebug () & FC_DBG_EDIT
)
1279 printf ("No match\n");
1282 if (FcDebug () & FC_DBG_EDIT
)
1284 printf ("Substitute ");
1287 for (e
= s
->edit
; e
; e
= e
->next
)
1290 * Evaluate the list of expressions
1292 l
= FcConfigValues (p
, e
->expr
, e
->binding
);
1294 * Locate any test associated with this field, skipping
1295 * tests associated with the pattern when substituting in
1298 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1300 if ((t
->kind
== FcMatchFont
|| kind
== FcMatchPattern
) &&
1301 !FcStrCmpIgnoreCase ((FcChar8
*) t
->field
,
1302 (FcChar8
*) e
->field
))
1305 * KLUDGE - the pattern may have been reallocated or
1306 * things may have been inserted or deleted above
1307 * this element by other edits. Go back and find
1310 if (e
!= s
->edit
&& st
[i
].elt
)
1311 st
[i
].elt
= FcPatternFindElt (p
, t
->field
);
1320 * If there was a test, then replace the matched
1321 * value with the new list of values
1325 FcValueList
*thisValue
= st
[i
].value
;
1326 FcValueList
*nextValue
= thisValue
? thisValue
->next
: 0;
1329 * Append the new list of values after the current value
1331 FcConfigAdd (&st
[i
].elt
->values
, thisValue
, FcTrue
, l
);
1333 * Delete the marked value
1335 FcConfigDel (&st
[i
].elt
->values
, thisValue
);
1337 * Adjust any pointers into the value list to ensure
1338 * future edits occur at the same place
1340 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1342 if (st
[i
].value
== thisValue
)
1343 st
[i
].value
= nextValue
;
1347 /* fall through ... */
1348 case FcOpAssignReplace
:
1350 * Delete all of the values and insert
1353 FcConfigPatternDel (p
, e
->field
);
1354 FcConfigPatternAdd (p
, e
->field
, l
, FcTrue
);
1356 * Adjust any pointers into the value list as they no
1357 * longer point to anything valid
1361 FcPatternElt
*thisElt
= st
[i
].elt
;
1362 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1364 if (st
[i
].elt
== thisElt
)
1372 FcConfigAdd (&st
[i
].elt
->values
, st
[i
].value
, FcFalse
, l
);
1375 /* fall through ... */
1376 case FcOpPrependFirst
:
1377 FcConfigPatternAdd (p
, e
->field
, l
, FcFalse
);
1382 FcConfigAdd (&st
[i
].elt
->values
, st
[i
].value
, FcTrue
, l
);
1385 /* fall through ... */
1386 case FcOpAppendLast
:
1387 FcConfigPatternAdd (p
, e
->field
, l
, FcTrue
);
1394 * Now go through the pattern and eliminate
1395 * any properties without data
1397 for (e
= s
->edit
; e
; e
= e
->next
)
1398 FcConfigPatternCanon (p
, e
->field
);
1400 if (FcDebug () & FC_DBG_EDIT
)
1402 printf ("FcConfigSubstitute edit");
1406 FcMemFree (FC_MEM_SUBSTATE
, config
->maxObjects
* sizeof (FcSubState
));
1408 if (FcDebug () & FC_DBG_EDIT
)
1410 printf ("FcConfigSubstitute done");
1417 FcConfigSubstitute (FcConfig
*config
,
1421 return FcConfigSubstituteWithPat (config
, p
, 0, kind
);
1424 #if defined (_WIN32) && (defined (PIC) || defined (DLL_EXPORT))
1426 static FcChar8 fontconfig_path
[1000] = "";
1429 DllMain (HINSTANCE hinstDLL
,
1435 switch (fdwReason
) {
1436 case DLL_PROCESS_ATTACH
:
1437 if (!GetModuleFileName ((HMODULE
) hinstDLL
, fontconfig_path
,
1438 sizeof (fontconfig_path
)))
1441 /* If the fontconfig DLL is in a "bin" or "lib" subfolder,
1442 * assume it's a Unix-style installation tree, and use
1443 * "etc/fonts" in there as FONTCONFIG_PATH. Otherwise use the
1444 * folder where the DLL is as FONTCONFIG_PATH.
1446 p
= strrchr (fontconfig_path
, '\\');
1450 p
= strrchr (fontconfig_path
, '\\');
1451 if (p
&& (FcStrCmpIgnoreCase (p
+ 1, "bin") == 0 ||
1452 FcStrCmpIgnoreCase (p
+ 1, "lib") == 0))
1454 strcat (fontconfig_path
, "\\etc\\fonts");
1457 fontconfig_path
[0] = '\0';
1465 #undef FONTCONFIG_PATH
1466 #define FONTCONFIG_PATH fontconfig_path
1468 #else /* !(_WIN32 && PIC) */
1470 #endif /* !(_WIN32 && PIC) */
1472 #ifndef FONTCONFIG_FILE
1473 #define FONTCONFIG_FILE "fonts.conf"
1477 FcConfigFileExists (const FcChar8
*dir
, const FcChar8
*file
)
1482 dir
= (FcChar8
*) "";
1483 path
= malloc (strlen ((char *) dir
) + 1 + strlen ((char *) file
) + 1);
1487 strcpy ((char *) path
, (const char *) dir
);
1488 /* make sure there's a single separator */
1490 if ((!path
[0] || (path
[strlen((char *) path
)-1] != '/' &&
1491 path
[strlen((char *) path
)-1] != '\\')) &&
1492 (file
[0] != '/' && file
[0] != '\\'))
1493 strcat ((char *) path
, "\\");
1495 if ((!path
[0] || path
[strlen((char *) path
)-1] != '/') && file
[0] != '/')
1496 strcat ((char *) path
, "/");
1498 strcat ((char *) path
, (char *) file
);
1500 FcMemAlloc (FC_MEM_STRING
, strlen ((char *) path
) + 1);
1501 if (access ((char *) path
, R_OK
) == 0)
1509 FcConfigGetPath (void)
1512 FcChar8
*env
, *e
, *colon
;
1517 npath
= 2; /* default dir + null */
1518 env
= (FcChar8
*) getenv ("FONTCONFIG_PATH");
1524 if (*e
++ == FC_SEARCH_PATH_SEPARATOR
)
1527 path
= calloc (npath
, sizeof (FcChar8
*));
1537 colon
= (FcChar8
*) strchr ((char *) e
, FC_SEARCH_PATH_SEPARATOR
);
1539 colon
= e
+ strlen ((char *) e
);
1540 path
[i
] = malloc (colon
- e
+ 1);
1543 strncpy ((char *) path
[i
], (const char *) e
, colon
- e
);
1544 path
[i
][colon
- e
] = '\0';
1553 dir
= (FcChar8
*) FONTCONFIG_PATH
;
1554 path
[i
] = malloc (strlen ((char *) dir
) + 1);
1557 strcpy ((char *) path
[i
], (const char *) dir
);
1561 for (i
= 0; path
[i
]; i
++)
1569 FcConfigFreePath (FcChar8
**path
)
1573 for (p
= path
; *p
; p
++)
1578 static FcBool _FcConfigHomeEnabled
= FcTrue
;
1583 if (_FcConfigHomeEnabled
)
1585 char *home
= getenv ("HOME");
1589 home
= getenv ("USERPROFILE");
1598 FcConfigEnableHome (FcBool enable
)
1600 FcBool prev
= _FcConfigHomeEnabled
;
1601 _FcConfigHomeEnabled
= enable
;
1606 FcConfigFilename (const FcChar8
*url
)
1608 FcChar8
*file
, *dir
, **path
, **p
;
1612 url
= (FcChar8
*) getenv ("FONTCONFIG_FILE");
1614 url
= (FcChar8
*) FONTCONFIG_FILE
;
1619 if (isalpha (*url
) &&
1621 (url
[2] == '/' || url
[2] == '\\'))
1627 dir
= FcConfigHome ();
1629 file
= FcConfigFileExists (dir
, url
+ 1);
1638 file
= FcConfigFileExists (0, url
);
1641 path
= FcConfigGetPath ();
1644 for (p
= path
; *p
; p
++)
1646 file
= FcConfigFileExists (*p
, url
);
1650 FcConfigFreePath (path
);
1657 * Manage the application-specific fonts
1661 FcConfigAppFontAddFile (FcConfig
*config
,
1662 const FcChar8
*file
)
1671 config
= FcConfigGetCurrent ();
1676 subdirs
= FcStrSetCreate ();
1680 set
= FcConfigGetFonts (config
, FcSetApplication
);
1683 set
= FcFontSetCreate ();
1686 FcStrSetDestroy (subdirs
);
1689 FcConfigSetFonts (config
, set
, FcSetApplication
);
1692 if (!FcFileScanConfig (set
, subdirs
, 0, config
->blanks
, file
, FcFalse
, config
))
1694 FcStrSetDestroy (subdirs
);
1697 if ((sublist
= FcStrListCreate (subdirs
)))
1699 while ((subdir
= FcStrListNext (sublist
)))
1701 FcConfigAppFontAddDir (config
, subdir
);
1703 FcStrListDone (sublist
);
1709 FcConfigAppFontAddDir (FcConfig
*config
,
1719 config
= FcConfigGetCurrent ();
1723 subdirs
= FcStrSetCreate ();
1727 set
= FcConfigGetFonts (config
, FcSetApplication
);
1730 set
= FcFontSetCreate ();
1733 FcStrSetDestroy (subdirs
);
1736 FcConfigSetFonts (config
, set
, FcSetApplication
);
1739 if (!FcDirScanConfig (set
, subdirs
, 0, config
->blanks
, dir
, FcFalse
, config
))
1741 FcStrSetDestroy (subdirs
);
1744 if ((sublist
= FcStrListCreate (subdirs
)))
1746 while ((subdir
= FcStrListNext (sublist
)))
1748 FcConfigAppFontAddDir (config
, subdir
);
1750 FcStrListDone (sublist
);
1756 FcConfigAppFontClear (FcConfig
*config
)
1760 config
= FcConfigGetCurrent ();
1765 FcConfigSetFonts (config
, 0, FcSetApplication
);
1769 * Manage filename-based font source selectors
1773 FcConfigGlobAdd (FcConfig
*config
,
1774 const FcChar8
*glob
,
1777 FcStrSet
*set
= accept
? config
->acceptGlobs
: config
->rejectGlobs
;
1779 return FcStrSetAdd (set
, glob
);
1783 FcConfigGlobMatch (const FcChar8
*glob
,
1784 const FcChar8
*string
)
1788 while ((c
= *glob
++))
1792 /* short circuit common case */
1795 /* short circuit another common case */
1796 if (strchr ((char *) glob
, '*') == 0)
1797 string
+= strlen ((char *) string
) - strlen ((char *) glob
);
1800 if (FcConfigGlobMatch (glob
, string
))
1806 if (*string
++ == '\0')
1815 return *string
== '\0';
1819 FcConfigGlobsMatch (const FcStrSet
*globs
,
1820 const FcChar8
*string
)
1824 for (i
= 0; i
< globs
->num
; i
++)
1825 if (FcConfigGlobMatch (globs
->strs
[i
], string
))
1831 FcConfigAcceptFilename (FcConfig
*config
,
1832 const FcChar8
*filename
)
1834 if (FcConfigGlobsMatch (config
->acceptGlobs
, filename
))
1836 if (FcConfigGlobsMatch (config
->rejectGlobs
, filename
))