2 * $RCSId: xc/lib/fontconfig/src/fccfg.c,v 1.23 2002/08/31 22:17:32 keithp Exp $
4 * Copyright © 2000 Keith Packard
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of Keith Packard not be used in
11 * advertising or publicity pertaining to distribution of the software without
12 * specific, written prior permission. Keith Packard makes no
13 * representations about the suitability of this software for any purpose. It
14 * is provided "as is" without express or implied warranty.
16 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22 * PERFORMANCE OF THIS SOFTWARE.
27 #if defined (_WIN32) && (defined (PIC) || defined (DLL_EXPORT))
33 #if defined (_WIN32) && !defined (R_OK)
45 config
= malloc (sizeof (FcConfig
));
48 FcMemAlloc (FC_MEM_CONFIG
, sizeof (FcConfig
));
50 config
->configDirs
= FcStrSetCreate ();
51 if (!config
->configDirs
)
54 config
->configFiles
= FcStrSetCreate ();
55 if (!config
->configFiles
)
58 config
->fontDirs
= FcStrSetCreate ();
59 if (!config
->fontDirs
)
62 config
->acceptGlobs
= FcStrSetCreate ();
63 if (!config
->acceptGlobs
)
66 config
->rejectGlobs
= FcStrSetCreate ();
67 if (!config
->rejectGlobs
)
72 if (!FcConfigSetCache (config
, (FcChar8
*) ("~/" FC_USER_CACHE_FILE
)))
77 config
->substPattern
= 0;
78 config
->substFont
= 0;
79 config
->maxObjects
= 0;
80 for (set
= FcSetSystem
; set
<= FcSetApplication
; set
++)
81 config
->fonts
[set
] = 0;
83 config
->rescanTime
= time(0);
84 config
->rescanInterval
= 30;
89 FcStrSetDestroy (config
->rejectGlobs
);
91 FcStrSetDestroy (config
->acceptGlobs
);
93 FcStrSetDestroy (config
->fontDirs
);
95 FcStrSetDestroy (config
->configFiles
);
97 FcStrSetDestroy (config
->configDirs
);
100 FcMemFree (FC_MEM_CONFIG
, sizeof (FcConfig
));
105 typedef struct _FcFileTime
{
111 FcConfigNewestFile (FcStrSet
*files
)
113 FcStrList
*list
= FcStrListCreate (files
);
114 FcFileTime newest
= { 0, FcFalse
};
120 while ((file
= FcStrListNext (list
)))
121 if (stat ((char *) file
, &statb
) == 0)
122 if (!newest
.set
|| statb
.st_mtime
- newest
.time
> 0)
123 newest
.time
= statb
.st_mtime
;
124 FcStrListDone (list
);
130 FcConfigUptoDate (FcConfig
*config
)
132 FcFileTime config_time
, font_time
;
133 time_t now
= time(0);
136 config
= FcConfigGetCurrent ();
140 config_time
= FcConfigNewestFile (config
->configFiles
);
141 font_time
= FcConfigNewestFile (config
->configDirs
);
142 if ((config_time
.set
&& config_time
.time
- config
->rescanTime
> 0) ||
143 (font_time
.set
&& font_time
.time
- config
->rescanTime
) > 0)
147 config
->rescanTime
= now
;
152 FcSubstDestroy (FcSubst
*s
)
160 FcTestDestroy (s
->test
);
162 FcEditDestroy (s
->edit
);
168 FcConfigDestroy (FcConfig
*config
)
172 if (config
== _fcConfig
)
175 FcStrSetDestroy (config
->configDirs
);
176 FcStrSetDestroy (config
->fontDirs
);
177 FcStrSetDestroy (config
->configFiles
);
178 FcStrSetDestroy (config
->acceptGlobs
);
179 FcStrSetDestroy (config
->rejectGlobs
);
182 FcStrFree (config
->cache
);
184 FcSubstDestroy (config
->substPattern
);
185 FcSubstDestroy (config
->substFont
);
186 for (set
= FcSetSystem
; set
<= FcSetApplication
; set
++)
187 if (config
->fonts
[set
])
188 FcFontSetDestroy (config
->fonts
[set
]);
190 FcMemFree (FC_MEM_CONFIG
, sizeof (FcConfig
));
194 * Scan the current list of directories in the configuration
195 * and build the set of available fonts. Update the
196 * per-user cache file to reflect the new configuration
200 FcConfigBuildFonts (FcConfig
*config
)
203 FcGlobalCache
*cache
;
207 fonts
= FcFontSetCreate ();
211 cache
= FcGlobalCacheCreate ();
216 FcGlobalCacheLoad (cache
, config
->cache
);
218 list
= FcConfigGetFontDirs (config
);
222 while ((dir
= FcStrListNext (list
)))
224 if (FcDebug () & FC_DBG_FONTSET
)
225 printf ("scan dir %s\n", dir
);
226 FcDirScanConfig (fonts
, config
->fontDirs
, cache
,
227 config
->blanks
, dir
, FcFalse
, config
);
230 FcStrListDone (list
);
232 if (FcDebug () & FC_DBG_FONTSET
)
233 FcFontSetPrint (fonts
);
236 FcGlobalCacheSave (cache
, config
->cache
);
237 FcGlobalCacheDestroy (cache
);
239 FcConfigSetFonts (config
, fonts
, FcSetSystem
);
243 FcFontSetDestroy (fonts
);
249 FcConfigSetCurrent (FcConfig
*config
)
252 if (!FcConfigBuildFonts (config
))
256 FcConfigDestroy (_fcConfig
);
262 FcConfigGetCurrent (void)
271 FcConfigAddConfigDir (FcConfig
*config
,
274 return FcStrSetAddFilename (config
->configDirs
, d
);
278 FcConfigGetConfigDirs (FcConfig
*config
)
282 config
= FcConfigGetCurrent ();
286 return FcStrListCreate (config
->configDirs
);
290 FcConfigAddFontDir (FcConfig
*config
,
293 return FcStrSetAddFilename (config
->fontDirs
, d
);
297 FcConfigAddDir (FcConfig
*config
,
300 return (FcConfigAddConfigDir (config
, d
) &&
301 FcConfigAddFontDir (config
, d
));
305 FcConfigGetFontDirs (FcConfig
*config
)
309 config
= FcConfigGetCurrent ();
313 return FcStrListCreate (config
->fontDirs
);
317 FcConfigAddConfigFile (FcConfig
*config
,
321 FcChar8
*file
= FcConfigFilename (f
);
326 ret
= FcStrSetAdd (config
->configFiles
, file
);
332 FcConfigGetConfigFiles (FcConfig
*config
)
336 config
= FcConfigGetCurrent ();
340 return FcStrListCreate (config
->configFiles
);
344 FcConfigSetCache (FcConfig
*config
,
347 FcChar8
*new = FcStrCopyFilename (c
);
352 FcStrFree (config
->cache
);
358 FcConfigGetCache (FcConfig
*config
)
362 config
= FcConfigGetCurrent ();
366 return config
->cache
;
370 FcConfigGetFonts (FcConfig
*config
,
375 config
= FcConfigGetCurrent ();
379 return config
->fonts
[set
];
383 FcConfigSetFonts (FcConfig
*config
,
387 if (config
->fonts
[set
])
388 FcFontSetDestroy (config
->fonts
[set
]);
389 config
->fonts
[set
] = fonts
;
395 FcConfigGetBlanks (FcConfig
*config
)
399 config
= FcConfigGetCurrent ();
403 return config
->blanks
;
407 FcConfigAddBlank (FcConfig
*config
,
415 b
= FcBlanksCreate ();
419 if (!FcBlanksAdd (b
, blank
))
426 FcConfigGetRescanInverval (FcConfig
*config
)
430 config
= FcConfigGetCurrent ();
434 return config
->rescanInterval
;
438 FcConfigSetRescanInverval (FcConfig
*config
, int rescanInterval
)
442 config
= FcConfigGetCurrent ();
446 config
->rescanInterval
= rescanInterval
;
451 FcConfigAddEdit (FcConfig
*config
,
456 FcSubst
*subst
, **prev
;
460 subst
= (FcSubst
*) malloc (sizeof (FcSubst
));
463 FcMemAlloc (FC_MEM_SUBST
, sizeof (FcSubst
));
464 if (kind
== FcMatchPattern
)
465 prev
= &config
->substPattern
;
467 prev
= &config
->substFont
;
468 for (; *prev
; prev
= &(*prev
)->next
);
474 for (t
= test
; t
; t
= t
->next
)
476 if (t
->kind
== FcMatchDefault
)
480 if (config
->maxObjects
< num
)
481 config
->maxObjects
= num
;
482 if (FcDebug () & FC_DBG_EDIT
)
484 printf ("Add Subst ");
485 FcSubstPrint (subst
);
490 typedef struct _FcSubState
{
496 FcConfigPromote (FcValue v
, FcValue u
)
498 if (v
.type
== FcTypeInteger
)
500 v
.type
= FcTypeDouble
;
501 v
.u
.d
= (double) v
.u
.i
;
503 else if (v
.type
== FcTypeVoid
&& u
.type
== FcTypeMatrix
)
505 v
.u
.m
= &FcIdentityMatrix
;
506 v
.type
= FcTypeMatrix
;
508 else if (v
.type
== FcTypeString
&& u
.type
== FcTypeLangSet
)
510 v
.u
.l
= FcLangSetPromote (v
.u
.s
);
511 v
.type
= FcTypeLangSet
;
517 FcConfigCompareValue (const FcValue m_o
,
523 FcBool ret
= FcFalse
;
525 m
= FcConfigPromote (m
, v
);
526 v
= FcConfigPromote (v
, m
);
527 if (m
.type
== v
.type
)
531 break; /* FcConfigPromote prevents this from happening */
536 ret
= m
.u
.d
== v
.u
.d
;
539 case FcOpNotContains
:
540 ret
= m
.u
.d
!= v
.u
.d
;
546 ret
= m
.u
.d
<= v
.u
.d
;
552 ret
= m
.u
.d
>= v
.u
.d
;
562 ret
= m
.u
.b
== v
.u
.b
;
565 case FcOpNotContains
:
566 ret
= m
.u
.b
!= v
.u
.b
;
575 ret
= FcStrCmpIgnoreCase (m
.u
.s
, v
.u
.s
) == 0;
578 ret
= FcStrStrIgnoreCase (m
.u
.s
, v
.u
.s
) != 0;
581 ret
= FcStrCmpIgnoreCase (m
.u
.s
, v
.u
.s
) != 0;
583 case FcOpNotContains
:
584 ret
= FcStrStrIgnoreCase (m
.u
.s
, v
.u
.s
) == 0;
594 ret
= FcMatrixEqual (m
.u
.m
, v
.u
.m
);
597 case FcOpNotContains
:
598 ret
= !FcMatrixEqual (m
.u
.m
, v
.u
.m
);
607 /* v contains m if m is a subset of v */
608 ret
= FcCharSetIsSubset (m
.u
.c
, v
.u
.c
);
610 case FcOpNotContains
:
611 /* v contains m if m is a subset of v */
612 ret
= !FcCharSetIsSubset (m
.u
.c
, v
.u
.c
);
615 ret
= FcCharSetEqual (m
.u
.c
, v
.u
.c
);
618 ret
= !FcCharSetEqual (m
.u
.c
, v
.u
.c
);
627 ret
= FcLangSetContains (m
.u
.l
, v
.u
.l
);
629 case FcOpNotContains
:
630 ret
= FcLangSetContains (m
.u
.l
, v
.u
.l
);
633 ret
= FcLangSetEqual (m
.u
.l
, v
.u
.l
);
636 ret
= !FcLangSetEqual (m
.u
.l
, v
.u
.l
);
656 ret
= m
.u
.f
== v
.u
.f
;
659 case FcOpNotContains
:
660 ret
= m
.u
.f
!= v
.u
.f
;
670 if (op
== FcOpNotEqual
|| op
== FcOpNotContains
)
677 #define _FcDoubleFloor(d) ((int) (d))
678 #define _FcDoubleCeil(d) ((double) (int) (d) == (d) ? (int) (d) : (int) ((d) + 1))
679 #define FcDoubleFloor(d) ((d) >= 0 ? _FcDoubleFloor(d) : -_FcDoubleCeil(-(d)))
680 #define FcDoubleCeil(d) ((d) >= 0 ? _FcDoubleCeil(d) : -_FcDoubleFloor(-(d)))
681 #define FcDoubleRound(d) FcDoubleFloor ((d) + 0.5)
682 #define FcDoubleTrunc(d) ((d) >= 0 ? _FcDoubleFloor (d) : -_FcDoubleFloor (-(d)))
685 FcConfigEvaluate (FcPattern
*p
, FcExpr
*e
)
693 v
.type
= FcTypeInteger
;
697 v
.type
= FcTypeDouble
;
701 v
.type
= FcTypeString
;
706 v
.type
= FcTypeMatrix
;
711 v
.type
= FcTypeCharSet
;
720 r
= FcPatternGet (p
, e
->u
.field
, 0, &v
);
721 if (r
!= FcResultMatch
)
725 if (FcNameConstant (e
->u
.constant
, &v
.u
.i
))
726 v
.type
= FcTypeInteger
;
731 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
732 if (vl
.type
== FcTypeBool
)
735 v
= FcConfigEvaluate (p
, e
->u
.tree
.right
->u
.tree
.left
);
737 v
= FcConfigEvaluate (p
, e
->u
.tree
.right
->u
.tree
.right
);
750 case FcOpNotContains
:
751 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
752 vr
= FcConfigEvaluate (p
, e
->u
.tree
.right
);
754 v
.u
.b
= FcConfigCompareValue (vl
, e
->op
, vr
);
764 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
765 vr
= FcConfigEvaluate (p
, e
->u
.tree
.right
);
766 vl
= FcConfigPromote (vl
, vr
);
767 vr
= FcConfigPromote (vr
, vl
);
768 if (vl
.type
== vr
.type
)
774 v
.type
= FcTypeDouble
;
775 v
.u
.d
= vl
.u
.d
+ vr
.u
.d
;
778 v
.type
= FcTypeDouble
;
779 v
.u
.d
= vl
.u
.d
- vr
.u
.d
;
782 v
.type
= FcTypeDouble
;
783 v
.u
.d
= vl
.u
.d
* vr
.u
.d
;
786 v
.type
= FcTypeDouble
;
787 v
.u
.d
= vl
.u
.d
/ vr
.u
.d
;
793 if (v
.type
== FcTypeDouble
&&
794 v
.u
.d
== (double) (int) v
.u
.d
)
796 v
.type
= FcTypeInteger
;
804 v
.u
.b
= vl
.u
.b
|| vr
.u
.b
;
808 v
.u
.b
= vl
.u
.b
&& vr
.u
.b
;
818 v
.type
= FcTypeString
;
819 v
.u
.s
= FcStrPlus (vl
.u
.s
, vr
.u
.s
);
831 v
.type
= FcTypeMatrix
;
832 m
= malloc (sizeof (FcMatrix
));
835 FcMemAlloc (FC_MEM_MATRIX
, sizeof (FcMatrix
));
836 FcMatrixMultiply (m
, vl
.u
.m
, vr
.u
.m
);
860 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
873 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
879 v
.type
= FcTypeInteger
;
880 v
.u
.i
= FcDoubleFloor (vl
.u
.d
);
889 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
895 v
.type
= FcTypeInteger
;
896 v
.u
.i
= FcDoubleCeil (vl
.u
.d
);
905 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
911 v
.type
= FcTypeInteger
;
912 v
.u
.i
= FcDoubleRound (vl
.u
.d
);
921 vl
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
927 v
.type
= FcTypeInteger
;
928 v
.u
.i
= FcDoubleTrunc (vl
.u
.d
);
944 FcConfigMatchValueList (FcPattern
*p
,
948 FcValueList
*ret
= 0;
955 if (e
->op
== FcOpComma
)
957 value
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
962 value
= FcConfigEvaluate (p
, e
);
966 for (v
= values
; v
; v
= v
->next
)
968 if (FcConfigCompareValue (v
->value
, t
->op
, value
))
975 if (t
->qual
== FcQualAll
)
982 FcValueDestroy (value
);
988 FcConfigValues (FcPattern
*p
, FcExpr
*e
, FcValueBinding binding
)
994 l
= (FcValueList
*) malloc (sizeof (FcValueList
));
997 FcMemAlloc (FC_MEM_VALLIST
, sizeof (FcValueList
));
998 if (e
->op
== FcOpComma
)
1000 l
->value
= FcConfigEvaluate (p
, e
->u
.tree
.left
);
1001 l
->next
= FcConfigValues (p
, e
->u
.tree
.right
, binding
);
1005 l
->value
= FcConfigEvaluate (p
, e
);
1008 l
->binding
= binding
;
1009 while (l
&& l
->value
.type
== FcTypeVoid
)
1011 FcValueList
*next
= l
->next
;
1013 FcMemFree (FC_MEM_VALLIST
, sizeof (FcValueList
));
1021 FcConfigAdd (FcValueList
**head
,
1022 FcValueList
*position
,
1026 FcValueList
**prev
, *last
, *v
;
1027 FcValueBinding sameBinding
;
1030 sameBinding
= position
->binding
;
1032 sameBinding
= FcValueBindingWeak
;
1033 for (v
= new; v
; v
= v
->next
)
1034 if (v
->binding
== FcValueBindingSame
)
1035 v
->binding
= sameBinding
;
1039 prev
= &position
->next
;
1041 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1048 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1050 if (*prev
== position
)
1057 if (FcDebug () & FC_DBG_EDIT
)
1060 printf ("position not on list\n");
1064 if (FcDebug () & FC_DBG_EDIT
)
1066 printf ("%s list before ", append
? "Append" : "Prepend");
1067 FcValueListPrint (*head
);
1081 if (FcDebug () & FC_DBG_EDIT
)
1083 printf ("%s list after ", append
? "Append" : "Prepend");
1084 FcValueListPrint (*head
);
1092 FcConfigDel (FcValueList
**head
,
1093 FcValueList
*position
)
1097 for (prev
= head
; *prev
; prev
= &(*prev
)->next
)
1099 if (*prev
== position
)
1101 *prev
= position
->next
;
1103 FcValueListDestroy (position
);
1110 FcConfigPatternAdd (FcPattern
*p
,
1117 FcPatternElt
*e
= FcPatternInsertElt (p
, object
);
1121 FcConfigAdd (&e
->values
, 0, append
, list
);
1126 * Delete all values associated with a field
1129 FcConfigPatternDel (FcPattern
*p
,
1132 FcPatternElt
*e
= FcPatternFindElt (p
, object
);
1136 FcConfigDel (&e
->values
, e
->values
);
1140 FcConfigPatternCanon (FcPattern
*p
,
1143 FcPatternElt
*e
= FcPatternFindElt (p
, object
);
1147 FcPatternDel (p
, object
);
1151 FcConfigSubstituteWithPat (FcConfig
*config
,
1166 config
= FcConfigGetCurrent ();
1171 st
= (FcSubState
*) malloc (config
->maxObjects
* sizeof (FcSubState
));
1172 if (!st
&& config
->maxObjects
)
1174 FcMemAlloc (FC_MEM_SUBSTATE
, config
->maxObjects
* sizeof (FcSubState
));
1176 if (FcDebug () & FC_DBG_EDIT
)
1178 printf ("FcConfigSubstitute ");
1181 if (kind
== FcMatchPattern
)
1182 s
= config
->substPattern
;
1184 s
= config
->substFont
;
1185 for (; s
; s
= s
->next
)
1188 * Check the tests to see if
1189 * they all match the pattern
1191 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1193 if (FcDebug () & FC_DBG_EDIT
)
1195 printf ("FcConfigSubstitute test ");
1199 if (kind
== FcMatchFont
&& t
->kind
== FcMatchPattern
)
1204 st
[i
].elt
= FcPatternFindElt (m
, t
->field
);
1208 * If there's no such field in the font,
1209 * then FcQualAll matches while FcQualAny does not
1213 if (t
->qual
== FcQualAll
)
1222 * Check to see if there is a match, mark the location
1223 * to apply match-relative edits
1225 st
[i
].value
= FcConfigMatchValueList (m
, t
, st
[i
].elt
->values
);
1228 if (t
->qual
== FcQualFirst
&& st
[i
].value
!= st
[i
].elt
->values
)
1230 if (t
->qual
== FcQualNotFirst
&& st
[i
].value
== st
[i
].elt
->values
)
1235 if (FcDebug () & FC_DBG_EDIT
)
1236 printf ("No match\n");
1239 if (FcDebug () & FC_DBG_EDIT
)
1241 printf ("Substitute ");
1244 for (e
= s
->edit
; e
; e
= e
->next
)
1247 * Evaluate the list of expressions
1249 l
= FcConfigValues (p
, e
->expr
, e
->binding
);
1251 * Locate any test associated with this field, skipping
1252 * tests associated with the pattern when substituting in
1255 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1257 if ((t
->kind
== FcMatchFont
|| kind
== FcMatchPattern
) &&
1258 !FcStrCmpIgnoreCase ((FcChar8
*) t
->field
,
1259 (FcChar8
*) e
->field
))
1262 * KLUDGE - the pattern may have been reallocated or
1263 * things may have been inserted or deleted above
1264 * this element by other edits. Go back and find
1267 if (e
!= s
->edit
&& st
[i
].elt
)
1268 st
[i
].elt
= FcPatternFindElt (p
, t
->field
);
1277 * If there was a test, then replace the matched
1278 * value with the new list of values
1282 FcValueList
*thisValue
= st
[i
].value
;
1283 FcValueList
*nextValue
= thisValue
? thisValue
->next
: 0;
1286 * Append the new list of values after the current value
1288 FcConfigAdd (&st
[i
].elt
->values
, thisValue
, FcTrue
, l
);
1290 * Delete the marked value
1292 FcConfigDel (&st
[i
].elt
->values
, thisValue
);
1294 * Adjust any pointers into the value list to ensure
1295 * future edits occur at the same place
1297 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1299 if (st
[i
].value
== thisValue
)
1300 st
[i
].value
= nextValue
;
1304 /* fall through ... */
1305 case FcOpAssignReplace
:
1307 * Delete all of the values and insert
1310 FcConfigPatternDel (p
, e
->field
);
1311 FcConfigPatternAdd (p
, e
->field
, l
, FcTrue
);
1313 * Adjust any pointers into the value list as they no
1314 * longer point to anything valid
1318 FcPatternElt
*thisElt
= st
[i
].elt
;
1319 for (t
= s
->test
, i
= 0; t
; t
= t
->next
, i
++)
1321 if (st
[i
].elt
== thisElt
)
1329 FcConfigAdd (&st
[i
].elt
->values
, st
[i
].value
, FcFalse
, l
);
1332 /* fall through ... */
1333 case FcOpPrependFirst
:
1334 FcConfigPatternAdd (p
, e
->field
, l
, FcFalse
);
1339 FcConfigAdd (&st
[i
].elt
->values
, st
[i
].value
, FcTrue
, l
);
1342 /* fall through ... */
1343 case FcOpAppendLast
:
1344 FcConfigPatternAdd (p
, e
->field
, l
, FcTrue
);
1351 * Now go through the pattern and eliminate
1352 * any properties without data
1354 for (e
= s
->edit
; e
; e
= e
->next
)
1355 FcConfigPatternCanon (p
, e
->field
);
1357 if (FcDebug () & FC_DBG_EDIT
)
1359 printf ("FcConfigSubstitute edit");
1363 FcMemFree (FC_MEM_SUBSTATE
, config
->maxObjects
* sizeof (FcSubState
));
1365 if (FcDebug () & FC_DBG_EDIT
)
1367 printf ("FcConfigSubstitute done");
1374 FcConfigSubstitute (FcConfig
*config
,
1378 return FcConfigSubstituteWithPat (config
, p
, 0, kind
);
1381 #if defined (_WIN32) && (defined (PIC) || defined (DLL_EXPORT))
1383 static FcChar8 fontconfig_path
[1000] = "";
1386 DllMain (HINSTANCE hinstDLL
,
1392 switch (fdwReason
) {
1393 case DLL_PROCESS_ATTACH
:
1394 if (!GetModuleFileName ((HMODULE
) hinstDLL
, fontconfig_path
,
1395 sizeof (fontconfig_path
)))
1398 /* If the fontconfig DLL is in a "bin" or "lib" subfolder,
1399 * assume it's a Unix-style installation tree, and use
1400 * "etc/fonts" in there as FONTCONFIG_PATH. Otherwise use the
1401 * folder where the DLL is as FONTCONFIG_PATH.
1403 p
= strrchr (fontconfig_path
, '\\');
1407 p
= strrchr (fontconfig_path
, '\\');
1408 if (p
&& (FcStrCmpIgnoreCase (p
+ 1, "bin") == 0 ||
1409 FcStrCmpIgnoreCase (p
+ 1, "lib") == 0))
1411 strcat (fontconfig_path
, "\\etc\\fonts");
1414 fontconfig_path
[0] = '\0';
1422 #undef FONTCONFIG_PATH
1423 #define FONTCONFIG_PATH fontconfig_path
1425 #else /* !(_WIN32 && PIC) */
1427 #endif /* !(_WIN32 && PIC) */
1429 #ifndef FONTCONFIG_FILE
1430 #define FONTCONFIG_FILE "fonts.conf"
1434 FcConfigFileExists (const FcChar8
*dir
, const FcChar8
*file
)
1439 dir
= (FcChar8
*) "";
1440 path
= malloc (strlen ((char *) dir
) + 1 + strlen ((char *) file
) + 1);
1444 strcpy ((char *) path
, (const char *) dir
);
1445 /* make sure there's a single separator */
1447 if ((!path
[0] || (path
[strlen((char *) path
)-1] != '/' &&
1448 path
[strlen((char *) path
)-1] != '\\')) &&
1449 (file
[0] != '/' && file
[0] != '\\'))
1450 strcat ((char *) path
, "\\");
1452 if ((!path
[0] || path
[strlen((char *) path
)-1] != '/') && file
[0] != '/')
1453 strcat ((char *) path
, "/");
1455 strcat ((char *) path
, (char *) file
);
1457 FcMemAlloc (FC_MEM_STRING
, strlen ((char *) path
) + 1);
1458 if (access ((char *) path
, R_OK
) == 0)
1466 FcConfigGetPath (void)
1469 FcChar8
*env
, *e
, *colon
;
1474 npath
= 2; /* default dir + null */
1475 env
= (FcChar8
*) getenv ("FONTCONFIG_PATH");
1481 if (*e
++ == FC_SEARCH_PATH_SEPARATOR
)
1484 path
= calloc (npath
, sizeof (FcChar8
*));
1494 colon
= (FcChar8
*) strchr ((char *) e
, FC_SEARCH_PATH_SEPARATOR
);
1496 colon
= e
+ strlen ((char *) e
);
1497 path
[i
] = malloc (colon
- e
+ 1);
1500 strncpy ((char *) path
[i
], (const char *) e
, colon
- e
);
1501 path
[i
][colon
- e
] = '\0';
1510 dir
= (FcChar8
*) FONTCONFIG_PATH
;
1511 path
[i
] = malloc (strlen ((char *) dir
) + 1);
1514 strcpy ((char *) path
[i
], (const char *) dir
);
1518 for (i
= 0; path
[i
]; i
++)
1526 FcConfigFreePath (FcChar8
**path
)
1530 for (p
= path
; *p
; p
++)
1535 static FcBool _FcConfigHomeEnabled
= FcTrue
;
1540 if (_FcConfigHomeEnabled
)
1542 char *home
= getenv ("HOME");
1546 home
= getenv ("USERPROFILE");
1555 FcConfigEnableHome (FcBool enable
)
1557 FcBool prev
= _FcConfigHomeEnabled
;
1558 _FcConfigHomeEnabled
= enable
;
1563 FcConfigFilename (const FcChar8
*url
)
1565 FcChar8
*file
, *dir
, **path
, **p
;
1569 url
= (FcChar8
*) getenv ("FONTCONFIG_FILE");
1571 url
= (FcChar8
*) FONTCONFIG_FILE
;
1576 if (isalpha (*url
) &&
1578 (url
[2] == '/' || url
[2] == '\\'))
1584 dir
= FcConfigHome ();
1586 file
= FcConfigFileExists (dir
, url
+ 1);
1595 file
= FcConfigFileExists (0, url
);
1598 path
= FcConfigGetPath ();
1601 for (p
= path
; *p
; p
++)
1603 file
= FcConfigFileExists (*p
, url
);
1607 FcConfigFreePath (path
);
1614 * Manage the application-specific fonts
1618 FcConfigAppFontAddFile (FcConfig
*config
,
1619 const FcChar8
*file
)
1628 config
= FcConfigGetCurrent ();
1633 subdirs
= FcStrSetCreate ();
1637 set
= FcConfigGetFonts (config
, FcSetApplication
);
1640 set
= FcFontSetCreate ();
1643 FcStrSetDestroy (subdirs
);
1646 FcConfigSetFonts (config
, set
, FcSetApplication
);
1649 if (!FcFileScanConfig (set
, subdirs
, 0, config
->blanks
, file
, FcFalse
, config
))
1651 FcStrSetDestroy (subdirs
);
1654 if ((sublist
= FcStrListCreate (subdirs
)))
1656 while ((subdir
= FcStrListNext (sublist
)))
1658 FcConfigAppFontAddDir (config
, subdir
);
1660 FcStrListDone (sublist
);
1666 FcConfigAppFontAddDir (FcConfig
*config
,
1676 config
= FcConfigGetCurrent ();
1680 subdirs
= FcStrSetCreate ();
1684 set
= FcConfigGetFonts (config
, FcSetApplication
);
1687 set
= FcFontSetCreate ();
1690 FcStrSetDestroy (subdirs
);
1693 FcConfigSetFonts (config
, set
, FcSetApplication
);
1696 if (!FcDirScanConfig (set
, subdirs
, 0, config
->blanks
, dir
, FcFalse
, config
))
1698 FcStrSetDestroy (subdirs
);
1701 if ((sublist
= FcStrListCreate (subdirs
)))
1703 while ((subdir
= FcStrListNext (sublist
)))
1705 FcConfigAppFontAddDir (config
, subdir
);
1707 FcStrListDone (sublist
);
1713 FcConfigAppFontClear (FcConfig
*config
)
1715 FcConfigSetFonts (config
, 0, FcSetApplication
);
1719 * Manage filename-based font source selectors
1723 FcConfigGlobAdd (FcConfig
*config
,
1724 const FcChar8
*glob
,
1727 FcStrSet
*set
= accept
? config
->acceptGlobs
: config
->rejectGlobs
;
1729 return FcStrSetAdd (set
, glob
);
1733 FcConfigGlobMatch (const FcChar8
*glob
,
1734 const FcChar8
*string
)
1738 while ((c
= *glob
++))
1742 /* short circuit common case */
1745 /* short circuit another common case */
1746 if (strchr ((char *) glob
, '*') == 0)
1747 string
+= strlen ((char *) string
) - strlen ((char *) glob
);
1750 if (FcConfigGlobMatch (glob
, string
))
1756 if (*string
++ == '\0')
1765 return *string
== '\0';
1769 FcConfigGlobsMatch (const FcStrSet
*globs
,
1770 const FcChar8
*string
)
1774 for (i
= 0; i
< globs
->num
; i
++)
1775 if (FcConfigGlobMatch (globs
->strs
[i
], string
))
1781 FcConfigAcceptFilename (FcConfig
*config
,
1782 const FcChar8
*filename
)
1784 if (FcConfigGlobsMatch (config
->acceptGlobs
, filename
))
1786 if (FcConfigGlobsMatch (config
->rejectGlobs
, filename
))