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
)
251 FcGlobalCache
*cache
;
255 fonts
= FcFontSetCreate ();
259 cache
= FcGlobalCacheCreate ();
264 FcGlobalCacheLoad (cache
, config
->cache
);
266 list
= FcConfigGetFontDirs (config
);
270 while ((dir
= FcStrListNext (list
)))
272 if (FcDebug () & FC_DBG_FONTSET
)
273 printf ("scan dir %s\n", dir
);
274 FcDirScanConfig (fonts
, config
->fontDirs
, cache
,
275 config
->blanks
, dir
, FcFalse
, config
);
278 FcStrListDone (list
);
280 if (FcDebug () & FC_DBG_FONTSET
)
281 FcFontSetPrint (fonts
);
284 FcGlobalCacheSave (cache
, config
->cache
);
285 FcGlobalCacheDestroy (cache
);
287 FcConfigSetFonts (config
, fonts
, FcSetSystem
);
291 FcFontSetDestroy (fonts
);
297 FcConfigSetCurrent (FcConfig
*config
)
300 if (!FcConfigBuildFonts (config
))
304 FcConfigDestroy (_fcConfig
);
310 FcConfigGetCurrent (void)
319 FcConfigAddConfigDir (FcConfig
*config
,
322 return FcStrSetAddFilename (config
->configDirs
, d
);
326 FcConfigGetConfigDirs (FcConfig
*config
)
330 config
= FcConfigGetCurrent ();
334 return FcStrListCreate (config
->configDirs
);
338 FcConfigAddFontDir (FcConfig
*config
,
341 return FcStrSetAddFilename (config
->fontDirs
, d
);
345 FcConfigAddDir (FcConfig
*config
,
348 return (FcConfigAddConfigDir (config
, d
) &&
349 FcConfigAddFontDir (config
, d
));
353 FcConfigGetFontDirs (FcConfig
*config
)
357 config
= FcConfigGetCurrent ();
361 return FcStrListCreate (config
->fontDirs
);
365 FcConfigAddConfigFile (FcConfig
*config
,
369 FcChar8
*file
= FcConfigFilename (f
);
374 ret
= FcStrSetAdd (config
->configFiles
, file
);
380 FcConfigGetConfigFiles (FcConfig
*config
)
384 config
= FcConfigGetCurrent ();
388 return FcStrListCreate (config
->configFiles
);
392 FcConfigSetCache (FcConfig
*config
,
395 FcChar8
*new = FcStrCopyFilename (c
);
400 FcStrFree (config
->cache
);
406 FcConfigGetCache (FcConfig
*config
)
410 config
= FcConfigGetCurrent ();
414 return config
->cache
;
418 FcConfigGetFonts (FcConfig
*config
,
423 config
= FcConfigGetCurrent ();
427 return config
->fonts
[set
];
431 FcConfigSetFonts (FcConfig
*config
,
435 if (config
->fonts
[set
])
436 FcFontSetDestroy (config
->fonts
[set
]);
437 config
->fonts
[set
] = fonts
;
443 FcConfigGetBlanks (FcConfig
*config
)
447 config
= FcConfigGetCurrent ();
451 return config
->blanks
;
455 FcConfigAddBlank (FcConfig
*config
,
463 b
= FcBlanksCreate ();
467 if (!FcBlanksAdd (b
, blank
))
474 FcConfigGetRescanInverval (FcConfig
*config
)
478 config
= FcConfigGetCurrent ();
482 return config
->rescanInterval
;
486 FcConfigSetRescanInverval (FcConfig
*config
, int rescanInterval
)
490 config
= FcConfigGetCurrent ();
494 config
->rescanInterval
= rescanInterval
;
499 FcConfigAddEdit (FcConfig
*config
,
504 FcSubst
*subst
, **prev
;
508 subst
= (FcSubst
*) malloc (sizeof (FcSubst
));
511 FcMemAlloc (FC_MEM_SUBST
, sizeof (FcSubst
));
512 if (kind
== FcMatchPattern
)
513 prev
= &config
->substPattern
;
515 prev
= &config
->substFont
;
516 for (; *prev
; prev
= &(*prev
)->next
);
522 for (t
= test
; t
; t
= t
->next
)
524 if (t
->kind
== FcMatchDefault
)
528 if (config
->maxObjects
< num
)
529 config
->maxObjects
= num
;
530 if (FcDebug () & FC_DBG_EDIT
)
532 printf ("Add Subst ");
533 FcSubstPrint (subst
);
538 typedef struct _FcSubState
{
544 FcConfigPromote (FcValue v
, FcValue u
)
546 if (v
.type
== FcTypeInteger
)
548 v
.type
= FcTypeDouble
;
549 v
.u
.d
= (double) v
.u
.i
;
551 else if (v
.type
== FcTypeVoid
&& u
.type
== FcTypeMatrix
)
553 v
.u
.m
= &FcIdentityMatrix
;
554 v
.type
= FcTypeMatrix
;
556 else if (v
.type
== FcTypeString
&& u
.type
== FcTypeLangSet
)
558 v
.u
.l
= FcLangSetPromote (v
.u
.s
);
559 v
.type
= FcTypeLangSet
;
565 FcConfigCompareValue (const FcValue left_o
,
567 const FcValue right_o
)
569 FcValue left
= left_o
;
570 FcValue right
= right_o
;
571 FcBool ret
= FcFalse
;
573 left
= FcConfigPromote (left
, right
);
574 right
= FcConfigPromote (right
, left
);
575 if (left
.type
== right
.type
)
579 break; /* FcConfigPromote prevents this from happening */
585 ret
= left
.u
.d
== right
.u
.d
;
588 case FcOpNotContains
:
589 ret
= left
.u
.d
!= right
.u
.d
;
592 ret
= left
.u
.d
< right
.u
.d
;
595 ret
= left
.u
.d
<= right
.u
.d
;
598 ret
= left
.u
.d
> right
.u
.d
;
601 ret
= left
.u
.d
>= right
.u
.d
;
612 ret
= left
.u
.b
== right
.u
.b
;
615 case FcOpNotContains
:
616 ret
= left
.u
.b
!= right
.u
.b
;
626 ret
= FcStrCmpIgnoreCase (left
.u
.s
, right
.u
.s
) == 0;
629 ret
= FcStrStrIgnoreCase (left
.u
.s
, right
.u
.s
) != 0;
632 case FcOpNotContains
:
633 ret
= FcStrCmpIgnoreCase (left
.u
.s
, right
.u
.s
) != 0;
644 ret
= FcMatrixEqual (left
.u
.m
, right
.u
.m
);
647 case FcOpNotContains
:
648 ret
= !FcMatrixEqual (left
.u
.m
, right
.u
.m
);
658 /* left contains right if right is a subset of left */
659 ret
= FcCharSetIsSubset (right
.u
.c
, left
.u
.c
);
661 case FcOpNotContains
:
662 /* left contains right if right is a subset of left */
663 ret
= !FcCharSetIsSubset (right
.u
.c
, left
.u
.c
);
666 ret
= FcCharSetEqual (left
.u
.c
, right
.u
.c
);
669 ret
= !FcCharSetEqual (left
.u
.c
, right
.u
.c
);
679 ret
= FcLangSetContains (left
.u
.l
, right
.u
.l
);
681 case FcOpNotContains
:
682 ret
= !FcLangSetContains (left
.u
.l
, right
.u
.l
);
685 ret
= FcLangSetEqual (left
.u
.l
, right
.u
.l
);
688 ret
= !FcLangSetEqual (left
.u
.l
, right
.u
.l
);
710 ret
= left
.u
.f
== right
.u
.f
;
713 case FcOpNotContains
:
714 ret
= left
.u
.f
!= right
.u
.f
;
724 if (op
== FcOpNotEqual
|| op
== FcOpNotContains
)
731 #define _FcDoubleFloor(d) ((int) (d))
732 #define _FcDoubleCeil(d) ((double) (int) (d) == (d) ? (int) (d) : (int) ((d) + 1))
733 #define FcDoubleFloor(d) ((d) >= 0 ? _FcDoubleFloor(d) : -_FcDoubleCeil(-(d)))
734 #define FcDoubleCeil(d) ((d) >= 0 ? _FcDoubleCeil(d) : -_FcDoubleFloor(-(d)))
735 #define FcDoubleRound(d) FcDoubleFloor ((d) + 0.5)
736 #define FcDoubleTrunc(d) ((d) >= 0 ? _FcDoubleFloor (d) : -_FcDoubleFloor (-(d)))
739 FcConfigEvaluate (FcPattern
*p
, FcExpr
*e
)
747 v
.type
= FcTypeInteger
;
751 v
.type
= FcTypeDouble
;
755 v
.type
= FcTypeString
;
760 v
.type
= FcTypeMatrix
;
765 v
.type
= FcTypeCharSet
;
774 r
= FcPatternGet (p
, e
->u
.field
, 0, &v
);
775 if (r
!= FcResultMatch
)
779 if (FcNameConstant (e
->u
.constant
, &v
.u
.i
))
780 v
.type
= FcTypeInteger
;
785 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
786 if (vl
.type
== FcTypeBool
)
789 v
= FcConfigEvaluate (p
, e
->u
.tree
.right
->u
.tree
.left
);
791 v
= FcConfigEvaluate (p
, e
->u
.tree
.right
->u
.tree
.right
);
804 case FcOpNotContains
:
806 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
807 vr
= FcConfigEvaluate (p
, e
->u
.tree
.right
);
809 v
.u
.b
= FcConfigCompareValue (vl
, e
->op
, vr
);
819 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
820 vr
= FcConfigEvaluate (p
, e
->u
.tree
.right
);
821 vl
= FcConfigPromote (vl
, vr
);
822 vr
= FcConfigPromote (vr
, vl
);
823 if (vl
.type
== vr
.type
)
829 v
.type
= FcTypeDouble
;
830 v
.u
.d
= vl
.u
.d
+ vr
.u
.d
;
833 v
.type
= FcTypeDouble
;
834 v
.u
.d
= vl
.u
.d
- vr
.u
.d
;
837 v
.type
= FcTypeDouble
;
838 v
.u
.d
= vl
.u
.d
* vr
.u
.d
;
841 v
.type
= FcTypeDouble
;
842 v
.u
.d
= vl
.u
.d
/ vr
.u
.d
;
848 if (v
.type
== FcTypeDouble
&&
849 v
.u
.d
== (double) (int) v
.u
.d
)
851 v
.type
= FcTypeInteger
;
859 v
.u
.b
= vl
.u
.b
|| vr
.u
.b
;
863 v
.u
.b
= vl
.u
.b
&& vr
.u
.b
;
873 v
.type
= FcTypeString
;
874 v
.u
.s
= FcStrPlus (vl
.u
.s
, vr
.u
.s
);
886 v
.type
= FcTypeMatrix
;
887 m
= malloc (sizeof (FcMatrix
));
890 FcMemAlloc (FC_MEM_MATRIX
, sizeof (FcMatrix
));
891 FcMatrixMultiply (m
, vl
.u
.m
, vr
.u
.m
);
915 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
928 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
934 v
.type
= FcTypeInteger
;
935 v
.u
.i
= FcDoubleFloor (vl
.u
.d
);
944 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
950 v
.type
= FcTypeInteger
;
951 v
.u
.i
= FcDoubleCeil (vl
.u
.d
);
960 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
966 v
.type
= FcTypeInteger
;
967 v
.u
.i
= FcDoubleRound (vl
.u
.d
);
976 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
982 v
.type
= FcTypeInteger
;
983 v
.u
.i
= FcDoubleTrunc (vl
.u
.d
);
999 FcConfigMatchValueList (FcPattern
*p
,
1001 FcValueList
*values
)
1003 FcValueList
*ret
= 0;
1004 FcExpr
*e
= t
->expr
;
1010 /* Compute the value of the match expression */
1011 if (e
->op
== FcOpComma
)
1013 value
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
1014 e
= e
->u
.tree
.right
;
1018 value
= FcConfigEvaluate (p
, e
);
1022 for (v
= values
; v
; v
= v
->next
)
1024 /* Compare the pattern value to the match expression value */
1025 if (FcConfigCompareValue (v
->value
, t
->op
, value
))
1032 if (t
->qual
== FcQualAll
)
1039 FcValueDestroy (value
);
1044 static FcValueList
*
1045 FcConfigValues (FcPattern
*p
, FcExpr
*e
, FcValueBinding binding
)
1051 l
= (FcValueList
*) malloc (sizeof (FcValueList
));
1054 FcMemAlloc (FC_MEM_VALLIST
, sizeof (FcValueList
));
1055 if (e
->op
== FcOpComma
)
1057 l
->value
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
1058 l
->next
= FcConfigValues (p
, e
->u
.tree
.right
, binding
);
1062 l
->value
= FcConfigEvaluate (p
, e
);
1065 l
->binding
= binding
;
1066 while (l
&& l
->value
.type
== FcTypeVoid
)
1068 FcValueList
*next
= l
->next
;
1070 FcMemFree (FC_MEM_VALLIST
, sizeof (FcValueList
));
1078 FcConfigAdd (FcValueList
**head
,
1079 FcValueList
*position
,
1083 FcValueList
**prev
, *last
, *v
;
1084 FcValueBinding sameBinding
;
1087 sameBinding
= position
->binding
;
1089 sameBinding
= FcValueBindingWeak
;
1090 for (v
= new; v
; v
= v
->next
)
1091 if (v
->binding
== FcValueBindingSame
)
1092 v
->binding
= sameBinding
;
1096 prev
= &position
->next
;
1098 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1105 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1107 if (*prev
== position
)
1114 if (FcDebug () & FC_DBG_EDIT
)
1117 printf ("position not on list\n");
1121 if (FcDebug () & FC_DBG_EDIT
)
1123 printf ("%s list before ", append
? "Append" : "Prepend");
1124 FcValueListPrint (*head
);
1138 if (FcDebug () & FC_DBG_EDIT
)
1140 printf ("%s list after ", append
? "Append" : "Prepend");
1141 FcValueListPrint (*head
);
1149 FcConfigDel (FcValueList
**head
,
1150 FcValueList
*position
)
1154 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1156 if (*prev
== position
)
1158 *prev
= position
->next
;
1160 FcValueListDestroy (position
);
1167 FcConfigPatternAdd (FcPattern
*p
,
1174 FcPatternElt
*e
= FcPatternInsertElt (p
, object
);
1178 FcConfigAdd (&e
->values
, 0, append
, list
);
1183 * Delete all values associated with a field
1186 FcConfigPatternDel (FcPattern
*p
,
1189 FcPatternElt
*e
= FcPatternFindElt (p
, object
);
1193 FcConfigDel (&e
->values
, e
->values
);
1197 FcConfigPatternCanon (FcPattern
*p
,
1200 FcPatternElt
*e
= FcPatternFindElt (p
, object
);
1204 FcPatternDel (p
, object
);
1208 FcConfigSubstituteWithPat (FcConfig
*config
,
1223 config
= FcConfigGetCurrent ();
1228 st
= (FcSubState
*) malloc (config
->maxObjects
* sizeof (FcSubState
));
1229 if (!st
&& config
->maxObjects
)
1231 FcMemAlloc (FC_MEM_SUBSTATE
, config
->maxObjects
* sizeof (FcSubState
));
1233 if (FcDebug () & FC_DBG_EDIT
)
1235 printf ("FcConfigSubstitute ");
1238 if (kind
== FcMatchPattern
)
1239 s
= config
->substPattern
;
1241 s
= config
->substFont
;
1242 for (; s
; s
= s
->next
)
1245 * Check the tests to see if
1246 * they all match the pattern
1248 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1250 if (FcDebug () & FC_DBG_EDIT
)
1252 printf ("FcConfigSubstitute test ");
1256 if (kind
== FcMatchFont
&& t
->kind
== FcMatchPattern
)
1261 st
[i
].elt
= FcPatternFindElt (m
, t
->field
);
1265 * If there's no such field in the font,
1266 * then FcQualAll matches while FcQualAny does not
1270 if (t
->qual
== FcQualAll
)
1279 * Check to see if there is a match, mark the location
1280 * to apply match-relative edits
1282 st
[i
].value
= FcConfigMatchValueList (m
, t
, st
[i
].elt
->values
);
1285 if (t
->qual
== FcQualFirst
&& st
[i
].value
!= st
[i
].elt
->values
)
1287 if (t
->qual
== FcQualNotFirst
&& st
[i
].value
== st
[i
].elt
->values
)
1292 if (FcDebug () & FC_DBG_EDIT
)
1293 printf ("No match\n");
1296 if (FcDebug () & FC_DBG_EDIT
)
1298 printf ("Substitute ");
1301 for (e
= s
->edit
; e
; e
= e
->next
)
1304 * Evaluate the list of expressions
1306 l
= FcConfigValues (p
, e
->expr
, e
->binding
);
1308 * Locate any test associated with this field, skipping
1309 * tests associated with the pattern when substituting in
1312 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1314 if ((t
->kind
== FcMatchFont
|| kind
== FcMatchPattern
) &&
1315 !FcStrCmpIgnoreCase ((FcChar8
*) t
->field
,
1316 (FcChar8
*) e
->field
))
1319 * KLUDGE - the pattern may have been reallocated or
1320 * things may have been inserted or deleted above
1321 * this element by other edits. Go back and find
1324 if (e
!= s
->edit
&& st
[i
].elt
)
1325 st
[i
].elt
= FcPatternFindElt (p
, t
->field
);
1334 * If there was a test, then replace the matched
1335 * value with the new list of values
1339 FcValueList
*thisValue
= st
[i
].value
;
1340 FcValueList
*nextValue
= thisValue
? thisValue
->next
: 0;
1343 * Append the new list of values after the current value
1345 FcConfigAdd (&st
[i
].elt
->values
, thisValue
, FcTrue
, l
);
1347 * Delete the marked value
1349 FcConfigDel (&st
[i
].elt
->values
, thisValue
);
1351 * Adjust any pointers into the value list to ensure
1352 * future edits occur at the same place
1354 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1356 if (st
[i
].value
== thisValue
)
1357 st
[i
].value
= nextValue
;
1361 /* fall through ... */
1362 case FcOpAssignReplace
:
1364 * Delete all of the values and insert
1367 FcConfigPatternDel (p
, e
->field
);
1368 FcConfigPatternAdd (p
, e
->field
, l
, FcTrue
);
1370 * Adjust any pointers into the value list as they no
1371 * longer point to anything valid
1375 FcPatternElt
*thisElt
= st
[i
].elt
;
1376 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1378 if (st
[i
].elt
== thisElt
)
1386 FcConfigAdd (&st
[i
].elt
->values
, st
[i
].value
, FcFalse
, l
);
1389 /* fall through ... */
1390 case FcOpPrependFirst
:
1391 FcConfigPatternAdd (p
, e
->field
, l
, FcFalse
);
1396 FcConfigAdd (&st
[i
].elt
->values
, st
[i
].value
, FcTrue
, l
);
1399 /* fall through ... */
1400 case FcOpAppendLast
:
1401 FcConfigPatternAdd (p
, e
->field
, l
, FcTrue
);
1408 * Now go through the pattern and eliminate
1409 * any properties without data
1411 for (e
= s
->edit
; e
; e
= e
->next
)
1412 FcConfigPatternCanon (p
, e
->field
);
1414 if (FcDebug () & FC_DBG_EDIT
)
1416 printf ("FcConfigSubstitute edit");
1420 FcMemFree (FC_MEM_SUBSTATE
, config
->maxObjects
* sizeof (FcSubState
));
1422 if (FcDebug () & FC_DBG_EDIT
)
1424 printf ("FcConfigSubstitute done");
1431 FcConfigSubstitute (FcConfig
*config
,
1435 return FcConfigSubstituteWithPat (config
, p
, 0, kind
);
1438 #if defined (_WIN32) && (defined (PIC) || defined (DLL_EXPORT))
1440 static FcChar8 fontconfig_path
[1000] = "";
1443 DllMain (HINSTANCE hinstDLL
,
1449 switch (fdwReason
) {
1450 case DLL_PROCESS_ATTACH
:
1451 if (!GetModuleFileName ((HMODULE
) hinstDLL
, fontconfig_path
,
1452 sizeof (fontconfig_path
)))
1455 /* If the fontconfig DLL is in a "bin" or "lib" subfolder,
1456 * assume it's a Unix-style installation tree, and use
1457 * "etc/fonts" in there as FONTCONFIG_PATH. Otherwise use the
1458 * folder where the DLL is as FONTCONFIG_PATH.
1460 p
= strrchr (fontconfig_path
, '\\');
1464 p
= strrchr (fontconfig_path
, '\\');
1465 if (p
&& (FcStrCmpIgnoreCase (p
+ 1, "bin") == 0 ||
1466 FcStrCmpIgnoreCase (p
+ 1, "lib") == 0))
1468 strcat (fontconfig_path
, "\\etc\\fonts");
1471 fontconfig_path
[0] = '\0';
1479 #undef FONTCONFIG_PATH
1480 #define FONTCONFIG_PATH fontconfig_path
1482 #else /* !(_WIN32 && PIC) */
1484 #endif /* !(_WIN32 && PIC) */
1486 #ifndef FONTCONFIG_FILE
1487 #define FONTCONFIG_FILE "fonts.conf"
1491 FcConfigFileExists (const FcChar8
*dir
, const FcChar8
*file
)
1496 dir
= (FcChar8
*) "";
1497 path
= malloc (strlen ((char *) dir
) + 1 + strlen ((char *) file
) + 1);
1501 strcpy ((char *) path
, (const char *) dir
);
1502 /* make sure there's a single separator */
1504 if ((!path
[0] || (path
[strlen((char *) path
)-1] != '/' &&
1505 path
[strlen((char *) path
)-1] != '\\')) &&
1506 (file
[0] != '/' && file
[0] != '\\'))
1507 strcat ((char *) path
, "\\");
1509 if ((!path
[0] || path
[strlen((char *) path
)-1] != '/') && file
[0] != '/')
1510 strcat ((char *) path
, "/");
1512 strcat ((char *) path
, (char *) file
);
1514 FcMemAlloc (FC_MEM_STRING
, strlen ((char *) path
) + 1);
1515 if (access ((char *) path
, R_OK
) == 0)
1523 FcConfigGetPath (void)
1526 FcChar8
*env
, *e
, *colon
;
1531 npath
= 2; /* default dir + null */
1532 env
= (FcChar8
*) getenv ("FONTCONFIG_PATH");
1538 if (*e
++ == FC_SEARCH_PATH_SEPARATOR
)
1541 path
= calloc (npath
, sizeof (FcChar8
*));
1551 colon
= (FcChar8
*) strchr ((char *) e
, FC_SEARCH_PATH_SEPARATOR
);
1553 colon
= e
+ strlen ((char *) e
);
1554 path
[i
] = malloc (colon
- e
+ 1);
1557 strncpy ((char *) path
[i
], (const char *) e
, colon
- e
);
1558 path
[i
][colon
- e
] = '\0';
1567 dir
= (FcChar8
*) FONTCONFIG_PATH
;
1568 path
[i
] = malloc (strlen ((char *) dir
) + 1);
1571 strcpy ((char *) path
[i
], (const char *) dir
);
1575 for (i
= 0; path
[i
]; i
++)
1583 FcConfigFreePath (FcChar8
**path
)
1587 for (p
= path
; *p
; p
++)
1592 static FcBool _FcConfigHomeEnabled
= FcTrue
;
1597 if (_FcConfigHomeEnabled
)
1599 char *home
= getenv ("HOME");
1603 home
= getenv ("USERPROFILE");
1612 FcConfigEnableHome (FcBool enable
)
1614 FcBool prev
= _FcConfigHomeEnabled
;
1615 _FcConfigHomeEnabled
= enable
;
1620 FcConfigFilename (const FcChar8
*url
)
1622 FcChar8
*file
, *dir
, **path
, **p
;
1626 url
= (FcChar8
*) getenv ("FONTCONFIG_FILE");
1628 url
= (FcChar8
*) FONTCONFIG_FILE
;
1633 if (isalpha (*url
) &&
1635 (url
[2] == '/' || url
[2] == '\\'))
1641 dir
= FcConfigHome ();
1643 file
= FcConfigFileExists (dir
, url
+ 1);
1652 file
= FcConfigFileExists (0, url
);
1655 path
= FcConfigGetPath ();
1658 for (p
= path
; *p
; p
++)
1660 file
= FcConfigFileExists (*p
, url
);
1664 FcConfigFreePath (path
);
1671 * Manage the application-specific fonts
1675 FcConfigAppFontAddFile (FcConfig
*config
,
1676 const FcChar8
*file
)
1685 config
= FcConfigGetCurrent ();
1690 subdirs
= FcStrSetCreate ();
1694 set
= FcConfigGetFonts (config
, FcSetApplication
);
1697 set
= FcFontSetCreate ();
1700 FcStrSetDestroy (subdirs
);
1703 FcConfigSetFonts (config
, set
, FcSetApplication
);
1706 if (!FcFileScanConfig (set
, subdirs
, 0, config
->blanks
, file
, FcFalse
, config
))
1708 FcStrSetDestroy (subdirs
);
1711 if ((sublist
= FcStrListCreate (subdirs
)))
1713 while ((subdir
= FcStrListNext (sublist
)))
1715 FcConfigAppFontAddDir (config
, subdir
);
1717 FcStrListDone (sublist
);
1723 FcConfigAppFontAddDir (FcConfig
*config
,
1733 config
= FcConfigGetCurrent ();
1737 subdirs
= FcStrSetCreate ();
1741 set
= FcConfigGetFonts (config
, FcSetApplication
);
1744 set
= FcFontSetCreate ();
1747 FcStrSetDestroy (subdirs
);
1750 FcConfigSetFonts (config
, set
, FcSetApplication
);
1753 if (!FcDirScanConfig (set
, subdirs
, 0, config
->blanks
, dir
, FcFalse
, config
))
1755 FcStrSetDestroy (subdirs
);
1758 if ((sublist
= FcStrListCreate (subdirs
)))
1760 while ((subdir
= FcStrListNext (sublist
)))
1762 FcConfigAppFontAddDir (config
, subdir
);
1764 FcStrListDone (sublist
);
1770 FcConfigAppFontClear (FcConfig
*config
)
1774 config
= FcConfigGetCurrent ();
1779 FcConfigSetFonts (config
, 0, FcSetApplication
);
1783 * Manage filename-based font source selectors
1787 FcConfigGlobAdd (FcConfig
*config
,
1788 const FcChar8
*glob
,
1791 FcStrSet
*set
= accept
? config
->acceptGlobs
: config
->rejectGlobs
;
1793 return FcStrSetAdd (set
, glob
);
1797 FcConfigGlobMatch (const FcChar8
*glob
,
1798 const FcChar8
*string
)
1802 while ((c
= *glob
++))
1806 /* short circuit common case */
1809 /* short circuit another common case */
1810 if (strchr ((char *) glob
, '*') == 0)
1811 string
+= strlen ((char *) string
) - strlen ((char *) glob
);
1814 if (FcConfigGlobMatch (glob
, string
))
1820 if (*string
++ == '\0')
1829 return *string
== '\0';
1833 FcConfigGlobsMatch (const FcStrSet
*globs
,
1834 const FcChar8
*string
)
1838 for (i
= 0; i
< globs
->num
; i
++)
1839 if (FcConfigGlobMatch (globs
->strs
[i
], string
))
1845 FcConfigAcceptFilename (FcConfig
*config
,
1846 const FcChar8
*filename
)
1848 if (FcConfigGlobsMatch (config
->acceptGlobs
, filename
))
1850 if (FcConfigGlobsMatch (config
->rejectGlobs
, filename
))
1856 * Manage font-pattern based font source selectors
1860 FcConfigPatternsAdd (FcConfig
*config
,
1864 FcFontSet
*set
= accept
? config
->acceptPatterns
: config
->rejectPatterns
;
1866 return FcFontSetAdd (set
, pattern
);
1870 FcConfigPatternsMatch (const FcFontSet
*patterns
,
1871 const FcPattern
*font
)
1875 for (i
= 0; i
< patterns
->nfont
; i
++)
1876 if (FcListPatternMatchAny (patterns
->fonts
[i
], font
))
1882 FcConfigAcceptFont (FcConfig
*config
,
1883 const FcPattern
*font
)
1885 if (FcConfigPatternsMatch (config
->acceptPatterns
, font
))
1887 if (FcConfigPatternsMatch (config
->rejectPatterns
, font
))