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")
53 #define FC_SEARCH_PATH_SEPARATOR ';'
55 #define FC_SEARCH_PATH_SEPARATOR ':'
58 #define FC_DBG_MATCH 1
59 #define FC_DBG_MATCHV 2
61 #define FC_DBG_FONTSET 8
62 #define FC_DBG_CACHE 16
63 #define FC_DBG_CACHEV 32
64 #define FC_DBG_PARSE 64
65 #define FC_DBG_SCAN 128
66 #define FC_DBG_SCANV 256
67 #define FC_DBG_MEMORY 512
68 #define FC_DBG_CONFIG 1024
70 #define FC_MEM_CHARSET 0
71 #define FC_MEM_CHARLEAF 1
72 #define FC_MEM_FONTSET 2
73 #define FC_MEM_FONTPTR 3
74 #define FC_MEM_OBJECTSET 4
75 #define FC_MEM_OBJECTPTR 5
76 #define FC_MEM_MATRIX 6
77 #define FC_MEM_PATTERN 7
78 #define FC_MEM_PATELT 8
79 #define FC_MEM_VALLIST 9
80 #define FC_MEM_SUBSTATE 10
81 #define FC_MEM_STRING 11
82 #define FC_MEM_LISTBUCK 12
83 #define FC_MEM_STRSET 13
84 #define FC_MEM_STRLIST 14
85 #define FC_MEM_CONFIG 15
86 #define FC_MEM_LANGSET 16
87 #define FC_MEM_ATOMIC 17
88 #define FC_MEM_BLANKS 18
89 #define FC_MEM_CACHE 19
90 #define FC_MEM_STRBUF 20
91 #define FC_MEM_SUBST 21
92 #define FC_MEM_OBJECTTYPE 22
93 #define FC_MEM_CONSTANT 23
94 #define FC_MEM_TEST 24
95 #define FC_MEM_EXPR 25
96 #define FC_MEM_VSTACK 26
97 #define FC_MEM_ATTR 27
98 #define FC_MEM_PSTACK 28
99 #define FC_MEM_STATICSTR 29
101 #define FC_MEM_NUM 30
103 #define FC_BANK_DYNAMIC 0
104 #define FC_BANK_FIRST 1
105 #define FC_BANK_LANGS 0xfcfcfcfc
107 typedef enum _FcValueBinding {
108 FcValueBindingWeak, FcValueBindingStrong, FcValueBindingSame
111 typedef struct _FcValueListPtr {
115 struct _FcValueList *dyn;
119 typedef struct _FcValueList {
123 FcValueBinding binding;
126 typedef int FcObjectPtr;
128 typedef struct _FcPatternEltPtr {
132 struct _FcPatternElt *dyn;
136 typedef struct _FcPatternElt {
138 FcValueListPtr values;
144 FcPatternEltPtr elts;
150 FcOpInteger, FcOpDouble, FcOpString, FcOpMatrix, FcOpBool, FcOpCharSet,
152 FcOpField, FcOpConst,
153 FcOpAssign, FcOpAssignReplace,
154 FcOpPrependFirst, FcOpPrepend, FcOpAppend, FcOpAppendLast,
156 FcOpOr, FcOpAnd, FcOpEqual, FcOpNotEqual,
157 FcOpContains, FcOpListing, FcOpNotContains,
158 FcOpLess, FcOpLessEqual, FcOpMore, FcOpMoreEqual,
159 FcOpPlus, FcOpMinus, FcOpTimes, FcOpDivide,
160 FcOpNot, FcOpComma, FcOpFloor, FcOpCeil, FcOpRound, FcOpTrunc,
164 typedef struct _FcExpr {
176 struct _FcExpr *left, *right;
181 typedef enum _FcQual {
182 FcQualAny, FcQualAll, FcQualFirst, FcQualNotFirst
185 #define FcMatchDefault ((FcMatchKind) -1)
187 typedef struct _FcTest {
188 struct _FcTest *next;
196 typedef struct _FcEdit {
197 struct _FcEdit *next;
201 FcValueBinding binding;
204 typedef struct _FcSubst {
205 struct _FcSubst *next;
210 typedef struct _FcCharLeaf {
211 FcChar32 map[256/32];
214 #define FC_REF_CONSTANT -1
217 int ref; /* reference count */
218 int num; /* size of leaves and numbers arrays */
233 int ref; /* reference count */
244 typedef struct _FcStrBuf {
252 typedef struct _FcCache {
253 int magic; /* 0xFC02FC02 */
254 int count; /* number of bytes of data in block */
255 int bank; /* bank ID */
256 int pattern_count; /* number of FcPatterns */
257 int patternelt_count; /* number of FcPatternElts */
258 int valuelist_count; /* number of FcValueLists */
259 int str_count; /* size of strings appearing as FcValues */
260 int langset_count; /* number of FcLangSets */
261 int charset_count; /* number of FcCharSets */
262 int charset_numbers_count;
263 int charset_leaf_count;
264 int charset_leaf_idx_count;
268 * To map adobe glyph names to unicode values, a precomputed hash
272 typedef struct _FcGlyphName {
273 FcChar32 ucs; /* unicode value */
274 FcChar8 name[1]; /* name extends beyond struct */
278 * To perform case-insensitive string comparisons, a table
279 * is used which holds three different kinds of folding data.
281 * The first is a range of upper case values mapping to a range
282 * of their lower case equivalents. Within each range, the offset
283 * between upper and lower case is constant.
285 * The second is a range of upper case values which are interleaved
286 * with their lower case equivalents.
288 * The third is a set of raw unicode values mapping to a list
289 * of unicode values for comparison purposes. This allows conversion
290 * of ß to "ss" so that SS, ss and ß all match. A separate array
291 * holds the list of unicode values for each entry.
293 * These are packed into a single table. Using a binary search,
294 * the appropriate entry can be located.
297 #define FC_CASE_FOLD_RANGE 0
298 #define FC_CASE_FOLD_EVEN_ODD 1
299 #define FC_CASE_FOLD_FULL 2
301 typedef struct _FcCaseFold {
305 short offset; /* lower - upper for RANGE, table id for FULL */
308 #define FC_MAX_FILE_LEN 4096
310 #define FC_STORAGE_STATIC 0x80
311 #define fc_value_string(v) (((v)->type & FC_STORAGE_STATIC) ? ((FcChar8 *) v) + (v)->u.s_off : (v) -> u.s)
312 #define fc_value_charset(v) (((v)->type & FC_STORAGE_STATIC) ? (const FcCharSet *)(((char *) v) + (v)->u.c_off) : (v) -> u.c)
313 #define fc_value_langset(v) (((v)->type & FC_STORAGE_STATIC) ? (const FcLangSet *)(((char *) v) + (v)->u.l_off) : (v) -> u.l)
314 #define fc_storage_type(v) ((v)->type & ~FC_STORAGE_STATIC)
317 * The per-user ~/.fonts.cache-<version> file is loaded into
318 * this data structure. Each directory gets a substructure
319 * which is validated by comparing the directory timestamp with
320 * that saved in the cache. When valid, the entire directory cache
321 * can be immediately loaded without reading the directory. Otherwise,
322 * the files are checked individually; updated files are loaded into the
323 * cache which is then rewritten to the users home directory
326 #define FC_CACHE_MAGIC 0xFC02FC02
328 typedef struct _FcGlobalCacheDir FcGlobalCacheDir;
330 struct _FcGlobalCacheDir {
331 struct _FcGlobalCacheDir *next;
338 typedef struct _FcGlobalCache {
339 FcGlobalCacheDir *dirs;
345 FcChar8 *file; /* original file name */
346 FcChar8 *new; /* temp file name -- write data here */
347 FcChar8 *lck; /* lockfile name (used for locking) */
348 FcChar8 *tmp; /* tmpfile name (used for locking) */
359 * File names loaded from the configuration -- saved here as the
360 * cache file must be consulted before the directories are scanned,
361 * and those directives may occur in any order
363 FcStrSet *configDirs; /* directories to scan for fonts */
364 FcChar8 *cache; /* name of per-user cache file */
366 * Set of allowed blank chars -- used to
367 * trim fonts of bogus glyphs
371 * List of directories containing fonts,
372 * built by recursively scanning the set
373 * of configured directories
377 * Names of all of the configuration files used
378 * to create this configuration
380 FcStrSet *configFiles; /* config files loaded */
382 * Substitution instructions for patterns and fonts;
383 * maxObjects is used to allocate appropriate intermediate storage
384 * while performing a whole set of substitutions
386 FcSubst *substPattern; /* substitutions for patterns */
387 FcSubst *substFont; /* substitutions for fonts */
388 int maxObjects; /* maximum number of tests in all substs */
390 * List of patterns used to control font file selection
392 FcStrSet *acceptGlobs;
393 FcStrSet *rejectGlobs;
394 FcFontSet *acceptPatterns;
395 FcFontSet *rejectPatterns;
397 * The set of fonts loaded from the listed directories; the
398 * order within the set does not determine the font selection,
399 * except in the case of identical matches in which case earlier fonts
400 * match preferrentially
402 FcFontSet *fonts[FcSetApplication + 1];
404 * Fontconfig can periodically rescan the system configuration
405 * and font directories. This rescanning occurs when font
406 * listing requests are made, but no more often than rescanInterval
409 time_t rescanTime; /* last time information was scanned */
410 int rescanInterval; /* interval between scans */
413 extern FcConfig *_fcConfig;
415 typedef struct _FcFileTime {
420 typedef struct _FcCharMap FcCharMap;
422 #define ALIGN(v,type) ((__typeof__(v))(((uintptr_t)(v) + __alignof__(type) - 1) & ~(__alignof__(type) - 1)))
429 FcGlobalCacheCreate (void);
432 FcGlobalCacheDestroy (FcGlobalCache *cache);
435 FcGlobalCacheReadDir (FcFontSet *set,
437 FcGlobalCache *cache,
442 FcGlobalCacheLoad (FcGlobalCache *cache,
444 const FcChar8 *cache_file,
448 FcGlobalCacheUpdate (FcGlobalCache *cache,
453 FcGlobalCacheSave (FcGlobalCache *cache,
454 const FcChar8 *cache_file);
457 FcCacheRead (FcConfig *config, FcGlobalCache * cache);
460 FcDirCacheWrite (FcFontSet *set, FcStrSet * dirs, const FcChar8 *dir);
463 FcDirCacheRead (FcFontSet * set, FcStrSet * dirs, const FcChar8 *dir);
465 extern int *_fcBankId, *_fcBankIdx;
467 FcCacheBankToIndexMTF (int bank);
469 static __inline__ int
470 FcCacheBankToIndex (int bank)
472 return (_fcBankId[*_fcBankIdx] == bank) ? *_fcBankIdx : FcCacheBankToIndexMTF(bank);
476 FcCacheFindBankDir (int bank);
481 FcConfigAddConfigDir (FcConfig *config,
485 FcConfigAddFontDir (FcConfig *config,
489 FcConfigAddDir (FcConfig *config,
493 FcConfigAddConfigFile (FcConfig *config,
497 FcConfigSetCache (FcConfig *config,
501 FcConfigAddBlank (FcConfig *config,
505 FcConfigAddEdit (FcConfig *config,
511 FcConfigSetFonts (FcConfig *config,
516 FcConfigCompareValue (const FcValue *m,
521 FcConfigGlobAdd (FcConfig *config,
526 FcConfigAcceptFilename (FcConfig *config,
527 const FcChar8 *filename);
530 FcConfigPatternsAdd (FcConfig *config,
535 FcConfigAcceptFont (FcConfig *config,
536 const FcPattern *font);
539 FcConfigModifiedTime (FcConfig *config);
543 FcLangCharSetPopulate (void);
546 FcCharSetFreeze (FcCharSet *cs);
549 FcCharSetThawAll (void);
552 FcNameUnparseCharSet (FcStrBuf *buf, const FcCharSet *c);
555 FcNameParseCharSet (FcChar8 *string);
558 FcCharSetFindLeafCreate (FcCharSet *fcs, FcChar32 ucs4);
561 FcCharSetNewBank (void);
564 FcCharSetNeededBytes (const FcCharSet *c);
567 FcCharSetNeededBytesAlign (void);
570 FcCharSetDistributeBytes (FcCache * metadata,
574 FcCharSetSerialize(int bank, FcCharSet *c);
577 FcCharSetUnserialize (FcCache * metadata, void *block_ptr);
580 FcCharSetGetLeaf(const FcCharSet *c, int i);
583 FcCharSetGetNumbers(const FcCharSet *c);
587 FcValueListPrint (const FcValueListPtr l);
590 FcLangSetPrint (const FcLangSet *ls);
596 FcTestPrint (const FcTest *test);
599 FcExprPrint (const FcExpr *expr);
602 FcEditPrint (const FcEdit *edit);
605 FcSubstPrint (const FcSubst *subst);
607 extern int FcDebugVal;
609 static __inline__ int
610 FcDebug (void) { return FcDebugVal; }
617 FcGetDefaultLang (void);
622 FcFileIsDir (const FcChar8 *file);
625 FcFileScanConfig (FcFontSet *set,
634 FcDirScanConfig (FcFontSet *set,
648 FcFreeTypeIsExclusiveLang (const FcChar8 *lang);
651 FcFreeTypeHasLang (FcPattern *pattern, const FcChar8 *lang);
654 FcFreeTypeUcs4ToPrivate (FcChar32 ucs4, const FcCharMap *map);
657 FcFreeTypePrivateToUcs4 (FcChar32 private, const FcCharMap *map);
660 FcFreeTypeGetPrivateMap (FT_Encoding encoding);
665 FcFontSetNewBank (void);
668 FcFontSetNeededBytes (FcFontSet *s);
671 FcFontSetNeededBytesAlign (void);
674 FcFontSetDistributeBytes (FcCache * metadata, void * block_ptr);
677 FcFontSetSerialize (int bank, FcFontSet * s);
680 FcFontSetUnserialize(FcCache * metadata, FcFontSet * s, void * block_ptr);
684 FcConfigparse (void);
690 FcConfigerror (char *fmt, ...);
693 FcConfigSaveField (const char *field);
696 FcTestDestroy (FcTest *test);
699 FcExprCreateInteger (int i);
702 FcExprCreateDouble (double d);
705 FcExprCreateString (const FcChar8 *s);
708 FcExprCreateMatrix (const FcMatrix *m);
711 FcExprCreateBool (FcBool b);
714 FcExprCreateNil (void);
717 FcExprCreateField (const char *field);
720 FcExprCreateConst (const FcChar8 *constant);
723 FcExprCreateOp (FcExpr *left, FcOp op, FcExpr *right);
726 FcExprDestroy (FcExpr *e);
729 FcEditDestroy (FcEdit *e);
737 FcMemAlloc (int kind, int size);
740 FcMemFree (int kind, int size);
744 FcFreeTypeLangSet (const FcCharSet *charset,
745 const FcChar8 *exclusiveLang);
748 FcLangCompare (const FcChar8 *s1, const FcChar8 *s2);
751 FcCharSetForLang (const FcChar8 *lang);
754 FcLangSetPromote (const FcChar8 *lang);
757 FcNameParseLangSet (const FcChar8 *string);
760 FcNameUnparseLangSet (FcStrBuf *buf, const FcLangSet *ls);
763 FcLangSetNewBank (void);
766 FcLangSetNeededBytes (const FcLangSet *l);
769 FcLangSetNeededBytesAlign (void);
772 FcLangSetDistributeBytes (FcCache * metadata,
776 FcLangSetSerialize (int bank, FcLangSet *l);
779 FcLangSetUnserialize (FcCache * metadata, void *block_ptr);
784 FcListPatternMatchAny (const FcPattern *p,
785 const FcPattern *font);
792 FcNameBool (const FcChar8 *v, FcBool *result);
795 FcObjectDistributeBytes (FcCache * metadata,
799 FcObjectToPtr (const char * si);
802 FcObjectNeededBytes (void);
805 FcObjectNeededBytesAlign (void);
808 FcObjectUnserialize (FcCache * metadata, void *block_ptr);
811 FcObjectSerialize (void);
814 FcObjectPtrU (FcObjectPtr p);
816 static __inline__ int
817 FcObjectPtrCompare (const FcObjectPtr a, const FcObjectPtr b)
823 FcObjectStaticNameFini (void);
828 FcValueCanonicalize (const FcValue *v);
831 FcValueListDestroy (FcValueListPtr l);
834 FcPatternFindElt (const FcPattern *p, const char *object);
837 FcPatternInsertElt (FcPattern *p, const char *object);
840 FcPatternAddWithBinding (FcPattern *p,
843 FcValueBinding binding,
847 FcPatternFreeze (FcPattern *p);
850 FcPatternFini (void);
853 FcPatternAppend (FcPattern *p, FcPattern *s);
856 FcPatternAddFullFname (const FcPattern *p, const char *fname);
859 FcPatternTransferFullFname (const FcPattern *new, const FcPattern *orig);
862 FcStrStaticName (const FcChar8 *name);
865 FcStringHash (const FcChar8 *s);
868 FcPatternNewBank (void);
871 FcPatternNeededBytes (FcPattern *p);
874 FcPatternNeededBytesAlign (void);
877 FcPatternDistributeBytes (FcCache * metadata, void * block_ptr);
879 /* please don't access these outside of fcpat.c! only visible so that
880 * *PtrU can be inlined. */
881 extern FcValueList ** _fcValueLists;
882 extern FcPatternElt ** _fcPatternElts;
884 static __inline__ FcValueList *
885 FcValueListPtrU (FcValueListPtr pi)
887 if (pi.bank == FC_BANK_DYNAMIC)
890 return &_fcValueLists[FcCacheBankToIndex(pi.bank)][pi.u.stat];
893 static __inline__ FcPatternElt *
894 FcPatternEltU (FcPatternEltPtr pei)
896 if (pei.bank == FC_BANK_DYNAMIC)
899 return &_fcPatternElts[FcCacheBankToIndex(pei.bank)][pei.u.stat];
903 FcPatternEltU (FcPatternEltPtr pei);
906 FcValueListPtrCreateDynamic(FcValueList * p);
909 FcPatternSerialize (int bank, FcPattern * p);
912 FcPatternUnserialize (FcCache * metadata, void *block_ptr);
918 extern const FcMatrix FcIdentityMatrix;
921 FcMatrixFree (FcMatrix *mat);
925 FcStrSetSort (FcStrSet * set);
928 FcStrPlus (const FcChar8 *s1, const FcChar8 *s2);
931 FcStrFree (FcChar8 *s);
934 FcStrBufInit (FcStrBuf *buf, FcChar8 *init, int size);
937 FcStrBufDestroy (FcStrBuf *buf);
940 FcStrBufDone (FcStrBuf *buf);
943 FcStrBufChar (FcStrBuf *buf, FcChar8 c);
946 FcStrBufString (FcStrBuf *buf, const FcChar8 *s);
949 FcStrBufData (FcStrBuf *buf, const FcChar8 *s, int len);
952 FcStrCmpIgnoreBlanksAndCase (const FcChar8 *s1, const FcChar8 *s2);
955 FcStrContainsIgnoreBlanksAndCase (const FcChar8 *s1, const FcChar8 *s2);
958 FcStrContainsIgnoreCase (const FcChar8 *s1, const FcChar8 *s2);
961 FcStrUsesHome (const FcChar8 *s);
964 FcStrLastSlash (const FcChar8 *path);
967 FcStrHashIgnoreCase (const FcChar8 *s);
969 #endif /* _FC_INT_H_ */