2 * $RCSId: xc/lib/fontconfig/src/fcint.h,v 1.27 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.
35 #include <sys/types.h>
38 #include <fontconfig/fontconfig.h>
39 #include <fontconfig/fcprivate.h>
40 #include <fontconfig/fcfreetype.h>
45 #ifndef FC_CONFIG_PATH
46 #define FC_CONFIG_PATH "fonts.conf"
49 #define FC_FONT_FILE_INVALID ((FcChar8 *) ".")
50 #define FC_FONT_FILE_DIR ((FcChar8 *) ".dir")
51 #define FC_GLOBAL_MAGIC_COOKIE "GLOBAL"
54 #define FC_SEARCH_PATH_SEPARATOR ';'
56 #define FC_SEARCH_PATH_SEPARATOR ':'
59 #define FC_DBG_MATCH 1
60 #define FC_DBG_MATCHV 2
62 #define FC_DBG_FONTSET 8
63 #define FC_DBG_CACHE 16
64 #define FC_DBG_CACHEV 32
65 #define FC_DBG_PARSE 64
66 #define FC_DBG_SCAN 128
67 #define FC_DBG_SCANV 256
68 #define FC_DBG_MEMORY 512
69 #define FC_DBG_CONFIG 1024
71 #define FC_MEM_CHARSET 0
72 #define FC_MEM_CHARLEAF 1
73 #define FC_MEM_FONTSET 2
74 #define FC_MEM_FONTPTR 3
75 #define FC_MEM_OBJECTSET 4
76 #define FC_MEM_OBJECTPTR 5
77 #define FC_MEM_MATRIX 6
78 #define FC_MEM_PATTERN 7
79 #define FC_MEM_PATELT 8
80 #define FC_MEM_VALLIST 9
81 #define FC_MEM_SUBSTATE 10
82 #define FC_MEM_STRING 11
83 #define FC_MEM_LISTBUCK 12
84 #define FC_MEM_STRSET 13
85 #define FC_MEM_STRLIST 14
86 #define FC_MEM_CONFIG 15
87 #define FC_MEM_LANGSET 16
88 #define FC_MEM_ATOMIC 17
89 #define FC_MEM_BLANKS 18
90 #define FC_MEM_CACHE 19
91 #define FC_MEM_STRBUF 20
92 #define FC_MEM_SUBST 21
93 #define FC_MEM_OBJECTTYPE 22
94 #define FC_MEM_CONSTANT 23
95 #define FC_MEM_TEST 24
96 #define FC_MEM_EXPR 25
97 #define FC_MEM_VSTACK 26
98 #define FC_MEM_ATTR 27
99 #define FC_MEM_PSTACK 28
100 #define FC_MEM_STATICSTR 29
102 #define FC_MEM_NUM 30
104 #define FC_BANK_DYNAMIC 0
105 #define FC_BANK_FIRST 1
106 #define FC_BANK_LANGS 0xfcfcfcfc
108 typedef enum _FcValueBinding {
109 FcValueBindingWeak, FcValueBindingStrong, FcValueBindingSame
112 typedef struct _FcValueListPtr {
116 struct _FcValueList *dyn;
120 typedef struct _FcValueList {
124 FcValueBinding binding;
127 typedef int FcObjectPtr;
129 typedef struct _FcPatternEltPtr {
133 struct _FcPatternElt *dyn;
137 typedef struct _FcPatternElt {
139 FcValueListPtr values;
145 FcPatternEltPtr elts;
151 FcOpInteger, FcOpDouble, FcOpString, FcOpMatrix, FcOpBool, FcOpCharSet,
153 FcOpField, FcOpConst,
154 FcOpAssign, FcOpAssignReplace,
155 FcOpPrependFirst, FcOpPrepend, FcOpAppend, FcOpAppendLast,
157 FcOpOr, FcOpAnd, FcOpEqual, FcOpNotEqual,
158 FcOpContains, FcOpListing, FcOpNotContains,
159 FcOpLess, FcOpLessEqual, FcOpMore, FcOpMoreEqual,
160 FcOpPlus, FcOpMinus, FcOpTimes, FcOpDivide,
161 FcOpNot, FcOpComma, FcOpFloor, FcOpCeil, FcOpRound, FcOpTrunc,
165 typedef struct _FcExpr {
177 struct _FcExpr *left, *right;
182 typedef enum _FcQual {
183 FcQualAny, FcQualAll, FcQualFirst, FcQualNotFirst
186 #define FcMatchDefault ((FcMatchKind) -1)
188 typedef struct _FcTest {
189 struct _FcTest *next;
197 typedef struct _FcEdit {
198 struct _FcEdit *next;
202 FcValueBinding binding;
205 typedef struct _FcSubst {
206 struct _FcSubst *next;
211 typedef struct _FcCharLeaf {
212 FcChar32 map[256/32];
215 #define FC_REF_CONSTANT -1
218 int ref; /* reference count */
219 int num; /* size of leaves and numbers arrays */
234 int ref; /* reference count */
245 typedef struct _FcStrBuf {
253 typedef struct _FcCache {
254 int magic; /* 0xFC02FC02 */
255 int count; /* number of bytes of data in block */
256 int bank; /* bank ID */
257 int pattern_count; /* number of FcPatterns */
258 int patternelt_count; /* number of FcPatternElts */
259 int valuelist_count; /* number of FcValueLists */
260 int str_count; /* size of strings appearing as FcValues */
261 int langset_count; /* number of FcLangSets */
262 int charset_count; /* number of FcCharSets */
263 int charset_numbers_count;
264 int charset_leaf_count;
265 int charset_leaf_idx_count;
269 * To map adobe glyph names to unicode values, a precomputed hash
273 typedef struct _FcGlyphName {
274 FcChar32 ucs; /* unicode value */
275 FcChar8 name[1]; /* name extends beyond struct */
279 * To perform case-insensitive string comparisons, a table
280 * is used which holds three different kinds of folding data.
282 * The first is a range of upper case values mapping to a range
283 * of their lower case equivalents. Within each range, the offset
284 * between upper and lower case is constant.
286 * The second is a range of upper case values which are interleaved
287 * with their lower case equivalents.
289 * The third is a set of raw unicode values mapping to a list
290 * of unicode values for comparison purposes. This allows conversion
291 * of ß to "ss" so that SS, ss and ß all match. A separate array
292 * holds the list of unicode values for each entry.
294 * These are packed into a single table. Using a binary search,
295 * the appropriate entry can be located.
298 #define FC_CASE_FOLD_RANGE 0
299 #define FC_CASE_FOLD_EVEN_ODD 1
300 #define FC_CASE_FOLD_FULL 2
302 typedef struct _FcCaseFold {
306 short offset; /* lower - upper for RANGE, table id for FULL */
309 #define FC_MAX_FILE_LEN 4096
311 #define FC_STORAGE_STATIC 0x80
312 #define fc_value_string(v) (((v)->type & FC_STORAGE_STATIC) ? ((FcChar8 *) v) + (v)->u.s_off : (v) -> u.s)
313 #define fc_value_charset(v) (((v)->type & FC_STORAGE_STATIC) ? (const FcCharSet *)(((char *) v) + (v)->u.c_off) : (v) -> u.c)
314 #define fc_value_langset(v) (((v)->type & FC_STORAGE_STATIC) ? (const FcLangSet *)(((char *) v) + (v)->u.l_off) : (v) -> u.l)
315 #define fc_storage_type(v) ((v)->type & ~FC_STORAGE_STATIC)
318 * The per-user ~/.fonts.cache-<version> file is loaded into
319 * this data structure. Each directory gets a substructure
320 * which is validated by comparing the directory timestamp with
321 * that saved in the cache. When valid, the entire directory cache
322 * can be immediately loaded without reading the directory. Otherwise,
323 * the files are checked individually; updated files are loaded into the
324 * cache which is then rewritten to the users home directory
327 #define FC_CACHE_MAGIC 0xFC02FC02
329 typedef struct _FcGlobalCacheDir FcGlobalCacheDir;
331 struct _FcGlobalCacheDir {
332 struct _FcGlobalCacheDir *next;
339 typedef struct _FcGlobalCache {
340 FcGlobalCacheDir *dirs;
346 FcChar8 *file; /* original file name */
347 FcChar8 *new; /* temp file name -- write data here */
348 FcChar8 *lck; /* lockfile name (used for locking) */
349 FcChar8 *tmp; /* tmpfile name (used for locking) */
360 * File names loaded from the configuration -- saved here as the
361 * cache file must be consulted before the directories are scanned,
362 * and those directives may occur in any order
364 FcStrSet *configDirs; /* directories to scan for fonts */
365 FcChar8 *cache; /* name of per-user cache file */
367 * Set of allowed blank chars -- used to
368 * trim fonts of bogus glyphs
372 * List of directories containing fonts,
373 * built by recursively scanning the set
374 * of configured directories
378 * Names of all of the configuration files used
379 * to create this configuration
381 FcStrSet *configFiles; /* config files loaded */
383 * Substitution instructions for patterns and fonts;
384 * maxObjects is used to allocate appropriate intermediate storage
385 * while performing a whole set of substitutions
387 FcSubst *substPattern; /* substitutions for patterns */
388 FcSubst *substFont; /* substitutions for fonts */
389 int maxObjects; /* maximum number of tests in all substs */
391 * List of patterns used to control font file selection
393 FcStrSet *acceptGlobs;
394 FcStrSet *rejectGlobs;
395 FcFontSet *acceptPatterns;
396 FcFontSet *rejectPatterns;
398 * The set of fonts loaded from the listed directories; the
399 * order within the set does not determine the font selection,
400 * except in the case of identical matches in which case earlier fonts
401 * match preferrentially
403 FcFontSet *fonts[FcSetApplication + 1];
405 * Fontconfig can periodically rescan the system configuration
406 * and font directories. This rescanning occurs when font
407 * listing requests are made, but no more often than rescanInterval
410 time_t rescanTime; /* last time information was scanned */
411 int rescanInterval; /* interval between scans */
414 extern FcConfig *_fcConfig;
416 typedef struct _FcFileTime {
421 typedef struct _FcCharMap FcCharMap;
423 #define ALIGN(v,type) ((__typeof__(v))(((uintptr_t)(v) + __alignof__(type) - 1) & ~(__alignof__(type) - 1)))
430 FcGlobalCacheCreate (void);
433 FcGlobalCacheDestroy (FcGlobalCache *cache);
436 FcGlobalCacheReadDir (FcFontSet *set,
438 FcGlobalCache *cache,
443 FcGlobalCacheLoad (FcGlobalCache *cache,
445 const FcChar8 *cache_file,
449 FcGlobalCacheUpdate (FcGlobalCache *cache,
454 FcGlobalCacheSave (FcGlobalCache *cache,
455 const FcChar8 *cache_file);
458 FcCacheRead (FcConfig *config, FcGlobalCache * cache);
461 FcDirCacheWrite (FcFontSet *set, FcStrSet * dirs, const FcChar8 *dir);
464 FcDirCacheRead (FcFontSet * set, FcStrSet * dirs, const FcChar8 *dir);
466 extern int *_fcBankId, *_fcBankIdx;
468 FcCacheBankToIndexMTF (int bank);
470 static __inline__ int
471 FcCacheBankToIndex (int bank)
473 return (_fcBankId[*_fcBankIdx] == bank) ? *_fcBankIdx : FcCacheBankToIndexMTF(bank);
477 FcCacheFindBankDir (int bank);
482 FcConfigAddConfigDir (FcConfig *config,
486 FcConfigAddFontDir (FcConfig *config,
490 FcConfigAddDir (FcConfig *config,
494 FcConfigAddConfigFile (FcConfig *config,
498 FcConfigSetCache (FcConfig *config,
502 FcConfigAddBlank (FcConfig *config,
506 FcConfigAddEdit (FcConfig *config,
512 FcConfigSetFonts (FcConfig *config,
517 FcConfigCompareValue (const FcValue *m,
522 FcConfigGlobAdd (FcConfig *config,
527 FcConfigAcceptFilename (FcConfig *config,
528 const FcChar8 *filename);
531 FcConfigPatternsAdd (FcConfig *config,
536 FcConfigAcceptFont (FcConfig *config,
537 const FcPattern *font);
540 FcConfigModifiedTime (FcConfig *config);
544 FcLangCharSetPopulate (void);
547 FcCharSetFreeze (FcCharSet *cs);
550 FcCharSetThawAll (void);
553 FcNameUnparseCharSet (FcStrBuf *buf, const FcCharSet *c);
556 FcNameParseCharSet (FcChar8 *string);
559 FcCharSetFindLeafCreate (FcCharSet *fcs, FcChar32 ucs4);
562 FcCharSetNewBank (void);
565 FcCharSetNeededBytes (const FcCharSet *c);
568 FcCharSetNeededBytesAlign (void);
571 FcCharSetDistributeBytes (FcCache * metadata,
575 FcCharSetSerialize(int bank, FcCharSet *c);
578 FcCharSetUnserialize (FcCache * metadata, void *block_ptr);
581 FcCharSetGetLeaf(const FcCharSet *c, int i);
584 FcCharSetGetNumbers(const FcCharSet *c);
588 FcValueListPrint (const FcValueListPtr l);
591 FcLangSetPrint (const FcLangSet *ls);
597 FcTestPrint (const FcTest *test);
600 FcExprPrint (const FcExpr *expr);
603 FcEditPrint (const FcEdit *edit);
606 FcSubstPrint (const FcSubst *subst);
608 extern int FcDebugVal;
610 static __inline__ int
611 FcDebug (void) { return FcDebugVal; }
618 FcGetDefaultLang (void);
623 FcFileIsDir (const FcChar8 *file);
626 FcFileScanConfig (FcFontSet *set,
635 FcDirScanConfig (FcFontSet *set,
649 FcFreeTypeIsExclusiveLang (const FcChar8 *lang);
652 FcFreeTypeHasLang (FcPattern *pattern, const FcChar8 *lang);
655 FcFreeTypeUcs4ToPrivate (FcChar32 ucs4, const FcCharMap *map);
658 FcFreeTypePrivateToUcs4 (FcChar32 private, const FcCharMap *map);
661 FcFreeTypeGetPrivateMap (FT_Encoding encoding);
666 FcFontSetNewBank (void);
669 FcFontSetNeededBytes (FcFontSet *s);
672 FcFontSetNeededBytesAlign (void);
675 FcFontSetDistributeBytes (FcCache * metadata, void * block_ptr);
678 FcFontSetSerialize (int bank, FcFontSet * s);
681 FcFontSetUnserialize(FcCache * metadata, FcFontSet * s, void * block_ptr);
685 FcConfigparse (void);
691 FcConfigerror (char *fmt, ...);
694 FcConfigSaveField (const char *field);
697 FcTestDestroy (FcTest *test);
700 FcExprCreateInteger (int i);
703 FcExprCreateDouble (double d);
706 FcExprCreateString (const FcChar8 *s);
709 FcExprCreateMatrix (const FcMatrix *m);
712 FcExprCreateBool (FcBool b);
715 FcExprCreateNil (void);
718 FcExprCreateField (const char *field);
721 FcExprCreateConst (const FcChar8 *constant);
724 FcExprCreateOp (FcExpr *left, FcOp op, FcExpr *right);
727 FcExprDestroy (FcExpr *e);
730 FcEditDestroy (FcEdit *e);
738 FcMemAlloc (int kind, int size);
741 FcMemFree (int kind, int size);
745 FcFreeTypeLangSet (const FcCharSet *charset,
746 const FcChar8 *exclusiveLang);
749 FcLangCompare (const FcChar8 *s1, const FcChar8 *s2);
752 FcCharSetForLang (const FcChar8 *lang);
755 FcLangSetPromote (const FcChar8 *lang);
758 FcNameParseLangSet (const FcChar8 *string);
761 FcNameUnparseLangSet (FcStrBuf *buf, const FcLangSet *ls);
764 FcLangSetNewBank (void);
767 FcLangSetNeededBytes (const FcLangSet *l);
770 FcLangSetNeededBytesAlign (void);
773 FcLangSetDistributeBytes (FcCache * metadata,
777 FcLangSetSerialize (int bank, FcLangSet *l);
780 FcLangSetUnserialize (FcCache * metadata, void *block_ptr);
785 FcListPatternMatchAny (const FcPattern *p,
786 const FcPattern *font);
793 FcNameBool (const FcChar8 *v, FcBool *result);
796 FcObjectDistributeBytes (FcCache * metadata,
800 FcObjectToPtr (const char * si);
803 FcObjectNeededBytes (void);
806 FcObjectNeededBytesAlign (void);
809 FcObjectUnserialize (FcCache * metadata, void *block_ptr);
812 FcObjectSerialize (void);
815 FcObjectPtrU (FcObjectPtr p);
817 static __inline__ int
818 FcObjectPtrCompare (const FcObjectPtr a, const FcObjectPtr b)
824 FcObjectStaticNameFini (void);
829 FcValueCanonicalize (const FcValue *v);
832 FcValueListDestroy (FcValueListPtr l);
835 FcPatternFindElt (const FcPattern *p, const char *object);
838 FcPatternInsertElt (FcPattern *p, const char *object);
841 FcPatternAddWithBinding (FcPattern *p,
844 FcValueBinding binding,
848 FcPatternFreeze (FcPattern *p);
851 FcPatternFini (void);
854 FcPatternAppend (FcPattern *p, FcPattern *s);
857 FcPatternAddFullFname (const FcPattern *p, const char *fname);
860 FcPatternTransferFullFname (const FcPattern *new, const FcPattern *orig);
863 FcStrStaticName (const FcChar8 *name);
866 FcStringHash (const FcChar8 *s);
869 FcPatternNewBank (void);
872 FcPatternNeededBytes (FcPattern *p);
875 FcPatternNeededBytesAlign (void);
878 FcPatternDistributeBytes (FcCache * metadata, void * block_ptr);
880 /* please don't access these outside of fcpat.c! only visible so that
881 * *PtrU can be inlined. */
882 extern FcValueList ** _fcValueLists;
883 extern FcPatternElt ** _fcPatternElts;
885 static __inline__ FcValueList *
886 FcValueListPtrU (FcValueListPtr pi)
888 if (pi.bank == FC_BANK_DYNAMIC)
891 return &_fcValueLists[FcCacheBankToIndex(pi.bank)][pi.u.stat];
894 static __inline__ FcPatternElt *
895 FcPatternEltU (FcPatternEltPtr pei)
897 if (pei.bank == FC_BANK_DYNAMIC)
900 return &_fcPatternElts[FcCacheBankToIndex(pei.bank)][pei.u.stat];
904 FcPatternEltU (FcPatternEltPtr pei);
907 FcValueListPtrCreateDynamic(FcValueList * p);
910 FcPatternSerialize (int bank, FcPattern * p);
913 FcPatternUnserialize (FcCache * metadata, void *block_ptr);
919 extern const FcMatrix FcIdentityMatrix;
922 FcMatrixFree (FcMatrix *mat);
926 FcStrSetSort (FcStrSet * set);
929 FcStrPlus (const FcChar8 *s1, const FcChar8 *s2);
932 FcStrFree (FcChar8 *s);
935 FcStrBufInit (FcStrBuf *buf, FcChar8 *init, int size);
938 FcStrBufDestroy (FcStrBuf *buf);
941 FcStrBufDone (FcStrBuf *buf);
944 FcStrBufChar (FcStrBuf *buf, FcChar8 c);
947 FcStrBufString (FcStrBuf *buf, const FcChar8 *s);
950 FcStrBufData (FcStrBuf *buf, const FcChar8 *s, int len);
953 FcStrCmpIgnoreBlanksAndCase (const FcChar8 *s1, const FcChar8 *s2);
956 FcStrContainsIgnoreBlanksAndCase (const FcChar8 *s1, const FcChar8 *s2);
959 FcStrContainsIgnoreCase (const FcChar8 *s1, const FcChar8 *s2);
962 FcStrUsesHome (const FcChar8 *s);
965 FcStrLastSlash (const FcChar8 *path);
968 FcStrHashIgnoreCase (const FcChar8 *s);
970 #endif /* _FC_INT_H_ */