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 #include <sys/types.h>
29 #if defined (_WIN32) && (defined (PIC) || defined (DLL_EXPORT))
35 #if defined (_WIN32) && !defined (R_OK)
47 config
= malloc (sizeof (FcConfig
));
50 FcMemAlloc (FC_MEM_CONFIG
, sizeof (FcConfig
));
52 config
->configDirs
= FcStrSetCreate ();
53 if (!config
->configDirs
)
56 config
->configFiles
= FcStrSetCreate ();
57 if (!config
->configFiles
)
60 config
->fontDirs
= FcStrSetCreate ();
61 if (!config
->fontDirs
)
64 config
->acceptGlobs
= FcStrSetCreate ();
65 if (!config
->acceptGlobs
)
68 config
->rejectGlobs
= FcStrSetCreate ();
69 if (!config
->rejectGlobs
)
72 config
->acceptPatterns
= FcFontSetCreate ();
73 if (!config
->acceptPatterns
)
76 config
->rejectPatterns
= FcFontSetCreate ();
77 if (!config
->rejectPatterns
)
80 config
->cacheDirs
= FcStrSetCreate ();
81 if (!config
->cacheDirs
)
86 config
->substPattern
= 0;
87 config
->substFont
= 0;
88 config
->substScan
= 0;
89 config
->maxObjects
= 0;
90 for (set
= FcSetSystem
; set
<= FcSetApplication
; set
++)
91 config
->fonts
[set
] = 0;
93 config
->rescanTime
= time(0);
94 config
->rescanInterval
= 30;
99 FcFontSetDestroy (config
->rejectPatterns
);
101 FcFontSetDestroy (config
->acceptPatterns
);
103 FcStrSetDestroy (config
->rejectGlobs
);
105 FcStrSetDestroy (config
->acceptGlobs
);
107 FcStrSetDestroy (config
->fontDirs
);
109 FcStrSetDestroy (config
->configFiles
);
111 FcStrSetDestroy (config
->configDirs
);
114 FcMemFree (FC_MEM_CONFIG
, sizeof (FcConfig
));
120 FcConfigNewestFile (FcStrSet
*files
)
122 FcStrList
*list
= FcStrListCreate (files
);
123 FcFileTime newest
= { 0, FcFalse
};
129 while ((file
= FcStrListNext (list
)))
130 if (stat ((char *) file
, &statb
) == 0)
131 if (!newest
.set
|| statb
.st_mtime
- newest
.time
> 0)
134 newest
.time
= statb
.st_mtime
;
136 FcStrListDone (list
);
142 FcConfigUptoDate (FcConfig
*config
)
144 FcFileTime config_time
, config_dir_time
, font_time
;
145 time_t now
= time(0);
148 config
= FcConfigGetCurrent ();
152 config_time
= FcConfigNewestFile (config
->configFiles
);
153 config_dir_time
= FcConfigNewestFile (config
->configDirs
);
154 font_time
= FcConfigNewestFile (config
->fontDirs
);
155 if ((config_time
.set
&& config_time
.time
- config
->rescanTime
> 0) ||
156 (config_dir_time
.set
&& (config_dir_time
.time
- config
->rescanTime
) > 0) ||
157 (font_time
.set
&& (font_time
.time
- config
->rescanTime
) > 0))
161 config
->rescanTime
= now
;
166 FcSubstDestroy (FcSubst
*s
)
174 FcTestDestroy (s
->test
);
176 FcEditDestroy (s
->edit
);
178 FcMemFree (FC_MEM_SUBST
, sizeof (FcSubst
));
184 FcConfigDestroy (FcConfig
*config
)
188 if (config
== _fcConfig
)
191 FcStrSetDestroy (config
->configDirs
);
192 FcStrSetDestroy (config
->fontDirs
);
193 FcStrSetDestroy (config
->cacheDirs
);
194 FcStrSetDestroy (config
->configFiles
);
195 FcStrSetDestroy (config
->acceptGlobs
);
196 FcStrSetDestroy (config
->rejectGlobs
);
197 FcFontSetDestroy (config
->acceptPatterns
);
198 FcFontSetDestroy (config
->rejectPatterns
);
201 FcBlanksDestroy (config
->blanks
);
203 FcSubstDestroy (config
->substPattern
);
204 FcSubstDestroy (config
->substFont
);
205 FcSubstDestroy (config
->substScan
);
206 for (set
= FcSetSystem
; set
<= FcSetApplication
; set
++)
207 if (config
->fonts
[set
])
208 FcFontSetDestroy (config
->fonts
[set
]);
211 FcMemFree (FC_MEM_CONFIG
, sizeof (FcConfig
));
215 * Add cache to configuration, adding fonts and directories
219 FcConfigAddCache (FcConfig
*config
, FcCache
*cache
,
220 FcSetName set
, FcStrSet
*dirSet
)
229 fs
= FcCacheSet (cache
);
234 for (i
= 0; i
< fs
->nfont
; i
++)
236 FcPattern
*font
= FcFontSetFont (fs
, i
);
240 * Check to see if font is banned by filename
242 if (FcPatternObjectGetString (font
, FC_FILE_OBJECT
,
243 0, &font_file
) == FcResultMatch
&&
244 !FcConfigAcceptFilename (config
, font_file
))
250 * Check to see if font is banned by pattern
252 if (!FcConfigAcceptFont (config
, font
))
256 FcFontSetAdd (config
->fonts
[set
], font
);
258 FcDirCacheReference (cache
, nref
);
264 dirs
= FcCacheDirs (cache
);
267 for (i
= 0; i
< cache
->dirs_count
; i
++)
269 FcChar8
*dir
= FcOffsetToPtr (dirs
, dirs
[i
], FcChar8
);
270 if (FcConfigAcceptFilename (config
, dir
))
271 FcStrSetAddFilename (dirSet
, dir
);
278 FcConfigAddDirList (FcConfig
*config
, FcSetName set
, FcStrSet
*dirSet
)
284 dirlist
= FcStrListCreate (dirSet
);
288 while ((dir
= FcStrListNext (dirlist
)))
290 if (FcDebug () & FC_DBG_FONTSET
)
291 printf ("adding fonts from%s\n", dir
);
292 cache
= FcDirCacheRead (dir
, FcFalse
, config
);
295 FcConfigAddCache (config
, cache
, set
, dirSet
);
296 FcDirCacheUnload (cache
);
298 FcStrListDone (dirlist
);
303 * Scan the current list of directories in the configuration
304 * and build the set of available fonts.
308 FcConfigBuildFonts (FcConfig
*config
)
314 config
= FcConfigGetCurrent ();
319 fonts
= FcFontSetCreate ();
323 FcConfigSetFonts (config
, fonts
, FcSetSystem
);
325 if (!FcConfigAddDirList (config
, FcSetSystem
, config
->fontDirs
))
327 if (FcDebug () & FC_DBG_FONTSET
)
328 FcFontSetPrint (fonts
);
333 FcConfigSetCurrent (FcConfig
*config
)
336 if (!FcConfigBuildFonts (config
))
340 FcConfigDestroy (_fcConfig
);
346 FcConfigGetCurrent (void)
355 FcConfigAddConfigDir (FcConfig
*config
,
358 return FcStrSetAddFilename (config
->configDirs
, d
);
362 FcConfigGetConfigDirs (FcConfig
*config
)
366 config
= FcConfigGetCurrent ();
370 return FcStrListCreate (config
->configDirs
);
374 FcConfigAddFontDir (FcConfig
*config
,
377 return FcStrSetAddFilename (config
->fontDirs
, d
);
381 FcConfigAddDir (FcConfig
*config
,
384 return (FcConfigAddConfigDir (config
, d
) &&
385 FcConfigAddFontDir (config
, d
));
389 FcConfigGetFontDirs (FcConfig
*config
)
393 config
= FcConfigGetCurrent ();
397 return FcStrListCreate (config
->fontDirs
);
401 FcConfigAddCacheDir (FcConfig
*config
,
404 return FcStrSetAddFilename (config
->cacheDirs
, d
);
408 FcConfigGetCacheDirs (FcConfig
*config
)
412 config
= FcConfigGetCurrent ();
416 return FcStrListCreate (config
->cacheDirs
);
420 FcConfigAddConfigFile (FcConfig
*config
,
424 FcChar8
*file
= FcConfigFilename (f
);
429 ret
= FcStrSetAdd (config
->configFiles
, file
);
435 FcConfigGetConfigFiles (FcConfig
*config
)
439 config
= FcConfigGetCurrent ();
443 return FcStrListCreate (config
->configFiles
);
447 FcConfigGetCache (FcConfig
*config
)
453 FcConfigGetFonts (FcConfig
*config
,
458 config
= FcConfigGetCurrent ();
462 return config
->fonts
[set
];
466 FcConfigSetFonts (FcConfig
*config
,
470 if (config
->fonts
[set
])
471 FcFontSetDestroy (config
->fonts
[set
]);
472 config
->fonts
[set
] = fonts
;
476 FcConfigGetBlanks (FcConfig
*config
)
480 config
= FcConfigGetCurrent ();
484 return config
->blanks
;
488 FcConfigAddBlank (FcConfig
*config
,
491 FcBlanks
*b
, *freeme
= 0;
496 freeme
= b
= FcBlanksCreate ();
500 if (!FcBlanksAdd (b
, blank
))
503 FcBlanksDestroy (freeme
);
511 FcConfigGetRescanInverval (FcConfig
*config
)
515 config
= FcConfigGetCurrent ();
519 return config
->rescanInterval
;
523 FcConfigSetRescanInverval (FcConfig
*config
, int rescanInterval
)
527 config
= FcConfigGetCurrent ();
531 config
->rescanInterval
= rescanInterval
;
536 FcConfigAddEdit (FcConfig
*config
,
541 FcSubst
*subst
, **prev
;
547 prev
= &config
->substPattern
;
550 prev
= &config
->substFont
;
553 prev
= &config
->substScan
;
558 subst
= (FcSubst
*) malloc (sizeof (FcSubst
));
561 FcMemAlloc (FC_MEM_SUBST
, sizeof (FcSubst
));
562 for (; *prev
; prev
= &(*prev
)->next
);
568 for (t
= test
; t
; t
= t
->next
)
570 if (t
->kind
== FcMatchDefault
)
574 if (config
->maxObjects
< num
)
575 config
->maxObjects
= num
;
576 if (FcDebug () & FC_DBG_EDIT
)
578 printf ("Add Subst ");
579 FcSubstPrint (subst
);
584 typedef struct _FcSubState
{
590 FcConfigPromote (FcValue v
, FcValue u
)
592 if (v
.type
== FcTypeInteger
)
594 v
.type
= FcTypeDouble
;
595 v
.u
.d
= (double) v
.u
.i
;
597 else if (v
.type
== FcTypeVoid
&& u
.type
== FcTypeMatrix
)
599 v
.u
.m
= &FcIdentityMatrix
;
600 v
.type
= FcTypeMatrix
;
602 else if (v
.type
== FcTypeString
&& u
.type
== FcTypeLangSet
)
604 v
.u
.l
= FcLangSetPromote (v
.u
.s
);
605 v
.type
= FcTypeLangSet
;
611 FcConfigCompareValue (const FcValue
*left_o
,
613 const FcValue
*right_o
)
615 FcValue left
= FcValueCanonicalize(left_o
);
616 FcValue right
= FcValueCanonicalize(right_o
);
617 FcBool ret
= FcFalse
;
619 left
= FcConfigPromote (left
, right
);
620 right
= FcConfigPromote (right
, left
);
621 if (left
.type
== right
.type
)
625 break; /* FcConfigPromote prevents this from happening */
631 ret
= left
.u
.d
== right
.u
.d
;
634 case FcOpNotContains
:
635 ret
= left
.u
.d
!= right
.u
.d
;
638 ret
= left
.u
.d
< right
.u
.d
;
641 ret
= left
.u
.d
<= right
.u
.d
;
644 ret
= left
.u
.d
> right
.u
.d
;
647 ret
= left
.u
.d
>= right
.u
.d
;
658 ret
= left
.u
.b
== right
.u
.b
;
661 case FcOpNotContains
:
662 ret
= left
.u
.b
!= right
.u
.b
;
672 ret
= FcStrCmpIgnoreCase (left
.u
.s
, right
.u
.s
) == 0;
675 ret
= FcStrStrIgnoreCase (left
.u
.s
, right
.u
.s
) != 0;
678 ret
= FcStrCmpIgnoreCase (left
.u
.s
, right
.u
.s
) != 0;
680 case FcOpNotContains
:
681 ret
= FcStrCmpIgnoreCase (left
.u
.s
, right
.u
.s
) == 0;
692 ret
= FcMatrixEqual (left
.u
.m
, right
.u
.m
);
695 case FcOpNotContains
:
696 ret
= !FcMatrixEqual (left
.u
.m
, right
.u
.m
);
706 /* left contains right if right is a subset of left */
707 ret
= FcCharSetIsSubset (right
.u
.c
, left
.u
.c
);
709 case FcOpNotContains
:
710 /* left contains right if right is a subset of left */
711 ret
= !FcCharSetIsSubset (right
.u
.c
, left
.u
.c
);
714 ret
= FcCharSetEqual (left
.u
.c
, right
.u
.c
);
717 ret
= !FcCharSetEqual (left
.u
.c
, right
.u
.c
);
727 ret
= FcLangSetContains (left
.u
.l
, right
.u
.l
);
729 case FcOpNotContains
:
730 ret
= !FcLangSetContains (left
.u
.l
, right
.u
.l
);
733 ret
= FcLangSetEqual (left
.u
.l
, right
.u
.l
);
736 ret
= !FcLangSetEqual (left
.u
.l
, right
.u
.l
);
758 ret
= left
.u
.f
== right
.u
.f
;
761 case FcOpNotContains
:
762 ret
= left
.u
.f
!= right
.u
.f
;
772 if (op
== FcOpNotEqual
|| op
== FcOpNotContains
)
779 #define _FcDoubleFloor(d) ((int) (d))
780 #define _FcDoubleCeil(d) ((double) (int) (d) == (d) ? (int) (d) : (int) ((d) + 1))
781 #define FcDoubleFloor(d) ((d) >= 0 ? _FcDoubleFloor(d) : -_FcDoubleCeil(-(d)))
782 #define FcDoubleCeil(d) ((d) >= 0 ? _FcDoubleCeil(d) : -_FcDoubleFloor(-(d)))
783 #define FcDoubleRound(d) FcDoubleFloor ((d) + 0.5)
784 #define FcDoubleTrunc(d) ((d) >= 0 ? _FcDoubleFloor (d) : -_FcDoubleFloor (-(d)))
787 FcConfigEvaluate (FcPattern
*p
, FcExpr
*e
)
796 v
.type
= FcTypeInteger
;
800 v
.type
= FcTypeDouble
;
804 v
.type
= FcTypeString
;
805 v
.u
.s
= FcStrStaticName(e
->u
.sval
);
808 v
.type
= FcTypeMatrix
;
813 v
.type
= FcTypeCharSet
;
822 r
= FcPatternObjectGet (p
, e
->u
.object
, 0, &v
);
823 if (r
!= FcResultMatch
)
828 if (FcNameConstant (e
->u
.constant
, &v
.u
.i
))
829 v
.type
= FcTypeInteger
;
834 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
835 if (vl
.type
== FcTypeBool
)
838 v
= FcConfigEvaluate (p
, e
->u
.tree
.right
->u
.tree
.left
);
840 v
= FcConfigEvaluate (p
, e
->u
.tree
.right
->u
.tree
.right
);
853 case FcOpNotContains
:
855 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
856 vr
= FcConfigEvaluate (p
, e
->u
.tree
.right
);
858 v
.u
.b
= FcConfigCompareValue (&vl
, e
->op
, &vr
);
868 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
869 vr
= FcConfigEvaluate (p
, e
->u
.tree
.right
);
870 vl
= FcConfigPromote (vl
, vr
);
871 vr
= FcConfigPromote (vr
, vl
);
872 if (vl
.type
== vr
.type
)
878 v
.type
= FcTypeDouble
;
879 v
.u
.d
= vl
.u
.d
+ vr
.u
.d
;
882 v
.type
= FcTypeDouble
;
883 v
.u
.d
= vl
.u
.d
- vr
.u
.d
;
886 v
.type
= FcTypeDouble
;
887 v
.u
.d
= vl
.u
.d
* vr
.u
.d
;
890 v
.type
= FcTypeDouble
;
891 v
.u
.d
= vl
.u
.d
/ vr
.u
.d
;
897 if (v
.type
== FcTypeDouble
&&
898 v
.u
.d
== (double) (int) v
.u
.d
)
900 v
.type
= FcTypeInteger
;
908 v
.u
.b
= vl
.u
.b
|| vr
.u
.b
;
912 v
.u
.b
= vl
.u
.b
&& vr
.u
.b
;
922 v
.type
= FcTypeString
;
923 str
= FcStrPlus (vl
.u
.s
, vr
.u
.s
);
924 v
.u
.s
= FcStrStaticName (str
);
938 v
.type
= FcTypeMatrix
;
939 m
= malloc (sizeof (FcMatrix
));
942 FcMemAlloc (FC_MEM_MATRIX
, sizeof (FcMatrix
));
943 FcMatrixMultiply (m
, vl
.u
.m
, vr
.u
.m
);
967 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
980 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
986 v
.type
= FcTypeInteger
;
987 v
.u
.i
= FcDoubleFloor (vl
.u
.d
);
996 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
1002 v
.type
= FcTypeInteger
;
1003 v
.u
.i
= FcDoubleCeil (vl
.u
.d
);
1006 v
.type
= FcTypeVoid
;
1009 FcValueDestroy (vl
);
1012 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
1018 v
.type
= FcTypeInteger
;
1019 v
.u
.i
= FcDoubleRound (vl
.u
.d
);
1022 v
.type
= FcTypeVoid
;
1025 FcValueDestroy (vl
);
1028 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
1034 v
.type
= FcTypeInteger
;
1035 v
.u
.i
= FcDoubleTrunc (vl
.u
.d
);
1038 v
.type
= FcTypeVoid
;
1041 FcValueDestroy (vl
);
1044 v
.type
= FcTypeVoid
;
1050 static FcValueList
*
1051 FcConfigMatchValueList (FcPattern
*p
,
1053 FcValueList
*values
)
1055 FcValueList
*ret
= 0;
1056 FcExpr
*e
= t
->expr
;
1062 /* Compute the value of the match expression */
1063 if (e
->op
== FcOpComma
)
1065 value
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
1066 e
= e
->u
.tree
.right
;
1070 value
= FcConfigEvaluate (p
, e
);
1074 for (v
= values
; v
; v
= FcValueListNext(v
))
1076 /* Compare the pattern value to the match expression value */
1077 if (FcConfigCompareValue (&v
->value
, t
->op
, &value
))
1084 if (t
->qual
== FcQualAll
)
1091 FcValueDestroy (value
);
1096 static FcValueList
*
1097 FcConfigValues (FcPattern
*p
, FcExpr
*e
, FcValueBinding binding
)
1103 l
= (FcValueList
*) malloc (sizeof (FcValueList
));
1106 FcMemAlloc (FC_MEM_VALLIST
, sizeof (FcValueList
));
1107 if (e
->op
== FcOpComma
)
1109 l
->value
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
1110 l
->next
= FcConfigValues (p
, e
->u
.tree
.right
, binding
);
1114 l
->value
= FcConfigEvaluate (p
, e
);
1117 l
->binding
= binding
;
1118 if (l
->value
.type
== FcTypeVoid
)
1120 FcValueList
*next
= FcValueListNext(l
);
1122 FcMemFree (FC_MEM_VALLIST
, sizeof (FcValueList
));
1131 FcConfigAdd (FcValueListPtr
*head
,
1132 FcValueList
*position
,
1136 FcValueListPtr
*prev
, last
, v
;
1137 FcValueBinding sameBinding
;
1140 sameBinding
= position
->binding
;
1142 sameBinding
= FcValueBindingWeak
;
1143 for (v
= new; v
!= NULL
; v
= FcValueListNext(v
))
1144 if (v
->binding
== FcValueBindingSame
)
1145 v
->binding
= sameBinding
;
1149 prev
= &position
->next
;
1151 for (prev
= head
; *prev
!= NULL
;
1152 prev
= &(*prev
)->next
)
1159 for (prev
= head
; *prev
!= NULL
;
1160 prev
= &(*prev
)->next
)
1162 if (*prev
== position
)
1169 if (FcDebug () & FC_DBG_EDIT
)
1172 printf ("position not on list\n");
1176 if (FcDebug () & FC_DBG_EDIT
)
1178 printf ("%s list before ", append
? "Append" : "Prepend");
1179 FcValueListPrint (*head
);
1186 while (last
->next
!= NULL
)
1193 if (FcDebug () & FC_DBG_EDIT
)
1195 printf ("%s list after ", append
? "Append" : "Prepend");
1196 FcValueListPrint (*head
);
1204 FcConfigDel (FcValueListPtr
*head
,
1205 FcValueList
*position
)
1207 FcValueListPtr
*prev
;
1209 for (prev
= head
; *prev
!= NULL
; prev
= &(*prev
)->next
)
1211 if (*prev
== position
)
1213 *prev
= position
->next
;
1214 position
->next
= NULL
;
1215 FcValueListDestroy (position
);
1222 FcConfigPatternAdd (FcPattern
*p
,
1229 FcPatternElt
*e
= FcPatternObjectInsertElt (p
, object
);
1233 FcConfigAdd (&e
->values
, 0, append
, list
);
1238 * Delete all values associated with a field
1241 FcConfigPatternDel (FcPattern
*p
,
1244 FcPatternElt
*e
= FcPatternObjectFindElt (p
, object
);
1247 while (e
->values
!= NULL
)
1248 FcConfigDel (&e
->values
, e
->values
);
1252 FcConfigPatternCanon (FcPattern
*p
,
1255 FcPatternElt
*e
= FcPatternObjectFindElt (p
, object
);
1258 if (e
->values
== NULL
)
1259 FcPatternObjectDel (p
, object
);
1263 FcConfigSubstituteWithPat (FcConfig
*config
,
1278 config
= FcConfigGetCurrent ();
1284 case FcMatchPattern
:
1285 s
= config
->substPattern
;
1288 s
= config
->substFont
;
1291 s
= config
->substScan
;
1297 st
= (FcSubState
*) malloc (config
->maxObjects
* sizeof (FcSubState
));
1298 if (!st
&& config
->maxObjects
)
1300 FcMemAlloc (FC_MEM_SUBSTATE
, config
->maxObjects
* sizeof (FcSubState
));
1302 if (FcDebug () & FC_DBG_EDIT
)
1304 printf ("FcConfigSubstitute ");
1307 for (; s
; s
= s
->next
)
1310 * Check the tests to see if
1311 * they all match the pattern
1313 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1315 if (FcDebug () & FC_DBG_EDIT
)
1317 printf ("FcConfigSubstitute test ");
1321 if (kind
== FcMatchFont
&& t
->kind
== FcMatchPattern
)
1326 st
[i
].elt
= FcPatternObjectFindElt (m
, t
->object
);
1330 * If there's no such field in the font,
1331 * then FcQualAll matches while FcQualAny does not
1335 if (t
->qual
== FcQualAll
)
1344 * Check to see if there is a match, mark the location
1345 * to apply match-relative edits
1347 st
[i
].value
= FcConfigMatchValueList (m
, t
, st
[i
].elt
->values
);
1350 if (t
->qual
== FcQualFirst
&& st
[i
].value
!= st
[i
].elt
->values
)
1352 if (t
->qual
== FcQualNotFirst
&& st
[i
].value
== st
[i
].elt
->values
)
1357 if (FcDebug () & FC_DBG_EDIT
)
1358 printf ("No match\n");
1361 if (FcDebug () & FC_DBG_EDIT
)
1363 printf ("Substitute ");
1366 for (e
= s
->edit
; e
; e
= e
->next
)
1369 * Evaluate the list of expressions
1371 l
= FcConfigValues (p
, e
->expr
, e
->binding
);
1373 * Locate any test associated with this field, skipping
1374 * tests associated with the pattern when substituting in
1377 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1379 if ((t
->kind
== FcMatchFont
|| kind
== FcMatchPattern
) &&
1380 t
->object
== e
->object
)
1383 * KLUDGE - the pattern may have been reallocated or
1384 * things may have been inserted or deleted above
1385 * this element by other edits. Go back and find
1388 if (e
!= s
->edit
&& st
[i
].elt
)
1389 st
[i
].elt
= FcPatternObjectFindElt (p
, t
->object
);
1398 * If there was a test, then replace the matched
1399 * value with the new list of values
1403 FcValueList
*thisValue
= st
[i
].value
;
1404 FcValueList
*nextValue
= thisValue
;
1407 * Append the new list of values after the current value
1409 FcConfigAdd (&st
[i
].elt
->values
, thisValue
, FcTrue
, l
);
1411 * Delete the marked value
1414 FcConfigDel (&st
[i
].elt
->values
, thisValue
);
1416 * Adjust any pointers into the value list to ensure
1417 * future edits occur at the same place
1419 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1421 if (st
[i
].value
== thisValue
)
1422 st
[i
].value
= nextValue
;
1426 /* fall through ... */
1427 case FcOpAssignReplace
:
1429 * Delete all of the values and insert
1432 FcConfigPatternDel (p
, e
->object
);
1433 FcConfigPatternAdd (p
, e
->object
, l
, FcTrue
);
1435 * Adjust any pointers into the value list as they no
1436 * longer point to anything valid
1440 FcPatternElt
*thisElt
= st
[i
].elt
;
1441 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1443 if (st
[i
].elt
== thisElt
)
1451 FcConfigAdd (&st
[i
].elt
->values
, st
[i
].value
, FcFalse
, l
);
1454 /* fall through ... */
1455 case FcOpPrependFirst
:
1456 FcConfigPatternAdd (p
, e
->object
, l
, FcFalse
);
1461 FcConfigAdd (&st
[i
].elt
->values
, st
[i
].value
, FcTrue
, l
);
1464 /* fall through ... */
1465 case FcOpAppendLast
:
1466 FcConfigPatternAdd (p
, e
->object
, l
, FcTrue
);
1469 FcValueListDestroy (l
);
1474 * Now go through the pattern and eliminate
1475 * any properties without data
1477 for (e
= s
->edit
; e
; e
= e
->next
)
1478 FcConfigPatternCanon (p
, e
->object
);
1480 if (FcDebug () & FC_DBG_EDIT
)
1482 printf ("FcConfigSubstitute edit");
1486 FcMemFree (FC_MEM_SUBSTATE
, config
->maxObjects
* sizeof (FcSubState
));
1488 if (FcDebug () & FC_DBG_EDIT
)
1490 printf ("FcConfigSubstitute done");
1497 FcConfigSubstitute (FcConfig
*config
,
1501 return FcConfigSubstituteWithPat (config
, p
, 0, kind
);
1504 #if defined (_WIN32) && (defined (PIC) || defined (DLL_EXPORT))
1506 static FcChar8 fontconfig_path
[1000] = "";
1509 DllMain (HINSTANCE hinstDLL
,
1515 switch (fdwReason
) {
1516 case DLL_PROCESS_ATTACH
:
1517 if (!GetModuleFileName ((HMODULE
) hinstDLL
, fontconfig_path
,
1518 sizeof (fontconfig_path
)))
1521 /* If the fontconfig DLL is in a "bin" or "lib" subfolder,
1522 * assume it's a Unix-style installation tree, and use
1523 * "etc/fonts" in there as FONTCONFIG_PATH. Otherwise use the
1524 * folder where the DLL is as FONTCONFIG_PATH.
1526 p
= strrchr (fontconfig_path
, '\\');
1530 p
= strrchr (fontconfig_path
, '\\');
1531 if (p
&& (FcStrCmpIgnoreCase (p
+ 1, "bin") == 0 ||
1532 FcStrCmpIgnoreCase (p
+ 1, "lib") == 0))
1534 strcat (fontconfig_path
, "\\etc\\fonts");
1537 fontconfig_path
[0] = '\0';
1545 #undef FONTCONFIG_PATH
1546 #define FONTCONFIG_PATH fontconfig_path
1548 #else /* !(_WIN32 && PIC) */
1550 #endif /* !(_WIN32 && PIC) */
1552 #ifndef FONTCONFIG_FILE
1553 #define FONTCONFIG_FILE "fonts.conf"
1557 FcConfigFileExists (const FcChar8
*dir
, const FcChar8
*file
)
1562 dir
= (FcChar8
*) "";
1563 path
= malloc (strlen ((char *) dir
) + 1 + strlen ((char *) file
) + 1);
1567 strcpy ((char *) path
, (const char *) dir
);
1568 /* make sure there's a single separator */
1570 if ((!path
[0] || (path
[strlen((char *) path
)-1] != '/' &&
1571 path
[strlen((char *) path
)-1] != '\\')) &&
1574 (isalpha (file
[0]) && file
[1] == ':' && (file
[2] == '/' || file
[2] == '\\'))))
1575 strcat ((char *) path
, "\\");
1577 if ((!path
[0] || path
[strlen((char *) path
)-1] != '/') && file
[0] != '/')
1578 strcat ((char *) path
, "/");
1580 strcat ((char *) path
, (char *) file
);
1582 FcMemAlloc (FC_MEM_STRING
, strlen ((char *) path
) + 1);
1583 if (access ((char *) path
, R_OK
) == 0)
1591 FcConfigGetPath (void)
1594 FcChar8
*env
, *e
, *colon
;
1599 npath
= 2; /* default dir + null */
1600 env
= (FcChar8
*) getenv ("FONTCONFIG_PATH");
1606 if (*e
++ == FC_SEARCH_PATH_SEPARATOR
)
1609 path
= calloc (npath
, sizeof (FcChar8
*));
1619 colon
= (FcChar8
*) strchr ((char *) e
, FC_SEARCH_PATH_SEPARATOR
);
1621 colon
= e
+ strlen ((char *) e
);
1622 path
[i
] = malloc (colon
- e
+ 1);
1625 strncpy ((char *) path
[i
], (const char *) e
, colon
- e
);
1626 path
[i
][colon
- e
] = '\0';
1635 dir
= (FcChar8
*) FONTCONFIG_PATH
;
1636 path
[i
] = malloc (strlen ((char *) dir
) + 1);
1639 strcpy ((char *) path
[i
], (const char *) dir
);
1643 for (i
= 0; path
[i
]; i
++)
1651 FcConfigFreePath (FcChar8
**path
)
1655 for (p
= path
; *p
; p
++)
1660 static FcBool _FcConfigHomeEnabled
= FcTrue
;
1665 if (_FcConfigHomeEnabled
)
1667 char *home
= getenv ("HOME");
1671 home
= getenv ("USERPROFILE");
1674 return (FcChar8
*) home
;
1680 FcConfigEnableHome (FcBool enable
)
1682 FcBool prev
= _FcConfigHomeEnabled
;
1683 _FcConfigHomeEnabled
= enable
;
1688 FcConfigFilename (const FcChar8
*url
)
1690 FcChar8
*file
, *dir
, **path
, **p
;
1694 url
= (FcChar8
*) getenv ("FONTCONFIG_FILE");
1696 url
= (FcChar8
*) FONTCONFIG_FILE
;
1701 if (isalpha (*url
) &&
1703 (url
[2] == '/' || url
[2] == '\\'))
1709 dir
= FcConfigHome ();
1711 file
= FcConfigFileExists (dir
, url
+ 1);
1720 file
= FcConfigFileExists (0, url
);
1723 path
= FcConfigGetPath ();
1726 for (p
= path
; *p
; p
++)
1728 file
= FcConfigFileExists (*p
, url
);
1732 FcConfigFreePath (path
);
1739 * Manage the application-specific fonts
1743 FcConfigAppFontAddFile (FcConfig
*config
,
1744 const FcChar8
*file
)
1753 config
= FcConfigGetCurrent ();
1758 subdirs
= FcStrSetCreate ();
1762 set
= FcConfigGetFonts (config
, FcSetApplication
);
1765 set
= FcFontSetCreate ();
1768 FcStrSetDestroy (subdirs
);
1771 FcConfigSetFonts (config
, set
, FcSetApplication
);
1774 if (!FcFileScanConfig (set
, subdirs
, config
->blanks
, file
, config
))
1776 FcStrSetDestroy (subdirs
);
1779 if ((sublist
= FcStrListCreate (subdirs
)))
1781 while ((subdir
= FcStrListNext (sublist
)))
1783 FcConfigAppFontAddDir (config
, subdir
);
1785 FcStrListDone (sublist
);
1787 FcStrSetDestroy (subdirs
);
1792 FcConfigAppFontAddDir (FcConfig
*config
,
1800 config
= FcConfigGetCurrent ();
1805 dirs
= FcStrSetCreate ();
1809 set
= FcConfigGetFonts (config
, FcSetApplication
);
1812 set
= FcFontSetCreate ();
1815 FcStrSetDestroy (dirs
);
1818 FcConfigSetFonts (config
, set
, FcSetApplication
);
1821 FcStrSetAddFilename (dirs
, dir
);
1823 if (!FcConfigAddDirList (config
, FcSetApplication
, dirs
))
1825 FcStrSetDestroy (dirs
);
1828 FcStrSetDestroy (dirs
);
1833 FcConfigAppFontClear (FcConfig
*config
)
1837 config
= FcConfigGetCurrent ();
1842 FcConfigSetFonts (config
, 0, FcSetApplication
);
1846 * Manage filename-based font source selectors
1850 FcConfigGlobAdd (FcConfig
*config
,
1851 const FcChar8
*glob
,
1854 FcStrSet
*set
= accept
? config
->acceptGlobs
: config
->rejectGlobs
;
1856 return FcStrSetAdd (set
, glob
);
1860 FcConfigGlobMatch (const FcChar8
*glob
,
1861 const FcChar8
*string
)
1865 while ((c
= *glob
++))
1869 /* short circuit common case */
1872 /* short circuit another common case */
1873 if (strchr ((char *) glob
, '*') == 0)
1874 string
+= strlen ((char *) string
) - strlen ((char *) glob
);
1877 if (FcConfigGlobMatch (glob
, string
))
1883 if (*string
++ == '\0')
1892 return *string
== '\0';
1896 FcConfigGlobsMatch (const FcStrSet
*globs
,
1897 const FcChar8
*string
)
1901 for (i
= 0; i
< globs
->num
; i
++)
1902 if (FcConfigGlobMatch (globs
->strs
[i
], string
))
1908 FcConfigAcceptFilename (FcConfig
*config
,
1909 const FcChar8
*filename
)
1911 if (FcConfigGlobsMatch (config
->acceptGlobs
, filename
))
1913 if (FcConfigGlobsMatch (config
->rejectGlobs
, filename
))
1919 * Manage font-pattern based font source selectors
1923 FcConfigPatternsAdd (FcConfig
*config
,
1927 FcFontSet
*set
= accept
? config
->acceptPatterns
: config
->rejectPatterns
;
1929 return FcFontSetAdd (set
, pattern
);
1933 FcConfigPatternsMatch (const FcFontSet
*patterns
,
1934 const FcPattern
*font
)
1938 for (i
= 0; i
< patterns
->nfont
; i
++)
1939 if (FcListPatternMatchAny (patterns
->fonts
[i
], font
))
1945 FcConfigAcceptFont (FcConfig
*config
,
1946 const FcPattern
*font
)
1948 if (FcConfigPatternsMatch (config
->acceptPatterns
, font
))
1950 if (FcConfigPatternsMatch (config
->rejectPatterns
, font
))
1955 #include "fcaliastail.h"