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
)
70 config
->acceptPatterns
= FcFontSetCreate ();
71 if (!config
->acceptPatterns
)
74 config
->rejectPatterns
= FcFontSetCreate ();
75 if (!config
->rejectPatterns
)
80 if (!FcConfigSetCache (config
, (FcChar8
*) ("~/" FC_USER_CACHE_FILE
)))
84 if (config
->cache
== 0)
86 /* If no home, use the temp folder. */
88 int templen
= GetTempPath (1, dummy
);
89 FcChar8
*temp
= malloc (templen
+ 1);
95 GetTempPath (templen
+ 1, temp
);
96 cache_dir
= FcStrPlus (temp
, FC_USER_CACHE_FILE
);
98 if (!FcConfigSetCache (config
, cache_dir
))
100 FcStrFree (cache_dir
);
103 FcStrFree (cache_dir
);
110 config
->substPattern
= 0;
111 config
->substFont
= 0;
112 config
->maxObjects
= 0;
113 for (set
= FcSetSystem
; set
<= FcSetApplication
; set
++)
114 config
->fonts
[set
] = 0;
116 config
->rescanTime
= time(0);
117 config
->rescanInterval
= 30;
122 FcFontSetDestroy (config
->rejectPatterns
);
124 FcFontSetDestroy (config
->acceptPatterns
);
126 FcStrSetDestroy (config
->rejectGlobs
);
128 FcStrSetDestroy (config
->acceptGlobs
);
130 FcStrSetDestroy (config
->fontDirs
);
132 FcStrSetDestroy (config
->configFiles
);
134 FcStrSetDestroy (config
->configDirs
);
137 FcMemFree (FC_MEM_CONFIG
, sizeof (FcConfig
));
142 typedef struct _FcFileTime
{
148 FcConfigNewestFile (FcStrSet
*files
)
150 FcStrList
*list
= FcStrListCreate (files
);
151 FcFileTime newest
= { 0, FcFalse
};
157 while ((file
= FcStrListNext (list
)))
158 if (stat ((char *) file
, &statb
) == 0)
159 if (!newest
.set
|| statb
.st_mtime
- newest
.time
> 0)
162 newest
.time
= statb
.st_mtime
;
164 FcStrListDone (list
);
170 FcConfigUptoDate (FcConfig
*config
)
172 FcFileTime config_time
, font_time
;
173 time_t now
= time(0);
176 config
= FcConfigGetCurrent ();
180 config_time
= FcConfigNewestFile (config
->configFiles
);
181 font_time
= FcConfigNewestFile (config
->fontDirs
);
182 if ((config_time
.set
&& config_time
.time
- config
->rescanTime
> 0) ||
183 (font_time
.set
&& (font_time
.time
- config
->rescanTime
) > 0))
187 config
->rescanTime
= now
;
192 FcSubstDestroy (FcSubst
*s
)
200 FcTestDestroy (s
->test
);
202 FcEditDestroy (s
->edit
);
204 FcMemFree (FC_MEM_SUBST
, sizeof (FcSubst
));
210 FcConfigDestroy (FcConfig
*config
)
214 if (config
== _fcConfig
)
217 FcStrSetDestroy (config
->configDirs
);
218 FcStrSetDestroy (config
->fontDirs
);
219 FcStrSetDestroy (config
->configFiles
);
220 FcStrSetDestroy (config
->acceptGlobs
);
221 FcStrSetDestroy (config
->rejectGlobs
);
222 FcFontSetDestroy (config
->acceptPatterns
);
223 FcFontSetDestroy (config
->rejectPatterns
);
226 FcBlanksDestroy (config
->blanks
);
229 FcStrFree (config
->cache
);
231 FcSubstDestroy (config
->substPattern
);
232 FcSubstDestroy (config
->substFont
);
233 for (set
= FcSetSystem
; set
<= FcSetApplication
; set
++)
234 if (config
->fonts
[set
])
235 FcFontSetDestroy (config
->fonts
[set
]);
238 FcMemFree (FC_MEM_CONFIG
, sizeof (FcConfig
));
242 * Scan the current list of directories in the configuration
243 * and build the set of available fonts. Update the
244 * per-user cache file to reflect the new configuration
248 FcConfigBuildFonts (FcConfig
*config
)
250 FcFontSet
*fonts
, *cached_fonts
;
251 FcGlobalCache
*cache
;
257 FcGlobalCacheLoad (cache
, config
->cache
);
259 if (config
->fonts
[FcSetSystem
])
262 fonts
= FcFontSetCreate ();
267 cache
= FcGlobalCacheCreate ();
272 cached_fonts
= FcCacheRead(config
);
275 list
= FcConfigGetFontDirs (config
);
279 while ((dir
= FcStrListNext (list
)))
281 if (FcDebug () & FC_DBG_FONTSET
)
282 printf ("scan dir %s\n", dir
);
283 FcDirScanConfig (fonts
, config
->fontDirs
, cache
,
284 config
->blanks
, dir
, FcFalse
, config
);
287 FcStrListDone (list
);
293 for (i
= 0; i
< cached_fonts
->nfont
; i
++)
295 if (FcConfigAcceptFont (config
, cached_fonts
->fonts
[i
]))
296 FcFontSetAdd (fonts
, cached_fonts
->fonts
[i
]);
298 FcFontSetDestroy (cached_fonts
);
301 if (FcDebug () & FC_DBG_FONTSET
)
302 FcFontSetPrint (fonts
);
306 FcGlobalCacheSave (cache
, config
->cache
);
307 FcGlobalCacheDestroy (cache
);
310 FcConfigSetFonts (config
, fonts
, FcSetSystem
);
314 FcFontSetDestroy (fonts
);
320 FcConfigSetCurrent (FcConfig
*config
)
323 if (!FcConfigBuildFonts (config
))
327 FcConfigDestroy (_fcConfig
);
333 FcConfigGetCurrent (void)
342 FcConfigAddConfigDir (FcConfig
*config
,
345 return FcStrSetAddFilename (config
->configDirs
, d
);
349 FcConfigGetConfigDirs (FcConfig
*config
)
353 config
= FcConfigGetCurrent ();
357 return FcStrListCreate (config
->configDirs
);
361 FcConfigAddFontDir (FcConfig
*config
,
364 return FcStrSetAddFilename (config
->fontDirs
, d
);
368 FcConfigAddDir (FcConfig
*config
,
371 return (FcConfigAddConfigDir (config
, d
) &&
372 FcConfigAddFontDir (config
, d
));
376 FcConfigGetFontDirs (FcConfig
*config
)
380 config
= FcConfigGetCurrent ();
384 return FcStrListCreate (config
->fontDirs
);
388 FcConfigAddConfigFile (FcConfig
*config
,
392 FcChar8
*file
= FcConfigFilename (f
);
397 ret
= FcStrSetAdd (config
->configFiles
, file
);
403 FcConfigGetConfigFiles (FcConfig
*config
)
407 config
= FcConfigGetCurrent ();
411 return FcStrListCreate (config
->configFiles
);
415 FcConfigSetCache (FcConfig
*config
,
418 FcChar8
*new = FcStrCopyFilename (c
);
423 FcStrFree (config
->cache
);
429 FcConfigGetCache (FcConfig
*config
)
433 config
= FcConfigGetCurrent ();
437 return config
->cache
;
441 FcConfigGetFonts (FcConfig
*config
,
446 config
= FcConfigGetCurrent ();
450 return config
->fonts
[set
];
454 FcConfigSetFonts (FcConfig
*config
,
458 if (config
->fonts
[set
])
459 FcFontSetDestroy (config
->fonts
[set
]);
460 config
->fonts
[set
] = fonts
;
466 FcConfigGetBlanks (FcConfig
*config
)
470 config
= FcConfigGetCurrent ();
474 return config
->blanks
;
478 FcConfigAddBlank (FcConfig
*config
,
486 b
= FcBlanksCreate ();
490 if (!FcBlanksAdd (b
, blank
))
497 FcConfigGetRescanInverval (FcConfig
*config
)
501 config
= FcConfigGetCurrent ();
505 return config
->rescanInterval
;
509 FcConfigSetRescanInverval (FcConfig
*config
, int rescanInterval
)
513 config
= FcConfigGetCurrent ();
517 config
->rescanInterval
= rescanInterval
;
522 FcConfigAddEdit (FcConfig
*config
,
527 FcSubst
*subst
, **prev
;
531 subst
= (FcSubst
*) malloc (sizeof (FcSubst
));
534 FcMemAlloc (FC_MEM_SUBST
, sizeof (FcSubst
));
535 if (kind
== FcMatchPattern
)
536 prev
= &config
->substPattern
;
538 prev
= &config
->substFont
;
539 for (; *prev
; prev
= &(*prev
)->next
);
545 for (t
= test
; t
; t
= t
->next
)
547 if (t
->kind
== FcMatchDefault
)
551 if (config
->maxObjects
< num
)
552 config
->maxObjects
= num
;
553 if (FcDebug () & FC_DBG_EDIT
)
555 printf ("Add Subst ");
556 FcSubstPrint (subst
);
561 typedef struct _FcSubState
{
567 FcConfigPromote (FcValue v
, FcValue u
)
569 if (v
.type
== FcTypeInteger
)
571 v
.type
= FcTypeDouble
;
572 v
.u
.d
= (double) v
.u
.i
;
574 else if (v
.type
== FcTypeVoid
&& u
.type
== FcTypeMatrix
)
576 v
.u
.m
= &FcIdentityMatrix
;
577 v
.type
= FcTypeMatrix
;
579 else if (v
.type
== FcTypeString
&& u
.type
== FcTypeLangSet
)
581 v
.u
.l
= FcLangSetPromote (v
.u
.s
);
582 v
.type
= FcTypeLangSet
;
588 FcConfigCompareValue (const FcValue
*left_o
,
590 const FcValue
*right_o
)
592 FcValue left
= FcValueCanonicalize(left_o
);
593 FcValue right
= FcValueCanonicalize(right_o
);
594 FcBool ret
= FcFalse
;
596 left
= FcConfigPromote (left
, right
);
597 right
= FcConfigPromote (right
, left
);
598 if (left
.type
== right
.type
)
602 break; /* FcConfigPromote prevents this from happening */
608 ret
= left
.u
.d
== right
.u
.d
;
611 case FcOpNotContains
:
612 ret
= left
.u
.d
!= right
.u
.d
;
615 ret
= left
.u
.d
< right
.u
.d
;
618 ret
= left
.u
.d
<= right
.u
.d
;
621 ret
= left
.u
.d
> right
.u
.d
;
624 ret
= left
.u
.d
>= right
.u
.d
;
635 ret
= left
.u
.b
== right
.u
.b
;
638 case FcOpNotContains
:
639 ret
= left
.u
.b
!= right
.u
.b
;
649 ret
= FcStrCmpIgnoreCase (left
.u
.s
, right
.u
.s
) == 0;
652 ret
= FcStrStrIgnoreCase (left
.u
.s
, right
.u
.s
) != 0;
655 ret
= FcStrCmpIgnoreCase (left
.u
.s
, right
.u
.s
) != 0;
657 case FcOpNotContains
:
658 ret
= FcStrCmpIgnoreCase (left
.u
.s
, right
.u
.s
) == 0;
669 ret
= FcMatrixEqual (left
.u
.m
, right
.u
.m
);
672 case FcOpNotContains
:
673 ret
= !FcMatrixEqual (left
.u
.m
, right
.u
.m
);
683 /* left contains right if right is a subset of left */
684 ret
= FcCharSetIsSubset (right
.u
.c
, left
.u
.c
);
686 case FcOpNotContains
:
687 /* left contains right if right is a subset of left */
688 ret
= !FcCharSetIsSubset (right
.u
.c
, left
.u
.c
);
691 ret
= FcCharSetEqual (left
.u
.c
, right
.u
.c
);
694 ret
= !FcCharSetEqual (left
.u
.c
, right
.u
.c
);
704 ret
= FcLangSetContains (left
.u
.l
, right
.u
.l
);
706 case FcOpNotContains
:
707 ret
= !FcLangSetContains (left
.u
.l
, right
.u
.l
);
710 ret
= FcLangSetEqual (left
.u
.l
, right
.u
.l
);
713 ret
= !FcLangSetEqual (left
.u
.l
, right
.u
.l
);
735 ret
= left
.u
.f
== right
.u
.f
;
738 case FcOpNotContains
:
739 ret
= left
.u
.f
!= right
.u
.f
;
749 if (op
== FcOpNotEqual
|| op
== FcOpNotContains
)
756 #define _FcDoubleFloor(d) ((int) (d))
757 #define _FcDoubleCeil(d) ((double) (int) (d) == (d) ? (int) (d) : (int) ((d) + 1))
758 #define FcDoubleFloor(d) ((d) >= 0 ? _FcDoubleFloor(d) : -_FcDoubleCeil(-(d)))
759 #define FcDoubleCeil(d) ((d) >= 0 ? _FcDoubleCeil(d) : -_FcDoubleFloor(-(d)))
760 #define FcDoubleRound(d) FcDoubleFloor ((d) + 0.5)
761 #define FcDoubleTrunc(d) ((d) >= 0 ? _FcDoubleFloor (d) : -_FcDoubleFloor (-(d)))
764 FcConfigEvaluate (FcPattern
*p
, FcExpr
*e
)
772 v
.type
= FcTypeInteger
;
776 v
.type
= FcTypeDouble
;
780 v
.type
= FcTypeString
;
781 v
.u
.s
= FcObjectStaticName(e
->u
.sval
);
785 v
.type
= FcTypeMatrix
;
790 v
.type
= FcTypeCharSet
;
799 r
= FcPatternGet (p
, e
->u
.field
, 0, &v
);
800 if (r
!= FcResultMatch
)
804 if (FcNameConstant (e
->u
.constant
, &v
.u
.i
))
805 v
.type
= FcTypeInteger
;
810 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
811 if (vl
.type
== FcTypeBool
)
814 v
= FcConfigEvaluate (p
, e
->u
.tree
.right
->u
.tree
.left
);
816 v
= FcConfigEvaluate (p
, e
->u
.tree
.right
->u
.tree
.right
);
829 case FcOpNotContains
:
831 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
832 vr
= FcConfigEvaluate (p
, e
->u
.tree
.right
);
834 v
.u
.b
= FcConfigCompareValue (&vl
, e
->op
, &vr
);
844 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
845 vr
= FcConfigEvaluate (p
, e
->u
.tree
.right
);
846 vl
= FcConfigPromote (vl
, vr
);
847 vr
= FcConfigPromote (vr
, vl
);
848 if (vl
.type
== vr
.type
)
854 v
.type
= FcTypeDouble
;
855 v
.u
.d
= vl
.u
.d
+ vr
.u
.d
;
858 v
.type
= FcTypeDouble
;
859 v
.u
.d
= vl
.u
.d
- vr
.u
.d
;
862 v
.type
= FcTypeDouble
;
863 v
.u
.d
= vl
.u
.d
* vr
.u
.d
;
866 v
.type
= FcTypeDouble
;
867 v
.u
.d
= vl
.u
.d
/ vr
.u
.d
;
873 if (v
.type
== FcTypeDouble
&&
874 v
.u
.d
== (double) (int) v
.u
.d
)
876 v
.type
= FcTypeInteger
;
884 v
.u
.b
= vl
.u
.b
|| vr
.u
.b
;
888 v
.u
.b
= vl
.u
.b
&& vr
.u
.b
;
898 v
.type
= FcTypeString
;
899 v
.u
.s
= FcObjectStaticName (FcStrPlus (vl
.u
.s
, vr
.u
.s
));
912 v
.type
= FcTypeMatrix
;
913 m
= malloc (sizeof (FcMatrix
));
916 FcMemAlloc (FC_MEM_MATRIX
, sizeof (FcMatrix
));
917 FcMatrixMultiply (m
, vl
.u
.m
, vr
.u
.m
);
941 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
954 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
960 v
.type
= FcTypeInteger
;
961 v
.u
.i
= FcDoubleFloor (vl
.u
.d
);
970 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
976 v
.type
= FcTypeInteger
;
977 v
.u
.i
= FcDoubleCeil (vl
.u
.d
);
986 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
992 v
.type
= FcTypeInteger
;
993 v
.u
.i
= FcDoubleRound (vl
.u
.d
);
1002 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
1008 v
.type
= FcTypeInteger
;
1009 v
.u
.i
= FcDoubleTrunc (vl
.u
.d
);
1012 v
.type
= FcTypeVoid
;
1015 FcValueDestroy (vl
);
1018 v
.type
= FcTypeVoid
;
1024 static FcValueList
*
1025 FcConfigMatchValueList (FcPattern
*p
,
1027 FcValueList
*values
)
1029 FcValueList
*ret
= 0;
1030 FcExpr
*e
= t
->expr
;
1036 /* Compute the value of the match expression */
1037 if (e
->op
== FcOpComma
)
1039 value
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
1040 e
= e
->u
.tree
.right
;
1044 value
= FcConfigEvaluate (p
, e
);
1048 for (v
= values
; v
; v
= FcValueListPtrU(v
->next
))
1050 /* Compare the pattern value to the match expression value */
1051 if (FcConfigCompareValue (&v
->value
, t
->op
, &value
))
1058 if (t
->qual
== FcQualAll
)
1065 FcValueDestroy (value
);
1070 static FcValueList
*
1071 FcConfigValues (FcPattern
*p
, FcExpr
*e
, FcValueBinding binding
)
1078 l
= (FcValueList
*) malloc (sizeof (FcValueList
));
1081 FcMemAlloc (FC_MEM_VALLIST
, sizeof (FcValueList
));
1082 if (e
->op
== FcOpComma
)
1084 l
->value
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
1085 l
->next
= FcValueListPtrCreateDynamic(FcConfigValues (p
, e
->u
.tree
.right
, binding
));
1089 l
->value
= FcConfigEvaluate (p
, e
);
1090 l
->next
= FcValueListPtrCreateDynamic(0);
1092 l
->binding
= binding
;
1093 lp
= FcValueListPtrCreateDynamic(l
);
1094 while (FcValueListPtrU(lp
) && FcValueListPtrU(lp
)->value
.type
== FcTypeVoid
)
1096 FcValueListPtr next
= FcValueListPtrU(lp
)->next
;
1098 if (lp
.bank
== FC_BANK_DYNAMIC
)
1100 FcMemFree (FC_MEM_VALLIST
, sizeof (FcValueList
));
1109 FcConfigAdd (FcValueListPtr
*head
,
1110 FcValueList
*position
,
1114 FcValueListPtr
*prev
, last
, v
;
1115 FcValueBinding sameBinding
;
1118 sameBinding
= position
->binding
;
1120 sameBinding
= FcValueBindingWeak
;
1121 for (v
= FcValueListPtrCreateDynamic(new); FcValueListPtrU(v
);
1122 v
= FcValueListPtrU(v
)->next
)
1123 if (FcValueListPtrU(v
)->binding
== FcValueBindingSame
)
1124 FcValueListPtrU(v
)->binding
= sameBinding
;
1128 prev
= &position
->next
;
1130 for (prev
= head
; FcValueListPtrU(*prev
);
1131 prev
= &(FcValueListPtrU(*prev
)->next
))
1138 for (prev
= head
; FcValueListPtrU(*prev
);
1139 prev
= &(FcValueListPtrU(*prev
)->next
))
1141 if (FcValueListPtrU(*prev
) == position
)
1148 if (FcDebug () & FC_DBG_EDIT
)
1150 if (!FcValueListPtrU(*prev
))
1151 printf ("position not on list\n");
1155 if (FcDebug () & FC_DBG_EDIT
)
1157 printf ("%s list before ", append
? "Append" : "Prepend");
1158 FcValueListPrint (*head
);
1164 last
= FcValueListPtrCreateDynamic(new);
1165 while (FcValueListPtrU(FcValueListPtrU(last
)->next
))
1166 last
= FcValueListPtrU(last
)->next
;
1168 FcValueListPtrU(last
)->next
= *prev
;
1169 *prev
= FcValueListPtrCreateDynamic(new);
1172 if (FcDebug () & FC_DBG_EDIT
)
1174 printf ("%s list after ", append
? "Append" : "Prepend");
1175 FcValueListPrint (*head
);
1183 FcConfigDel (FcValueListPtr
*head
,
1184 FcValueList
*position
)
1186 FcValueListPtr
*prev
;
1188 for (prev
= head
; FcValueListPtrU(*prev
);
1189 prev
= &(FcValueListPtrU(*prev
)->next
))
1191 if (FcValueListPtrU(*prev
) == position
)
1193 *prev
= position
->next
;
1194 position
->next
= FcValueListPtrCreateDynamic(0);
1195 FcValueListDestroy (FcValueListPtrCreateDynamic(position
));
1202 FcConfigPatternAdd (FcPattern
*p
,
1209 FcPatternElt
*e
= FcPatternInsertElt (p
, object
);
1213 FcConfigAdd (&e
->values
, 0, append
, list
);
1218 * Delete all values associated with a field
1221 FcConfigPatternDel (FcPattern
*p
,
1224 FcPatternElt
*e
= FcPatternFindElt (p
, object
);
1227 while (FcValueListPtrU(e
->values
))
1228 FcConfigDel (&e
->values
, FcValueListPtrU(e
->values
));
1232 FcConfigPatternCanon (FcPattern
*p
,
1235 FcPatternElt
*e
= FcPatternFindElt (p
, object
);
1238 if (!FcValueListPtrU(e
->values
))
1239 FcPatternDel (p
, object
);
1243 FcConfigSubstituteWithPat (FcConfig
*config
,
1258 config
= FcConfigGetCurrent ();
1263 st
= (FcSubState
*) malloc (config
->maxObjects
* sizeof (FcSubState
));
1264 if (!st
&& config
->maxObjects
)
1266 FcMemAlloc (FC_MEM_SUBSTATE
, config
->maxObjects
* sizeof (FcSubState
));
1268 if (FcDebug () & FC_DBG_EDIT
)
1270 printf ("FcConfigSubstitute ");
1273 if (kind
== FcMatchPattern
)
1274 s
= config
->substPattern
;
1276 s
= config
->substFont
;
1277 for (; s
; s
= s
->next
)
1280 * Check the tests to see if
1281 * they all match the pattern
1283 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1285 if (FcDebug () & FC_DBG_EDIT
)
1287 printf ("FcConfigSubstitute test ");
1291 if (kind
== FcMatchFont
&& t
->kind
== FcMatchPattern
)
1296 st
[i
].elt
= FcPatternFindElt (m
, t
->field
);
1300 * If there's no such field in the font,
1301 * then FcQualAll matches while FcQualAny does not
1305 if (t
->qual
== FcQualAll
)
1314 * Check to see if there is a match, mark the location
1315 * to apply match-relative edits
1317 st
[i
].value
= FcConfigMatchValueList (m
, t
, FcValueListPtrU(st
[i
].elt
->values
));
1320 if (t
->qual
== FcQualFirst
&& st
[i
].value
!= FcValueListPtrU(st
[i
].elt
->values
))
1322 if (t
->qual
== FcQualNotFirst
&& st
[i
].value
== FcValueListPtrU(st
[i
].elt
->values
))
1327 if (FcDebug () & FC_DBG_EDIT
)
1328 printf ("No match\n");
1331 if (FcDebug () & FC_DBG_EDIT
)
1333 printf ("Substitute ");
1336 for (e
= s
->edit
; e
; e
= e
->next
)
1339 * Evaluate the list of expressions
1341 l
= FcConfigValues (p
, e
->expr
, e
->binding
);
1343 * Locate any test associated with this field, skipping
1344 * tests associated with the pattern when substituting in
1347 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1349 if ((t
->kind
== FcMatchFont
|| kind
== FcMatchPattern
) &&
1350 !FcStrCmpIgnoreCase ((FcChar8
*) t
->field
,
1351 (FcChar8
*) e
->field
))
1354 * KLUDGE - the pattern may have been reallocated or
1355 * things may have been inserted or deleted above
1356 * this element by other edits. Go back and find
1359 if (e
!= s
->edit
&& st
[i
].elt
)
1360 st
[i
].elt
= FcPatternFindElt (p
, t
->field
);
1369 * If there was a test, then replace the matched
1370 * value with the new list of values
1374 FcValueList
*thisValue
= st
[i
].value
;
1375 FcValueList
*nextValue
= thisValue
? FcValueListPtrU(thisValue
->next
) : 0;
1378 * Append the new list of values after the current value
1380 FcConfigAdd (&st
[i
].elt
->values
, thisValue
, FcTrue
, l
);
1382 * Delete the marked value
1384 FcConfigDel (&st
[i
].elt
->values
, thisValue
);
1386 * Adjust any pointers into the value list to ensure
1387 * future edits occur at the same place
1389 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1391 if (st
[i
].value
== thisValue
)
1392 st
[i
].value
= nextValue
;
1396 /* fall through ... */
1397 case FcOpAssignReplace
:
1399 * Delete all of the values and insert
1402 FcConfigPatternDel (p
, e
->field
);
1403 FcConfigPatternAdd (p
, e
->field
, l
, FcTrue
);
1405 * Adjust any pointers into the value list as they no
1406 * longer point to anything valid
1410 FcPatternElt
*thisElt
= st
[i
].elt
;
1411 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1413 if (st
[i
].elt
== thisElt
)
1421 FcConfigAdd (&st
[i
].elt
->values
, st
[i
].value
, FcFalse
, l
);
1424 /* fall through ... */
1425 case FcOpPrependFirst
:
1426 FcConfigPatternAdd (p
, e
->field
, l
, FcFalse
);
1431 FcConfigAdd (&st
[i
].elt
->values
, st
[i
].value
, FcTrue
, l
);
1434 /* fall through ... */
1435 case FcOpAppendLast
:
1436 FcConfigPatternAdd (p
, e
->field
, l
, FcTrue
);
1443 * Now go through the pattern and eliminate
1444 * any properties without data
1446 for (e
= s
->edit
; e
; e
= e
->next
)
1447 FcConfigPatternCanon (p
, e
->field
);
1449 if (FcDebug () & FC_DBG_EDIT
)
1451 printf ("FcConfigSubstitute edit");
1455 FcMemFree (FC_MEM_SUBSTATE
, config
->maxObjects
* sizeof (FcSubState
));
1457 if (FcDebug () & FC_DBG_EDIT
)
1459 printf ("FcConfigSubstitute done");
1466 FcConfigSubstitute (FcConfig
*config
,
1470 return FcConfigSubstituteWithPat (config
, p
, 0, kind
);
1473 #if defined (_WIN32) && (defined (PIC) || defined (DLL_EXPORT))
1475 static FcChar8 fontconfig_path
[1000] = "";
1478 DllMain (HINSTANCE hinstDLL
,
1484 switch (fdwReason
) {
1485 case DLL_PROCESS_ATTACH
:
1486 if (!GetModuleFileName ((HMODULE
) hinstDLL
, fontconfig_path
,
1487 sizeof (fontconfig_path
)))
1490 /* If the fontconfig DLL is in a "bin" or "lib" subfolder,
1491 * assume it's a Unix-style installation tree, and use
1492 * "etc/fonts" in there as FONTCONFIG_PATH. Otherwise use the
1493 * folder where the DLL is as FONTCONFIG_PATH.
1495 p
= strrchr (fontconfig_path
, '\\');
1499 p
= strrchr (fontconfig_path
, '\\');
1500 if (p
&& (FcStrCmpIgnoreCase (p
+ 1, "bin") == 0 ||
1501 FcStrCmpIgnoreCase (p
+ 1, "lib") == 0))
1503 strcat (fontconfig_path
, "\\etc\\fonts");
1506 fontconfig_path
[0] = '\0';
1514 #undef FONTCONFIG_PATH
1515 #define FONTCONFIG_PATH fontconfig_path
1517 #else /* !(_WIN32 && PIC) */
1519 #endif /* !(_WIN32 && PIC) */
1521 #ifndef FONTCONFIG_FILE
1522 #define FONTCONFIG_FILE "fonts.conf"
1526 FcConfigFileExists (const FcChar8
*dir
, const FcChar8
*file
)
1531 dir
= (FcChar8
*) "";
1532 path
= malloc (strlen ((char *) dir
) + 1 + strlen ((char *) file
) + 1);
1536 strcpy ((char *) path
, (const char *) dir
);
1537 /* make sure there's a single separator */
1539 if ((!path
[0] || (path
[strlen((char *) path
)-1] != '/' &&
1540 path
[strlen((char *) path
)-1] != '\\')) &&
1543 (isalpha (file
[0]) && file
[1] == ':' && (file
[2] == '/' || file
[2] == '\\'))))
1544 strcat ((char *) path
, "\\");
1546 if ((!path
[0] || path
[strlen((char *) path
)-1] != '/') && file
[0] != '/')
1547 strcat ((char *) path
, "/");
1549 strcat ((char *) path
, (char *) file
);
1551 FcMemAlloc (FC_MEM_STRING
, strlen ((char *) path
) + 1);
1552 if (access ((char *) path
, R_OK
) == 0)
1560 FcConfigGetPath (void)
1563 FcChar8
*env
, *e
, *colon
;
1568 npath
= 2; /* default dir + null */
1569 env
= (FcChar8
*) getenv ("FONTCONFIG_PATH");
1575 if (*e
++ == FC_SEARCH_PATH_SEPARATOR
)
1578 path
= calloc (npath
, sizeof (FcChar8
*));
1588 colon
= (FcChar8
*) strchr ((char *) e
, FC_SEARCH_PATH_SEPARATOR
);
1590 colon
= e
+ strlen ((char *) e
);
1591 path
[i
] = malloc (colon
- e
+ 1);
1594 strncpy ((char *) path
[i
], (const char *) e
, colon
- e
);
1595 path
[i
][colon
- e
] = '\0';
1604 dir
= (FcChar8
*) FONTCONFIG_PATH
;
1605 path
[i
] = malloc (strlen ((char *) dir
) + 1);
1608 strcpy ((char *) path
[i
], (const char *) dir
);
1612 for (i
= 0; path
[i
]; i
++)
1620 FcConfigFreePath (FcChar8
**path
)
1624 for (p
= path
; *p
; p
++)
1629 static FcBool _FcConfigHomeEnabled
= FcTrue
;
1634 if (_FcConfigHomeEnabled
)
1636 char *home
= getenv ("HOME");
1640 home
= getenv ("USERPROFILE");
1649 FcConfigEnableHome (FcBool enable
)
1651 FcBool prev
= _FcConfigHomeEnabled
;
1652 _FcConfigHomeEnabled
= enable
;
1657 FcConfigFilename (const FcChar8
*url
)
1659 FcChar8
*file
, *dir
, **path
, **p
;
1663 url
= (FcChar8
*) getenv ("FONTCONFIG_FILE");
1665 url
= (FcChar8
*) FONTCONFIG_FILE
;
1670 if (isalpha (*url
) &&
1672 (url
[2] == '/' || url
[2] == '\\'))
1678 dir
= FcConfigHome ();
1680 file
= FcConfigFileExists (dir
, url
+ 1);
1689 file
= FcConfigFileExists (0, url
);
1692 path
= FcConfigGetPath ();
1695 for (p
= path
; *p
; p
++)
1697 file
= FcConfigFileExists (*p
, url
);
1701 FcConfigFreePath (path
);
1708 * Manage the application-specific fonts
1712 FcConfigAppFontAddFile (FcConfig
*config
,
1713 const FcChar8
*file
)
1722 config
= FcConfigGetCurrent ();
1727 subdirs
= FcStrSetCreate ();
1731 set
= FcConfigGetFonts (config
, FcSetApplication
);
1734 set
= FcFontSetCreate ();
1737 FcStrSetDestroy (subdirs
);
1740 FcConfigSetFonts (config
, set
, FcSetApplication
);
1743 if (!FcFileScanConfig (set
, subdirs
, 0, config
->blanks
, file
, FcFalse
, config
))
1745 FcStrSetDestroy (subdirs
);
1748 if ((sublist
= FcStrListCreate (subdirs
)))
1750 while ((subdir
= FcStrListNext (sublist
)))
1752 FcConfigAppFontAddDir (config
, subdir
);
1754 FcStrListDone (sublist
);
1760 FcConfigAppFontAddDir (FcConfig
*config
,
1770 config
= FcConfigGetCurrent ();
1774 subdirs
= FcStrSetCreate ();
1778 set
= FcConfigGetFonts (config
, FcSetApplication
);
1781 set
= FcFontSetCreate ();
1784 FcStrSetDestroy (subdirs
);
1787 FcConfigSetFonts (config
, set
, FcSetApplication
);
1790 if (!FcDirScanConfig (set
, subdirs
, 0, config
->blanks
, dir
, FcFalse
, config
))
1792 FcStrSetDestroy (subdirs
);
1795 if ((sublist
= FcStrListCreate (subdirs
)))
1797 while ((subdir
= FcStrListNext (sublist
)))
1799 FcConfigAppFontAddDir (config
, subdir
);
1801 FcStrListDone (sublist
);
1807 FcConfigAppFontClear (FcConfig
*config
)
1811 config
= FcConfigGetCurrent ();
1816 FcConfigSetFonts (config
, 0, FcSetApplication
);
1820 * Manage filename-based font source selectors
1824 FcConfigGlobAdd (FcConfig
*config
,
1825 const FcChar8
*glob
,
1828 FcStrSet
*set
= accept
? config
->acceptGlobs
: config
->rejectGlobs
;
1830 return FcStrSetAdd (set
, glob
);
1834 FcConfigGlobMatch (const FcChar8
*glob
,
1835 const FcChar8
*string
)
1839 while ((c
= *glob
++))
1843 /* short circuit common case */
1846 /* short circuit another common case */
1847 if (strchr ((char *) glob
, '*') == 0)
1848 string
+= strlen ((char *) string
) - strlen ((char *) glob
);
1851 if (FcConfigGlobMatch (glob
, string
))
1857 if (*string
++ == '\0')
1866 return *string
== '\0';
1870 FcConfigGlobsMatch (const FcStrSet
*globs
,
1871 const FcChar8
*string
)
1875 for (i
= 0; i
< globs
->num
; i
++)
1876 if (FcConfigGlobMatch (globs
->strs
[i
], string
))
1882 FcConfigAcceptFilename (FcConfig
*config
,
1883 const FcChar8
*filename
)
1885 if (FcConfigGlobsMatch (config
->acceptGlobs
, filename
))
1887 if (FcConfigGlobsMatch (config
->rejectGlobs
, filename
))
1893 * Manage font-pattern based font source selectors
1897 FcConfigPatternsAdd (FcConfig
*config
,
1901 FcFontSet
*set
= accept
? config
->acceptPatterns
: config
->rejectPatterns
;
1903 return FcFontSetAdd (set
, pattern
);
1907 FcConfigPatternsMatch (const FcFontSet
*patterns
,
1908 const FcPattern
*font
)
1912 for (i
= 0; i
< patterns
->nfont
; i
++)
1913 if (FcListPatternMatchAny (patterns
->fonts
[i
], font
))
1919 FcConfigAcceptFont (FcConfig
*config
,
1920 const FcPattern
*font
)
1922 if (FcConfigPatternsMatch (config
->acceptPatterns
, font
))
1924 if (FcConfigPatternsMatch (config
->rejectPatterns
, font
))