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.
34 #ifdef HAVE_INTTYPES_H
36 #elif defined(HAVE_STDINT_H)
39 #error missing C99 integer data types
45 #include <sys/types.h>
48 #include <fontconfig/fontconfig.h>
49 #include <fontconfig/fcprivate.h>
50 #include <fontconfig/fcfreetype.h>
52 #ifndef FC_CONFIG_PATH
53 #define FC_CONFIG_PATH "fonts.conf"
56 #define FC_FONT_FILE_INVALID ((FcChar8 *) ".")
57 #define FC_FONT_FILE_DIR ((FcChar8 *) ".dir")
58 #define FC_GLOBAL_MAGIC_COOKIE "GLOBAL"
61 #define FC_SEARCH_PATH_SEPARATOR ';'
63 #define FC_SEARCH_PATH_SEPARATOR ':'
66 #define FC_DBG_MATCH 1
67 #define FC_DBG_MATCHV 2
69 #define FC_DBG_FONTSET 8
70 #define FC_DBG_CACHE 16
71 #define FC_DBG_CACHEV 32
72 #define FC_DBG_PARSE 64
73 #define FC_DBG_SCAN 128
74 #define FC_DBG_SCANV 256
75 #define FC_DBG_MEMORY 512
76 #define FC_DBG_CONFIG 1024
78 #define FC_MEM_CHARSET 0
79 #define FC_MEM_CHARLEAF 1
80 #define FC_MEM_FONTSET 2
81 #define FC_MEM_FONTPTR 3
82 #define FC_MEM_OBJECTSET 4
83 #define FC_MEM_OBJECTPTR 5
84 #define FC_MEM_MATRIX 6
85 #define FC_MEM_PATTERN 7
86 #define FC_MEM_PATELT 8
87 #define FC_MEM_VALLIST 9
88 #define FC_MEM_SUBSTATE 10
89 #define FC_MEM_STRING 11
90 #define FC_MEM_LISTBUCK 12
91 #define FC_MEM_STRSET 13
92 #define FC_MEM_STRLIST 14
93 #define FC_MEM_CONFIG 15
94 #define FC_MEM_LANGSET 16
95 #define FC_MEM_ATOMIC 17
96 #define FC_MEM_BLANKS 18
97 #define FC_MEM_CACHE 19
98 #define FC_MEM_STRBUF 20
99 #define FC_MEM_SUBST 21
100 #define FC_MEM_OBJECTTYPE 22
101 #define FC_MEM_CONSTANT 23
102 #define FC_MEM_TEST 24
103 #define FC_MEM_EXPR 25
104 #define FC_MEM_VSTACK 26
105 #define FC_MEM_ATTR 27
106 #define FC_MEM_PSTACK 28
107 #define FC_MEM_STATICSTR 29
109 #define FC_MEM_NUM 30
111 #define FC_BANK_DYNAMIC 0
112 #define FC_BANK_FIRST 1
113 #define FC_BANK_LANGS 0xfcfcfcfc
115 typedef enum _FcValueBinding {
116 FcValueBindingWeak, FcValueBindingStrong, FcValueBindingSame
119 typedef struct _FcValueListPtr {
123 struct _FcValueList *dyn;
127 typedef struct _FcValueList {
131 FcValueBinding binding;
134 typedef int FcObjectPtr;
136 typedef struct _FcPatternEltPtr {
140 struct _FcPatternElt *dyn;
144 typedef struct _FcPatternElt {
146 FcValueListPtr values;
152 FcPatternEltPtr elts;
158 FcOpInteger, FcOpDouble, FcOpString, FcOpMatrix, FcOpBool, FcOpCharSet,
160 FcOpField, FcOpConst,
161 FcOpAssign, FcOpAssignReplace,
162 FcOpPrependFirst, FcOpPrepend, FcOpAppend, FcOpAppendLast,
164 FcOpOr, FcOpAnd, FcOpEqual, FcOpNotEqual,
165 FcOpContains, FcOpListing, FcOpNotContains,
166 FcOpLess, FcOpLessEqual, FcOpMore, FcOpMoreEqual,
167 FcOpPlus, FcOpMinus, FcOpTimes, FcOpDivide,
168 FcOpNot, FcOpComma, FcOpFloor, FcOpCeil, FcOpRound, FcOpTrunc,
172 typedef struct _FcExpr {
184 struct _FcExpr *left, *right;
189 typedef enum _FcQual {
190 FcQualAny, FcQualAll, FcQualFirst, FcQualNotFirst
193 #define FcMatchDefault ((FcMatchKind) -1)
195 typedef struct _FcTest {
196 struct _FcTest *next;
204 typedef struct _FcEdit {
205 struct _FcEdit *next;
209 FcValueBinding binding;
212 typedef struct _FcSubst {
213 struct _FcSubst *next;
218 typedef struct _FcCharLeaf {
219 FcChar32 map[256/32];
222 #define FC_REF_CONSTANT -1
225 int ref; /* reference count */
226 int num; /* size of leaves and numbers arrays */
241 int ref; /* reference count */
252 typedef struct _FcStrBuf {
260 typedef struct _FcCache {
261 int magic; /* FC_CACHE_MAGIC */
262 int count; /* number of bytes of data in block */
263 int bank; /* bank ID */
264 int pattern_count; /* number of FcPatterns */
265 int patternelt_count; /* number of FcPatternElts */
266 int valuelist_count; /* number of FcValueLists */
267 int str_count; /* size of strings appearing as FcValues */
268 int langset_count; /* number of FcLangSets */
269 int charset_count; /* number of FcCharSets */
270 int charset_numbers_count;
271 int charset_leaf_count;
272 int charset_leaf_idx_count;
276 * To map adobe glyph names to unicode values, a precomputed hash
280 typedef struct _FcGlyphName {
281 FcChar32 ucs; /* unicode value */
282 FcChar8 name[1]; /* name extends beyond struct */
286 * To perform case-insensitive string comparisons, a table
287 * is used which holds three different kinds of folding data.
289 * The first is a range of upper case values mapping to a range
290 * of their lower case equivalents. Within each range, the offset
291 * between upper and lower case is constant.
293 * The second is a range of upper case values which are interleaved
294 * with their lower case equivalents.
296 * The third is a set of raw unicode values mapping to a list
297 * of unicode values for comparison purposes. This allows conversion
298 * of ß to "ss" so that SS, ss and ß all match. A separate array
299 * holds the list of unicode values for each entry.
301 * These are packed into a single table. Using a binary search,
302 * the appropriate entry can be located.
305 #define FC_CASE_FOLD_RANGE 0
306 #define FC_CASE_FOLD_EVEN_ODD 1
307 #define FC_CASE_FOLD_FULL 2
309 typedef struct _FcCaseFold {
313 short offset; /* lower - upper for RANGE, table id for FULL */
316 #define FC_MAX_FILE_LEN 4096
318 #define FC_STORAGE_STATIC 0x80
319 #define fc_value_string(v) (((v)->type & FC_STORAGE_STATIC) ? ((FcChar8 *) v) + (v)->u.s_off : (v) -> u.s)
320 #define fc_value_charset(v) (((v)->type & FC_STORAGE_STATIC) ? (const FcCharSet *)(((char *) v) + (v)->u.c_off) : (v) -> u.c)
321 #define fc_value_langset(v) (((v)->type & FC_STORAGE_STATIC) ? (const FcLangSet *)(((char *) v) + (v)->u.l_off) : (v) -> u.l)
322 #define fc_storage_type(v) ((v)->type & ~FC_STORAGE_STATIC)
325 * The per-user ~/.fonts.cache-<version> file is loaded into
326 * this data structure. Each directory gets a substructure
327 * which is validated by comparing the directory timestamp with
328 * that saved in the cache. When valid, the entire directory cache
329 * can be immediately loaded without reading the directory. Otherwise,
330 * the files are checked individually; updated files are loaded into the
331 * cache which is then rewritten to the users home directory
334 #define FC_CACHE_MAGIC 0xFC02FC03
336 typedef struct _FcGlobalCacheDir FcGlobalCacheDir;
339 FcGCDirDisabled, FcGCDirFileRead, FcGCDirConsumed, FcGCDirUpdated
341 struct _FcGlobalCacheDir {
342 struct _FcGlobalCacheDir *next;
348 enum FcGCDirState state;
351 typedef struct _FcGlobalCache {
352 FcGlobalCacheDir *dirs;
358 FcChar8 *file; /* original file name */
359 FcChar8 *new; /* temp file name -- write data here */
360 FcChar8 *lck; /* lockfile name (used for locking) */
361 FcChar8 *tmp; /* tmpfile name (used for locking) */
372 * File names loaded from the configuration -- saved here as the
373 * cache file must be consulted before the directories are scanned,
374 * and those directives may occur in any order
376 FcStrSet *configDirs; /* directories to scan for fonts */
377 FcChar8 *cache; /* name of per-user cache file */
379 * Set of allowed blank chars -- used to
380 * trim fonts of bogus glyphs
384 * List of directories containing fonts,
385 * built by recursively scanning the set
386 * of configured directories
390 * Names of all of the configuration files used
391 * to create this configuration
393 FcStrSet *configFiles; /* config files loaded */
395 * Substitution instructions for patterns and fonts;
396 * maxObjects is used to allocate appropriate intermediate storage
397 * while performing a whole set of substitutions
399 FcSubst *substPattern; /* substitutions for patterns */
400 FcSubst *substFont; /* substitutions for fonts */
401 int maxObjects; /* maximum number of tests in all substs */
403 * List of patterns used to control font file selection
405 FcStrSet *acceptGlobs;
406 FcStrSet *rejectGlobs;
407 FcFontSet *acceptPatterns;
408 FcFontSet *rejectPatterns;
410 * The set of fonts loaded from the listed directories; the
411 * order within the set does not determine the font selection,
412 * except in the case of identical matches in which case earlier fonts
413 * match preferrentially
415 FcFontSet *fonts[FcSetApplication + 1];
417 * Fontconfig can periodically rescan the system configuration
418 * and font directories. This rescanning occurs when font
419 * listing requests are made, but no more often than rescanInterval
422 time_t rescanTime; /* last time information was scanned */
423 int rescanInterval; /* interval between scans */
426 extern FcConfig *_fcConfig;
428 typedef struct _FcFileTime {
433 typedef struct _FcCharMap FcCharMap;
435 #define ALIGN(v,type) ((__typeof__(v))(((uintptr_t)(v) + __alignof__(type) - 1) & ~(__alignof__(type) - 1)))
442 FcGlobalCacheCreate (void);
445 FcGlobalCacheDestroy (FcGlobalCache *cache);
448 FcGlobalCacheReadDir (FcFontSet *set,
450 FcGlobalCache *cache,
455 FcGlobalCacheLoad (FcGlobalCache *cache,
457 const FcChar8 *cache_file,
461 FcGlobalCacheUpdate (FcGlobalCache *cache,
468 FcGlobalCacheSave (FcGlobalCache *cache,
469 const FcChar8 *cache_file,
473 FcCacheRead (FcConfig *config, FcGlobalCache * cache);
476 FcDirCacheWrite (FcFontSet *set, FcStrSet * dirs, const FcChar8 *dir);
479 FcDirCacheRead (FcFontSet * set, FcStrSet * dirs, const FcChar8 *dir, FcConfig *config);
481 extern int *_fcBankId, *_fcBankIdx;
483 FcCacheBankToIndexMTF (int bank);
485 static __inline__ int
486 FcCacheBankToIndex (int bank)
488 return (_fcBankId[*_fcBankIdx] == bank) ? *_fcBankIdx : FcCacheBankToIndexMTF(bank);
492 FcCacheFindBankDir (int bank);
497 FcConfigAddConfigDir (FcConfig *config,
501 FcConfigAddFontDir (FcConfig *config,
505 FcConfigAddDir (FcConfig *config,
509 FcConfigAddConfigFile (FcConfig *config,
513 FcConfigSetCache (FcConfig *config,
517 FcConfigAddBlank (FcConfig *config,
521 FcConfigAddEdit (FcConfig *config,
527 FcConfigSetFonts (FcConfig *config,
532 FcConfigCompareValue (const FcValue *m,
537 FcConfigGlobAdd (FcConfig *config,
542 FcConfigAcceptFilename (FcConfig *config,
543 const FcChar8 *filename);
546 FcConfigPatternsAdd (FcConfig *config,
551 FcConfigAcceptFont (FcConfig *config,
552 const FcPattern *font);
555 FcConfigModifiedTime (FcConfig *config);
559 FcLangCharSetPopulate (void);
562 FcCharSetFreeze (FcCharSet *cs);
565 FcCharSetThawAll (void);
568 FcNameUnparseCharSet (FcStrBuf *buf, const FcCharSet *c);
571 FcNameParseCharSet (FcChar8 *string);
574 FcCharSetFindLeafCreate (FcCharSet *fcs, FcChar32 ucs4);
577 FcCharSetNewBank (void);
580 FcCharSetNeededBytes (const FcCharSet *c);
583 FcCharSetNeededBytesAlign (void);
586 FcCharSetDistributeBytes (FcCache * metadata,
590 FcCharSetSerialize(int bank, FcCharSet *c);
593 FcCharSetUnserialize (FcCache * metadata, void *block_ptr);
596 FcCharSetGetLeaf(const FcCharSet *c, int i);
599 FcCharSetGetNumbers(const FcCharSet *c);
603 FcValueListPrint (const FcValueListPtr l);
606 FcLangSetPrint (const FcLangSet *ls);
612 FcTestPrint (const FcTest *test);
615 FcExprPrint (const FcExpr *expr);
618 FcEditPrint (const FcEdit *edit);
621 FcSubstPrint (const FcSubst *subst);
623 extern int FcDebugVal;
625 static __inline__ int
626 FcDebug (void) { return FcDebugVal; }
633 FcGetDefaultLang (void);
638 FcFileIsDir (const FcChar8 *file);
641 FcFileScanConfig (FcFontSet *set,
650 FcDirScanConfig (FcFontSet *set,
664 FcFreeTypeIsExclusiveLang (const FcChar8 *lang);
667 FcFreeTypeHasLang (FcPattern *pattern, const FcChar8 *lang);
670 FcFreeTypeUcs4ToPrivate (FcChar32 ucs4, const FcCharMap *map);
673 FcFreeTypePrivateToUcs4 (FcChar32 private, const FcCharMap *map);
676 FcFreeTypeGetPrivateMap (FT_Encoding encoding);
681 FcFontSetNewBank (void);
684 FcFontSetNeededBytes (FcFontSet *s);
687 FcFontSetNeededBytesAlign (void);
690 FcFontSetDistributeBytes (FcCache * metadata, void * block_ptr);
693 FcFontSetSerialize (int bank, FcFontSet * s);
696 FcFontSetUnserialize(FcCache * metadata, FcFontSet * s, void * block_ptr);
700 FcConfigparse (void);
706 FcConfigerror (char *fmt, ...);
709 FcConfigSaveField (const char *field);
712 FcTestDestroy (FcTest *test);
715 FcExprCreateInteger (int i);
718 FcExprCreateDouble (double d);
721 FcExprCreateString (const FcChar8 *s);
724 FcExprCreateMatrix (const FcMatrix *m);
727 FcExprCreateBool (FcBool b);
730 FcExprCreateNil (void);
733 FcExprCreateField (const char *field);
736 FcExprCreateConst (const FcChar8 *constant);
739 FcExprCreateOp (FcExpr *left, FcOp op, FcExpr *right);
742 FcExprDestroy (FcExpr *e);
745 FcEditDestroy (FcEdit *e);
753 FcMemAlloc (int kind, int size);
756 FcMemFree (int kind, int size);
760 FcFreeTypeLangSet (const FcCharSet *charset,
761 const FcChar8 *exclusiveLang);
764 FcLangCompare (const FcChar8 *s1, const FcChar8 *s2);
767 FcCharSetForLang (const FcChar8 *lang);
770 FcLangSetPromote (const FcChar8 *lang);
773 FcNameParseLangSet (const FcChar8 *string);
776 FcNameUnparseLangSet (FcStrBuf *buf, const FcLangSet *ls);
779 FcLangSetNewBank (void);
782 FcLangSetNeededBytes (const FcLangSet *l);
785 FcLangSetNeededBytesAlign (void);
788 FcLangSetDistributeBytes (FcCache * metadata,
792 FcLangSetSerialize (int bank, FcLangSet *l);
795 FcLangSetUnserialize (FcCache * metadata, void *block_ptr);
800 FcListPatternMatchAny (const FcPattern *p,
801 const FcPattern *font);
808 FcNameBool (const FcChar8 *v, FcBool *result);
811 FcObjectDistributeBytes (FcCache * metadata,
815 FcObjectToPtr (const char * si);
818 FcObjectNeededBytes (void);
821 FcObjectNeededBytesAlign (void);
824 FcObjectUnserialize (FcCache * metadata, void *block_ptr);
827 FcObjectSerialize (void);
830 FcObjectPtrU (FcObjectPtr p);
832 static __inline__ int
833 FcObjectPtrCompare (const FcObjectPtr a, const FcObjectPtr b)
839 FcObjectStaticNameFini (void);
844 FcValueCanonicalize (const FcValue *v);
847 FcValueListDestroy (FcValueListPtr l);
850 FcPatternFindElt (const FcPattern *p, const char *object);
853 FcPatternInsertElt (FcPattern *p, const char *object);
856 FcPatternAddWithBinding (FcPattern *p,
859 FcValueBinding binding,
863 FcPatternFreeze (FcPattern *p);
866 FcPatternFini (void);
869 FcPatternAppend (FcPattern *p, FcPattern *s);
872 FcPatternAddFullFname (const FcPattern *p, const char *fname);
875 FcPatternTransferFullFname (const FcPattern *new, const FcPattern *orig);
878 FcStrStaticName (const FcChar8 *name);
881 FcStringHash (const FcChar8 *s);
884 FcPatternNewBank (void);
887 FcPatternNeededBytes (FcPattern *p);
890 FcPatternNeededBytesAlign (void);
893 FcPatternDistributeBytes (FcCache * metadata, void * block_ptr);
895 /* please don't access these outside of fcpat.c! only visible so that
896 * *PtrU can be inlined. */
897 extern FcValueList ** _fcValueLists;
898 extern FcPatternElt ** _fcPatternElts;
900 static __inline__ FcValueList *
901 FcValueListPtrU (FcValueListPtr pi)
903 if (pi.bank == FC_BANK_DYNAMIC)
906 return &_fcValueLists[FcCacheBankToIndex(pi.bank)][pi.u.stat];
909 static __inline__ FcPatternElt *
910 FcPatternEltU (FcPatternEltPtr pei)
912 if (pei.bank == FC_BANK_DYNAMIC)
915 return &_fcPatternElts[FcCacheBankToIndex(pei.bank)][pei.u.stat];
919 FcValueListPtrCreateDynamic(FcValueList * p);
922 FcPatternSerialize (int bank, FcPattern * p);
925 FcPatternUnserialize (FcCache * metadata, void *block_ptr);
931 extern const FcMatrix FcIdentityMatrix;
934 FcMatrixFree (FcMatrix *mat);
938 FcStrSetSort (FcStrSet * set);
941 FcStrPlus (const FcChar8 *s1, const FcChar8 *s2);
944 FcStrFree (FcChar8 *s);
947 FcStrBufInit (FcStrBuf *buf, FcChar8 *init, int size);
950 FcStrBufDestroy (FcStrBuf *buf);
953 FcStrBufDone (FcStrBuf *buf);
956 FcStrBufChar (FcStrBuf *buf, FcChar8 c);
959 FcStrBufString (FcStrBuf *buf, const FcChar8 *s);
962 FcStrBufData (FcStrBuf *buf, const FcChar8 *s, int len);
965 FcStrCmpIgnoreBlanksAndCase (const FcChar8 *s1, const FcChar8 *s2);
968 FcStrContainsIgnoreBlanksAndCase (const FcChar8 *s1, const FcChar8 *s2);
971 FcStrContainsIgnoreCase (const FcChar8 *s1, const FcChar8 *s2);
974 FcStrUsesHome (const FcChar8 *s);
977 FcStrLastSlash (const FcChar8 *path);
980 FcStrHashIgnoreCase (const FcChar8 *s);
982 #endif /* _FC_INT_H_ */