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 FcConfigModifiedTime (FcConfig
*config
)
146 FcFileTime v
= { 0, FcFalse
};
147 config
= FcConfigGetCurrent ();
151 return FcConfigNewestFile (config
->configFiles
);
155 FcConfigUptoDate (FcConfig
*config
)
157 FcFileTime config_time
, font_time
;
158 time_t now
= time(0);
161 config
= FcConfigGetCurrent ();
165 config_time
= FcConfigNewestFile (config
->configFiles
);
166 font_time
= FcConfigNewestFile (config
->fontDirs
);
167 if ((config_time
.set
&& config_time
.time
- config
->rescanTime
> 0) ||
168 (font_time
.set
&& (font_time
.time
- config
->rescanTime
) > 0))
172 config
->rescanTime
= now
;
177 FcSubstDestroy (FcSubst
*s
)
185 FcTestDestroy (s
->test
);
187 FcEditDestroy (s
->edit
);
189 FcMemFree (FC_MEM_SUBST
, sizeof (FcSubst
));
195 FcConfigDestroy (FcConfig
*config
)
199 if (config
== _fcConfig
)
202 FcStrSetDestroy (config
->configDirs
);
203 FcStrSetDestroy (config
->fontDirs
);
204 FcStrSetDestroy (config
->cacheDirs
);
205 FcStrSetDestroy (config
->configFiles
);
206 FcStrSetDestroy (config
->acceptGlobs
);
207 FcStrSetDestroy (config
->rejectGlobs
);
208 FcFontSetDestroy (config
->acceptPatterns
);
209 FcFontSetDestroy (config
->rejectPatterns
);
212 FcBlanksDestroy (config
->blanks
);
214 FcSubstDestroy (config
->substPattern
);
215 FcSubstDestroy (config
->substFont
);
216 FcSubstDestroy (config
->substScan
);
217 for (set
= FcSetSystem
; set
<= FcSetApplication
; set
++)
218 if (config
->fonts
[set
])
219 FcFontSetDestroy (config
->fonts
[set
]);
222 FcMemFree (FC_MEM_CONFIG
, sizeof (FcConfig
));
226 * Add cache to configuration, adding fonts and directories
230 FcConfigAddCache (FcConfig
*config
, FcCache
*cache
)
239 fs
= FcCacheSet (cache
);
244 for (i
= 0; i
< fs
->nfont
; i
++)
246 FcPattern
*font
= FcFontSetFont (fs
, i
);
250 * Check to see if font is banned by filename
252 if (FcPatternObjectGetString (font
, FC_FILE_OBJECT
,
253 0, &font_file
) == FcResultMatch
&&
254 !FcConfigAcceptFilename (config
, font_file
))
260 * Check to see if font is banned by pattern
262 if (!FcConfigAcceptFont (config
, font
))
266 FcFontSetAdd (config
->fonts
[FcSetSystem
], font
);
268 FcDirCacheReference (cache
, nref
);
274 dirs
= FcCacheDirs (cache
);
277 for (i
= 0; i
< cache
->dirs_count
; i
++)
279 FcChar8
*dir
= FcOffsetToPtr (dirs
, dirs
[i
], FcChar8
);
280 if (FcConfigAcceptFilename (config
, dir
))
281 FcConfigAddFontDir (config
, dir
);
288 * Scan the current list of directories in the configuration
289 * and build the set of available fonts.
293 FcConfigBuildFonts (FcConfig
*config
)
302 config
= FcConfigGetCurrent ();
307 fonts
= FcFontSetCreate ();
311 FcConfigSetFonts (config
, fonts
, FcSetSystem
);
313 dirlist
= FcStrListCreate (config
->fontDirs
);
317 while ((dir
= FcStrListNext (dirlist
)))
319 if (FcDebug () & FC_DBG_FONTSET
)
320 printf ("adding fonts from%s\n", dir
);
321 cache
= FcDirCacheRead (dir
, FcFalse
, config
);
324 FcConfigAddCache (config
, cache
);
325 FcDirCacheUnload (cache
);
328 FcStrListDone (dirlist
);
330 if (FcDebug () & FC_DBG_FONTSET
)
331 FcFontSetPrint (fonts
);
339 FcConfigSetCurrent (FcConfig
*config
)
342 if (!FcConfigBuildFonts (config
))
346 FcConfigDestroy (_fcConfig
);
352 FcConfigGetCurrent (void)
361 FcConfigAddConfigDir (FcConfig
*config
,
364 return FcStrSetAddFilename (config
->configDirs
, d
);
368 FcConfigGetConfigDirs (FcConfig
*config
)
372 config
= FcConfigGetCurrent ();
376 return FcStrListCreate (config
->configDirs
);
380 FcConfigAddFontDir (FcConfig
*config
,
383 return FcStrSetAddFilename (config
->fontDirs
, d
);
387 FcConfigAddDir (FcConfig
*config
,
390 return (FcConfigAddConfigDir (config
, d
) &&
391 FcConfigAddFontDir (config
, d
));
395 FcConfigGetFontDirs (FcConfig
*config
)
399 config
= FcConfigGetCurrent ();
403 return FcStrListCreate (config
->fontDirs
);
407 FcConfigAddCacheDir (FcConfig
*config
,
410 return FcStrSetAddFilename (config
->cacheDirs
, d
);
414 FcConfigGetCacheDirs (FcConfig
*config
)
418 config
= FcConfigGetCurrent ();
422 return FcStrListCreate (config
->cacheDirs
);
426 FcConfigAddConfigFile (FcConfig
*config
,
430 FcChar8
*file
= FcConfigFilename (f
);
435 ret
= FcStrSetAdd (config
->configFiles
, file
);
441 FcConfigGetConfigFiles (FcConfig
*config
)
445 config
= FcConfigGetCurrent ();
449 return FcStrListCreate (config
->configFiles
);
453 FcConfigGetCache (FcConfig
*config
)
459 FcConfigGetFonts (FcConfig
*config
,
464 config
= FcConfigGetCurrent ();
468 return config
->fonts
[set
];
472 FcConfigSetFonts (FcConfig
*config
,
476 if (config
->fonts
[set
])
477 FcFontSetDestroy (config
->fonts
[set
]);
478 config
->fonts
[set
] = fonts
;
482 FcConfigGetBlanks (FcConfig
*config
)
486 config
= FcConfigGetCurrent ();
490 return config
->blanks
;
494 FcConfigAddBlank (FcConfig
*config
,
497 FcBlanks
*b
, *freeme
= 0;
502 freeme
= b
= FcBlanksCreate ();
506 if (!FcBlanksAdd (b
, blank
))
509 FcBlanksDestroy (freeme
);
517 FcConfigGetRescanInverval (FcConfig
*config
)
521 config
= FcConfigGetCurrent ();
525 return config
->rescanInterval
;
529 FcConfigSetRescanInverval (FcConfig
*config
, int rescanInterval
)
533 config
= FcConfigGetCurrent ();
537 config
->rescanInterval
= rescanInterval
;
542 FcConfigAddEdit (FcConfig
*config
,
547 FcSubst
*subst
, **prev
;
553 prev
= &config
->substPattern
;
556 prev
= &config
->substFont
;
559 prev
= &config
->substScan
;
564 subst
= (FcSubst
*) malloc (sizeof (FcSubst
));
567 FcMemAlloc (FC_MEM_SUBST
, sizeof (FcSubst
));
568 for (; *prev
; prev
= &(*prev
)->next
);
574 for (t
= test
; t
; t
= t
->next
)
576 if (t
->kind
== FcMatchDefault
)
580 if (config
->maxObjects
< num
)
581 config
->maxObjects
= num
;
582 if (FcDebug () & FC_DBG_EDIT
)
584 printf ("Add Subst ");
585 FcSubstPrint (subst
);
590 typedef struct _FcSubState
{
596 FcConfigPromote (FcValue v
, FcValue u
)
598 if (v
.type
== FcTypeInteger
)
600 v
.type
= FcTypeDouble
;
601 v
.u
.d
= (double) v
.u
.i
;
603 else if (v
.type
== FcTypeVoid
&& u
.type
== FcTypeMatrix
)
605 v
.u
.m
= &FcIdentityMatrix
;
606 v
.type
= FcTypeMatrix
;
608 else if (v
.type
== FcTypeString
&& u
.type
== FcTypeLangSet
)
610 v
.u
.l
= FcLangSetPromote (v
.u
.s
);
611 v
.type
= FcTypeLangSet
;
617 FcConfigCompareValue (const FcValue
*left_o
,
619 const FcValue
*right_o
)
621 FcValue left
= FcValueCanonicalize(left_o
);
622 FcValue right
= FcValueCanonicalize(right_o
);
623 FcBool ret
= FcFalse
;
625 left
= FcConfigPromote (left
, right
);
626 right
= FcConfigPromote (right
, left
);
627 if (left
.type
== right
.type
)
631 break; /* FcConfigPromote prevents this from happening */
637 ret
= left
.u
.d
== right
.u
.d
;
640 case FcOpNotContains
:
641 ret
= left
.u
.d
!= right
.u
.d
;
644 ret
= left
.u
.d
< right
.u
.d
;
647 ret
= left
.u
.d
<= right
.u
.d
;
650 ret
= left
.u
.d
> right
.u
.d
;
653 ret
= left
.u
.d
>= right
.u
.d
;
664 ret
= left
.u
.b
== right
.u
.b
;
667 case FcOpNotContains
:
668 ret
= left
.u
.b
!= right
.u
.b
;
678 ret
= FcStrCmpIgnoreCase (left
.u
.s
, right
.u
.s
) == 0;
681 ret
= FcStrStrIgnoreCase (left
.u
.s
, right
.u
.s
) != 0;
684 ret
= FcStrCmpIgnoreCase (left
.u
.s
, right
.u
.s
) != 0;
686 case FcOpNotContains
:
687 ret
= FcStrCmpIgnoreCase (left
.u
.s
, right
.u
.s
) == 0;
698 ret
= FcMatrixEqual (left
.u
.m
, right
.u
.m
);
701 case FcOpNotContains
:
702 ret
= !FcMatrixEqual (left
.u
.m
, right
.u
.m
);
712 /* left contains right if right is a subset of left */
713 ret
= FcCharSetIsSubset (right
.u
.c
, left
.u
.c
);
715 case FcOpNotContains
:
716 /* left contains right if right is a subset of left */
717 ret
= !FcCharSetIsSubset (right
.u
.c
, left
.u
.c
);
720 ret
= FcCharSetEqual (left
.u
.c
, right
.u
.c
);
723 ret
= !FcCharSetEqual (left
.u
.c
, right
.u
.c
);
733 ret
= FcLangSetContains (left
.u
.l
, right
.u
.l
);
735 case FcOpNotContains
:
736 ret
= !FcLangSetContains (left
.u
.l
, right
.u
.l
);
739 ret
= FcLangSetEqual (left
.u
.l
, right
.u
.l
);
742 ret
= !FcLangSetEqual (left
.u
.l
, right
.u
.l
);
764 ret
= left
.u
.f
== right
.u
.f
;
767 case FcOpNotContains
:
768 ret
= left
.u
.f
!= right
.u
.f
;
778 if (op
== FcOpNotEqual
|| op
== FcOpNotContains
)
785 #define _FcDoubleFloor(d) ((int) (d))
786 #define _FcDoubleCeil(d) ((double) (int) (d) == (d) ? (int) (d) : (int) ((d) + 1))
787 #define FcDoubleFloor(d) ((d) >= 0 ? _FcDoubleFloor(d) : -_FcDoubleCeil(-(d)))
788 #define FcDoubleCeil(d) ((d) >= 0 ? _FcDoubleCeil(d) : -_FcDoubleFloor(-(d)))
789 #define FcDoubleRound(d) FcDoubleFloor ((d) + 0.5)
790 #define FcDoubleTrunc(d) ((d) >= 0 ? _FcDoubleFloor (d) : -_FcDoubleFloor (-(d)))
793 FcConfigEvaluate (FcPattern
*p
, FcExpr
*e
)
802 v
.type
= FcTypeInteger
;
806 v
.type
= FcTypeDouble
;
810 v
.type
= FcTypeString
;
811 v
.u
.s
= FcStrStaticName(e
->u
.sval
);
814 v
.type
= FcTypeMatrix
;
819 v
.type
= FcTypeCharSet
;
828 r
= FcPatternObjectGet (p
, e
->u
.object
, 0, &v
);
829 if (r
!= FcResultMatch
)
834 if (FcNameConstant (e
->u
.constant
, &v
.u
.i
))
835 v
.type
= FcTypeInteger
;
840 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
841 if (vl
.type
== FcTypeBool
)
844 v
= FcConfigEvaluate (p
, e
->u
.tree
.right
->u
.tree
.left
);
846 v
= FcConfigEvaluate (p
, e
->u
.tree
.right
->u
.tree
.right
);
859 case FcOpNotContains
:
861 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
862 vr
= FcConfigEvaluate (p
, e
->u
.tree
.right
);
864 v
.u
.b
= FcConfigCompareValue (&vl
, e
->op
, &vr
);
874 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
875 vr
= FcConfigEvaluate (p
, e
->u
.tree
.right
);
876 vl
= FcConfigPromote (vl
, vr
);
877 vr
= FcConfigPromote (vr
, vl
);
878 if (vl
.type
== vr
.type
)
884 v
.type
= FcTypeDouble
;
885 v
.u
.d
= vl
.u
.d
+ vr
.u
.d
;
888 v
.type
= FcTypeDouble
;
889 v
.u
.d
= vl
.u
.d
- vr
.u
.d
;
892 v
.type
= FcTypeDouble
;
893 v
.u
.d
= vl
.u
.d
* vr
.u
.d
;
896 v
.type
= FcTypeDouble
;
897 v
.u
.d
= vl
.u
.d
/ vr
.u
.d
;
903 if (v
.type
== FcTypeDouble
&&
904 v
.u
.d
== (double) (int) v
.u
.d
)
906 v
.type
= FcTypeInteger
;
914 v
.u
.b
= vl
.u
.b
|| vr
.u
.b
;
918 v
.u
.b
= vl
.u
.b
&& vr
.u
.b
;
928 v
.type
= FcTypeString
;
929 str
= FcStrPlus (vl
.u
.s
, vr
.u
.s
);
930 v
.u
.s
= FcStrStaticName (str
);
944 v
.type
= FcTypeMatrix
;
945 m
= malloc (sizeof (FcMatrix
));
948 FcMemAlloc (FC_MEM_MATRIX
, sizeof (FcMatrix
));
949 FcMatrixMultiply (m
, vl
.u
.m
, vr
.u
.m
);
973 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
986 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
992 v
.type
= FcTypeInteger
;
993 v
.u
.i
= FcDoubleFloor (vl
.u
.d
);
1002 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
1008 v
.type
= FcTypeInteger
;
1009 v
.u
.i
= FcDoubleCeil (vl
.u
.d
);
1012 v
.type
= FcTypeVoid
;
1015 FcValueDestroy (vl
);
1018 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
1024 v
.type
= FcTypeInteger
;
1025 v
.u
.i
= FcDoubleRound (vl
.u
.d
);
1028 v
.type
= FcTypeVoid
;
1031 FcValueDestroy (vl
);
1034 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
1040 v
.type
= FcTypeInteger
;
1041 v
.u
.i
= FcDoubleTrunc (vl
.u
.d
);
1044 v
.type
= FcTypeVoid
;
1047 FcValueDestroy (vl
);
1050 v
.type
= FcTypeVoid
;
1056 static FcValueList
*
1057 FcConfigMatchValueList (FcPattern
*p
,
1059 FcValueList
*values
)
1061 FcValueList
*ret
= 0;
1062 FcExpr
*e
= t
->expr
;
1068 /* Compute the value of the match expression */
1069 if (e
->op
== FcOpComma
)
1071 value
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
1072 e
= e
->u
.tree
.right
;
1076 value
= FcConfigEvaluate (p
, e
);
1080 for (v
= values
; v
; v
= FcValueListNext(v
))
1082 /* Compare the pattern value to the match expression value */
1083 if (FcConfigCompareValue (&v
->value
, t
->op
, &value
))
1090 if (t
->qual
== FcQualAll
)
1097 FcValueDestroy (value
);
1102 static FcValueList
*
1103 FcConfigValues (FcPattern
*p
, FcExpr
*e
, FcValueBinding binding
)
1109 l
= (FcValueList
*) malloc (sizeof (FcValueList
));
1112 FcMemAlloc (FC_MEM_VALLIST
, sizeof (FcValueList
));
1113 if (e
->op
== FcOpComma
)
1115 l
->value
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
1116 l
->next
= FcConfigValues (p
, e
->u
.tree
.right
, binding
);
1120 l
->value
= FcConfigEvaluate (p
, e
);
1123 l
->binding
= binding
;
1124 if (l
->value
.type
== FcTypeVoid
)
1126 FcValueList
*next
= FcValueListNext(l
);
1128 FcMemFree (FC_MEM_VALLIST
, sizeof (FcValueList
));
1137 FcConfigAdd (FcValueListPtr
*head
,
1138 FcValueList
*position
,
1142 FcValueListPtr
*prev
, last
, v
;
1143 FcValueBinding sameBinding
;
1146 sameBinding
= position
->binding
;
1148 sameBinding
= FcValueBindingWeak
;
1149 for (v
= new; v
!= NULL
; v
= FcValueListNext(v
))
1150 if (v
->binding
== FcValueBindingSame
)
1151 v
->binding
= sameBinding
;
1155 prev
= &position
->next
;
1157 for (prev
= head
; *prev
!= NULL
;
1158 prev
= &(*prev
)->next
)
1165 for (prev
= head
; *prev
!= NULL
;
1166 prev
= &(*prev
)->next
)
1168 if (*prev
== position
)
1175 if (FcDebug () & FC_DBG_EDIT
)
1178 printf ("position not on list\n");
1182 if (FcDebug () & FC_DBG_EDIT
)
1184 printf ("%s list before ", append
? "Append" : "Prepend");
1185 FcValueListPrint (*head
);
1192 while (last
->next
!= NULL
)
1199 if (FcDebug () & FC_DBG_EDIT
)
1201 printf ("%s list after ", append
? "Append" : "Prepend");
1202 FcValueListPrint (*head
);
1210 FcConfigDel (FcValueListPtr
*head
,
1211 FcValueList
*position
)
1213 FcValueListPtr
*prev
;
1215 for (prev
= head
; *prev
!= NULL
; prev
= &(*prev
)->next
)
1217 if (*prev
== position
)
1219 *prev
= position
->next
;
1220 position
->next
= NULL
;
1221 FcValueListDestroy (position
);
1228 FcConfigPatternAdd (FcPattern
*p
,
1235 FcPatternElt
*e
= FcPatternObjectInsertElt (p
, object
);
1239 FcConfigAdd (&e
->values
, 0, append
, list
);
1244 * Delete all values associated with a field
1247 FcConfigPatternDel (FcPattern
*p
,
1250 FcPatternElt
*e
= FcPatternObjectFindElt (p
, object
);
1253 while (e
->values
!= NULL
)
1254 FcConfigDel (&e
->values
, e
->values
);
1258 FcConfigPatternCanon (FcPattern
*p
,
1261 FcPatternElt
*e
= FcPatternObjectFindElt (p
, object
);
1264 if (e
->values
== NULL
)
1265 FcPatternObjectDel (p
, object
);
1269 FcConfigSubstituteWithPat (FcConfig
*config
,
1284 config
= FcConfigGetCurrent ();
1290 case FcMatchPattern
:
1291 s
= config
->substPattern
;
1294 s
= config
->substFont
;
1297 s
= config
->substScan
;
1303 st
= (FcSubState
*) malloc (config
->maxObjects
* sizeof (FcSubState
));
1304 if (!st
&& config
->maxObjects
)
1306 FcMemAlloc (FC_MEM_SUBSTATE
, config
->maxObjects
* sizeof (FcSubState
));
1308 if (FcDebug () & FC_DBG_EDIT
)
1310 printf ("FcConfigSubstitute ");
1313 for (; s
; s
= s
->next
)
1316 * Check the tests to see if
1317 * they all match the pattern
1319 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1321 if (FcDebug () & FC_DBG_EDIT
)
1323 printf ("FcConfigSubstitute test ");
1327 if (kind
== FcMatchFont
&& t
->kind
== FcMatchPattern
)
1332 st
[i
].elt
= FcPatternObjectFindElt (m
, t
->object
);
1336 * If there's no such field in the font,
1337 * then FcQualAll matches while FcQualAny does not
1341 if (t
->qual
== FcQualAll
)
1350 * Check to see if there is a match, mark the location
1351 * to apply match-relative edits
1353 st
[i
].value
= FcConfigMatchValueList (m
, t
, st
[i
].elt
->values
);
1356 if (t
->qual
== FcQualFirst
&& st
[i
].value
!= st
[i
].elt
->values
)
1358 if (t
->qual
== FcQualNotFirst
&& st
[i
].value
== st
[i
].elt
->values
)
1363 if (FcDebug () & FC_DBG_EDIT
)
1364 printf ("No match\n");
1367 if (FcDebug () & FC_DBG_EDIT
)
1369 printf ("Substitute ");
1372 for (e
= s
->edit
; e
; e
= e
->next
)
1375 * Evaluate the list of expressions
1377 l
= FcConfigValues (p
, e
->expr
, e
->binding
);
1379 * Locate any test associated with this field, skipping
1380 * tests associated with the pattern when substituting in
1383 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1385 if ((t
->kind
== FcMatchFont
|| kind
== FcMatchPattern
) &&
1386 t
->object
== e
->object
)
1389 * KLUDGE - the pattern may have been reallocated or
1390 * things may have been inserted or deleted above
1391 * this element by other edits. Go back and find
1394 if (e
!= s
->edit
&& st
[i
].elt
)
1395 st
[i
].elt
= FcPatternObjectFindElt (p
, t
->object
);
1404 * If there was a test, then replace the matched
1405 * value with the new list of values
1409 FcValueList
*thisValue
= st
[i
].value
;
1410 FcValueList
*nextValue
= thisValue
;
1413 * Append the new list of values after the current value
1415 FcConfigAdd (&st
[i
].elt
->values
, thisValue
, FcTrue
, l
);
1417 * Delete the marked value
1420 FcConfigDel (&st
[i
].elt
->values
, thisValue
);
1422 * Adjust any pointers into the value list to ensure
1423 * future edits occur at the same place
1425 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1427 if (st
[i
].value
== thisValue
)
1428 st
[i
].value
= nextValue
;
1432 /* fall through ... */
1433 case FcOpAssignReplace
:
1435 * Delete all of the values and insert
1438 FcConfigPatternDel (p
, e
->object
);
1439 FcConfigPatternAdd (p
, e
->object
, l
, FcTrue
);
1441 * Adjust any pointers into the value list as they no
1442 * longer point to anything valid
1446 FcPatternElt
*thisElt
= st
[i
].elt
;
1447 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1449 if (st
[i
].elt
== thisElt
)
1457 FcConfigAdd (&st
[i
].elt
->values
, st
[i
].value
, FcFalse
, l
);
1460 /* fall through ... */
1461 case FcOpPrependFirst
:
1462 FcConfigPatternAdd (p
, e
->object
, l
, FcFalse
);
1467 FcConfigAdd (&st
[i
].elt
->values
, st
[i
].value
, FcTrue
, l
);
1470 /* fall through ... */
1471 case FcOpAppendLast
:
1472 FcConfigPatternAdd (p
, e
->object
, l
, FcTrue
);
1475 FcValueListDestroy (l
);
1480 * Now go through the pattern and eliminate
1481 * any properties without data
1483 for (e
= s
->edit
; e
; e
= e
->next
)
1484 FcConfigPatternCanon (p
, e
->object
);
1486 if (FcDebug () & FC_DBG_EDIT
)
1488 printf ("FcConfigSubstitute edit");
1492 FcMemFree (FC_MEM_SUBSTATE
, config
->maxObjects
* sizeof (FcSubState
));
1494 if (FcDebug () & FC_DBG_EDIT
)
1496 printf ("FcConfigSubstitute done");
1503 FcConfigSubstitute (FcConfig
*config
,
1507 return FcConfigSubstituteWithPat (config
, p
, 0, kind
);
1510 #if defined (_WIN32) && (defined (PIC) || defined (DLL_EXPORT))
1512 static FcChar8 fontconfig_path
[1000] = "";
1515 DllMain (HINSTANCE hinstDLL
,
1521 switch (fdwReason
) {
1522 case DLL_PROCESS_ATTACH
:
1523 if (!GetModuleFileName ((HMODULE
) hinstDLL
, fontconfig_path
,
1524 sizeof (fontconfig_path
)))
1527 /* If the fontconfig DLL is in a "bin" or "lib" subfolder,
1528 * assume it's a Unix-style installation tree, and use
1529 * "etc/fonts" in there as FONTCONFIG_PATH. Otherwise use the
1530 * folder where the DLL is as FONTCONFIG_PATH.
1532 p
= strrchr (fontconfig_path
, '\\');
1536 p
= strrchr (fontconfig_path
, '\\');
1537 if (p
&& (FcStrCmpIgnoreCase (p
+ 1, "bin") == 0 ||
1538 FcStrCmpIgnoreCase (p
+ 1, "lib") == 0))
1540 strcat (fontconfig_path
, "\\etc\\fonts");
1543 fontconfig_path
[0] = '\0';
1551 #undef FONTCONFIG_PATH
1552 #define FONTCONFIG_PATH fontconfig_path
1554 #else /* !(_WIN32 && PIC) */
1556 #endif /* !(_WIN32 && PIC) */
1558 #ifndef FONTCONFIG_FILE
1559 #define FONTCONFIG_FILE "fonts.conf"
1563 FcConfigFileExists (const FcChar8
*dir
, const FcChar8
*file
)
1568 dir
= (FcChar8
*) "";
1569 path
= malloc (strlen ((char *) dir
) + 1 + strlen ((char *) file
) + 1);
1573 strcpy ((char *) path
, (const char *) dir
);
1574 /* make sure there's a single separator */
1576 if ((!path
[0] || (path
[strlen((char *) path
)-1] != '/' &&
1577 path
[strlen((char *) path
)-1] != '\\')) &&
1580 (isalpha (file
[0]) && file
[1] == ':' && (file
[2] == '/' || file
[2] == '\\'))))
1581 strcat ((char *) path
, "\\");
1583 if ((!path
[0] || path
[strlen((char *) path
)-1] != '/') && file
[0] != '/')
1584 strcat ((char *) path
, "/");
1586 strcat ((char *) path
, (char *) file
);
1588 FcMemAlloc (FC_MEM_STRING
, strlen ((char *) path
) + 1);
1589 if (access ((char *) path
, R_OK
) == 0)
1597 FcConfigGetPath (void)
1600 FcChar8
*env
, *e
, *colon
;
1605 npath
= 2; /* default dir + null */
1606 env
= (FcChar8
*) getenv ("FONTCONFIG_PATH");
1612 if (*e
++ == FC_SEARCH_PATH_SEPARATOR
)
1615 path
= calloc (npath
, sizeof (FcChar8
*));
1625 colon
= (FcChar8
*) strchr ((char *) e
, FC_SEARCH_PATH_SEPARATOR
);
1627 colon
= e
+ strlen ((char *) e
);
1628 path
[i
] = malloc (colon
- e
+ 1);
1631 strncpy ((char *) path
[i
], (const char *) e
, colon
- e
);
1632 path
[i
][colon
- e
] = '\0';
1641 dir
= (FcChar8
*) FONTCONFIG_PATH
;
1642 path
[i
] = malloc (strlen ((char *) dir
) + 1);
1645 strcpy ((char *) path
[i
], (const char *) dir
);
1649 for (i
= 0; path
[i
]; i
++)
1657 FcConfigFreePath (FcChar8
**path
)
1661 for (p
= path
; *p
; p
++)
1666 static FcBool _FcConfigHomeEnabled
= FcTrue
;
1671 if (_FcConfigHomeEnabled
)
1673 char *home
= getenv ("HOME");
1677 home
= getenv ("USERPROFILE");
1680 return (FcChar8
*) home
;
1686 FcConfigEnableHome (FcBool enable
)
1688 FcBool prev
= _FcConfigHomeEnabled
;
1689 _FcConfigHomeEnabled
= enable
;
1694 FcConfigFilename (const FcChar8
*url
)
1696 FcChar8
*file
, *dir
, **path
, **p
;
1700 url
= (FcChar8
*) getenv ("FONTCONFIG_FILE");
1702 url
= (FcChar8
*) FONTCONFIG_FILE
;
1707 if (isalpha (*url
) &&
1709 (url
[2] == '/' || url
[2] == '\\'))
1715 dir
= FcConfigHome ();
1717 file
= FcConfigFileExists (dir
, url
+ 1);
1726 file
= FcConfigFileExists (0, url
);
1729 path
= FcConfigGetPath ();
1732 for (p
= path
; *p
; p
++)
1734 file
= FcConfigFileExists (*p
, url
);
1738 FcConfigFreePath (path
);
1745 * Manage the application-specific fonts
1749 FcConfigAppFontAddFile (FcConfig
*config
,
1750 const FcChar8
*file
)
1759 config
= FcConfigGetCurrent ();
1764 subdirs
= FcStrSetCreate ();
1768 set
= FcConfigGetFonts (config
, FcSetApplication
);
1771 set
= FcFontSetCreate ();
1774 FcStrSetDestroy (subdirs
);
1777 FcConfigSetFonts (config
, set
, FcSetApplication
);
1780 if (!FcFileScanConfig (set
, subdirs
, config
->blanks
, file
, config
))
1782 FcStrSetDestroy (subdirs
);
1785 if ((sublist
= FcStrListCreate (subdirs
)))
1787 while ((subdir
= FcStrListNext (sublist
)))
1789 FcConfigAppFontAddDir (config
, subdir
);
1791 FcStrListDone (sublist
);
1793 FcStrSetDestroy (subdirs
);
1798 FcConfigAppFontAddDir (FcConfig
*config
,
1808 config
= FcConfigGetCurrent ();
1812 subdirs
= FcStrSetCreate ();
1816 set
= FcConfigGetFonts (config
, FcSetApplication
);
1819 set
= FcFontSetCreate ();
1822 FcStrSetDestroy (subdirs
);
1825 FcConfigSetFonts (config
, set
, FcSetApplication
);
1828 if (!FcDirScanConfig (set
, subdirs
, config
->blanks
, dir
, FcFalse
, config
))
1830 FcStrSetDestroy (subdirs
);
1833 if ((sublist
= FcStrListCreate (subdirs
)))
1835 while ((subdir
= FcStrListNext (sublist
)))
1837 FcConfigAppFontAddDir (config
, subdir
);
1839 FcStrListDone (sublist
);
1841 FcStrSetDestroy (subdirs
);
1846 FcConfigAppFontClear (FcConfig
*config
)
1850 config
= FcConfigGetCurrent ();
1855 FcConfigSetFonts (config
, 0, FcSetApplication
);
1859 * Manage filename-based font source selectors
1863 FcConfigGlobAdd (FcConfig
*config
,
1864 const FcChar8
*glob
,
1867 FcStrSet
*set
= accept
? config
->acceptGlobs
: config
->rejectGlobs
;
1869 return FcStrSetAdd (set
, glob
);
1873 FcConfigGlobMatch (const FcChar8
*glob
,
1874 const FcChar8
*string
)
1878 while ((c
= *glob
++))
1882 /* short circuit common case */
1885 /* short circuit another common case */
1886 if (strchr ((char *) glob
, '*') == 0)
1887 string
+= strlen ((char *) string
) - strlen ((char *) glob
);
1890 if (FcConfigGlobMatch (glob
, string
))
1896 if (*string
++ == '\0')
1905 return *string
== '\0';
1909 FcConfigGlobsMatch (const FcStrSet
*globs
,
1910 const FcChar8
*string
)
1914 for (i
= 0; i
< globs
->num
; i
++)
1915 if (FcConfigGlobMatch (globs
->strs
[i
], string
))
1921 FcConfigAcceptFilename (FcConfig
*config
,
1922 const FcChar8
*filename
)
1924 if (FcConfigGlobsMatch (config
->acceptGlobs
, filename
))
1926 if (FcConfigGlobsMatch (config
->rejectGlobs
, filename
))
1932 * Manage font-pattern based font source selectors
1936 FcConfigPatternsAdd (FcConfig
*config
,
1940 FcFontSet
*set
= accept
? config
->acceptPatterns
: config
->rejectPatterns
;
1942 return FcFontSetAdd (set
, pattern
);
1946 FcConfigPatternsMatch (const FcFontSet
*patterns
,
1947 const FcPattern
*font
)
1951 for (i
= 0; i
< patterns
->nfont
; i
++)
1952 if (FcListPatternMatchAny (patterns
->fonts
[i
], font
))
1958 FcConfigAcceptFont (FcConfig
*config
,
1959 const FcPattern
*font
)
1961 if (FcConfigPatternsMatch (config
->acceptPatterns
, font
))
1963 if (FcConfigPatternsMatch (config
->rejectPatterns
, font
))
1968 #include "fcaliastail.h"