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 #include <sys/types.h>
37 #include <fontconfig/fontconfig.h>
38 #include <fontconfig/fcprivate.h>
39 #include <fontconfig/fcfreetype.h>
45 typedef struct _FcSymbolic {
50 #ifndef FC_CONFIG_PATH
51 #define FC_CONFIG_PATH "fonts.conf"
54 #define FC_FONT_FILE_INVALID ((FcChar8 *) ".")
55 #define FC_FONT_FILE_DIR ((FcChar8 *) ".dir")
58 #define FC_SEARCH_PATH_SEPARATOR ';'
60 #define FC_SEARCH_PATH_SEPARATOR ':'
63 #define FC_DBG_MATCH 1
64 #define FC_DBG_MATCHV 2
66 #define FC_DBG_FONTSET 8
67 #define FC_DBG_CACHE 16
68 #define FC_DBG_CACHEV 32
69 #define FC_DBG_PARSE 64
70 #define FC_DBG_SCAN 128
71 #define FC_DBG_SCANV 256
72 #define FC_DBG_MEMORY 512
73 #define FC_DBG_CONFIG 1024
75 #define FC_MEM_CHARSET 0
76 #define FC_MEM_CHARLEAF 1
77 #define FC_MEM_FONTSET 2
78 #define FC_MEM_FONTPTR 3
79 #define FC_MEM_OBJECTSET 4
80 #define FC_MEM_OBJECTPTR 5
81 #define FC_MEM_MATRIX 6
82 #define FC_MEM_PATTERN 7
83 #define FC_MEM_PATELT 8
84 #define FC_MEM_VALLIST 9
85 #define FC_MEM_SUBSTATE 10
86 #define FC_MEM_STRING 11
87 #define FC_MEM_LISTBUCK 12
88 #define FC_MEM_STRSET 13
89 #define FC_MEM_STRLIST 14
90 #define FC_MEM_CONFIG 15
91 #define FC_MEM_LANGSET 16
92 #define FC_MEM_ATOMIC 17
93 #define FC_MEM_BLANKS 18
94 #define FC_MEM_CACHE 19
95 #define FC_MEM_STRBUF 20
96 #define FC_MEM_SUBST 21
97 #define FC_MEM_OBJECTTYPE 22
98 #define FC_MEM_CONSTANT 23
99 #define FC_MEM_TEST 24
100 #define FC_MEM_EXPR 25
101 #define FC_MEM_VSTACK 26
102 #define FC_MEM_ATTR 27
103 #define FC_MEM_PSTACK 28
104 #define FC_MEM_STATICSTR 29
106 #define FC_MEM_NUM 30
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 {
258 int patternelt_count;
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)
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 0x12345678
327 #define FC_GLOBAL_CACHE_DIR_HASH_SIZE 37
328 #define FC_GLOBAL_CACHE_FILE_HASH_SIZE 67
330 typedef struct _FcGlobalCacheInfo {
337 typedef struct _FcGlobalCacheFile {
338 struct _FcGlobalCacheFile *next;
339 FcGlobalCacheInfo info;
344 typedef struct _FcGlobalCacheDir FcGlobalCacheDir;
346 typedef struct _FcGlobalCacheSubdir {
347 struct _FcGlobalCacheSubdir *next;
348 FcGlobalCacheDir *ent;
349 } FcGlobalCacheSubdir;
351 struct _FcGlobalCacheDir {
352 struct _FcGlobalCacheDir *next;
353 FcGlobalCacheInfo info;
355 FcGlobalCacheFile *ents[FC_GLOBAL_CACHE_FILE_HASH_SIZE];
356 FcGlobalCacheSubdir *subdirs;
359 typedef struct _FcGlobalCache {
360 FcGlobalCacheDir *ents[FC_GLOBAL_CACHE_DIR_HASH_SIZE];
368 FcChar8 *file; /* original file name */
369 FcChar8 *new; /* temp file name -- write data here */
370 FcChar8 *lck; /* lockfile name (used for locking) */
371 FcChar8 *tmp; /* tmpfile name (used for locking) */
382 * File names loaded from the configuration -- saved here as the
383 * cache file must be consulted before the directories are scanned,
384 * and those directives may occur in any order
386 FcStrSet *configDirs; /* directories to scan for fonts */
387 FcChar8 *cache; /* name of per-user cache file */
389 * Set of allowed blank chars -- used to
390 * trim fonts of bogus glyphs
394 * List of directories containing fonts,
395 * built by recursively scanning the set
396 * of configured directories
400 * Names of all of the configuration files used
401 * to create this configuration
403 FcStrSet *configFiles; /* config files loaded */
405 * Substitution instructions for patterns and fonts;
406 * maxObjects is used to allocate appropriate intermediate storage
407 * while performing a whole set of substitutions
409 FcSubst *substPattern; /* substitutions for patterns */
410 FcSubst *substFont; /* substitutions for fonts */
411 int maxObjects; /* maximum number of tests in all substs */
413 * List of patterns used to control font file selection
415 FcStrSet *acceptGlobs;
416 FcStrSet *rejectGlobs;
417 FcFontSet *acceptPatterns;
418 FcFontSet *rejectPatterns;
420 * The set of fonts loaded from the listed directories; the
421 * order within the set does not determine the font selection,
422 * except in the case of identical matches in which case earlier fonts
423 * match preferrentially
425 FcFontSet *fonts[FcSetApplication + 1];
427 * Fontconfig can periodically rescan the system configuration
428 * and font directories. This rescanning occurs when font
429 * listing requests are made, but no more often than rescanInterval
432 time_t rescanTime; /* last time information was scanned */
433 int rescanInterval; /* interval between scans */
436 extern FcConfig *_fcConfig;
438 typedef struct _FcCharMap FcCharMap;
445 FcGlobalCacheCreate (void);
448 FcGlobalCacheDestroy (FcGlobalCache *cache);
451 FcGlobalCacheCheckTime (const FcChar8*file, FcGlobalCacheInfo *info);
454 FcGlobalCacheReferenced (FcGlobalCache *cache,
455 FcGlobalCacheInfo *info);
458 FcGlobalCacheReferenceSubdir (FcGlobalCache *cache,
462 FcGlobalCacheDirGet (FcGlobalCache *cache,
465 FcBool create_missing);
468 FcGlobalCacheScanDir (FcFontSet *set,
470 FcGlobalCache *cache,
475 FcGlobalCacheFileGet (FcGlobalCache *cache,
482 FcGlobalCacheLoad (FcGlobalCache *cache,
483 const FcChar8 *cache_file);
486 FcGlobalCacheUpdate (FcGlobalCache *cache,
489 const FcChar8 *name);
492 FcGlobalCacheSave (FcGlobalCache *cache,
493 const FcChar8 *cache_file);
496 FcCacheForce(FcBool force);
499 FcCacheSerialize (int bank, FcConfig * config);
502 FcCacheRead (FcConfig *config, FcGlobalCache * cache);
505 FcDirCacheRead (FcFontSet * set, const FcChar8 *dir);
508 FcDirCacheWrite (int bank, FcFontSet *set, const FcChar8 *dir);
511 FcCacheBankCount (void);
514 FcCacheHaveBank (int bank);
517 FcCacheBankToIndex (int bank);
522 FcConfigAddConfigDir (FcConfig *config,
526 FcConfigAddFontDir (FcConfig *config,
530 FcConfigAddDir (FcConfig *config,
534 FcConfigAddConfigFile (FcConfig *config,
538 FcConfigSetCache (FcConfig *config,
542 FcConfigAddBlank (FcConfig *config,
546 FcConfigAddEdit (FcConfig *config,
552 FcConfigSetFonts (FcConfig *config,
557 FcConfigCompareValue (const FcValue *m,
562 FcConfigGlobAdd (FcConfig *config,
567 FcConfigAcceptFilename (FcConfig *config,
568 const FcChar8 *filename);
571 FcConfigPatternsAdd (FcConfig *config,
576 FcConfigAcceptFont (FcConfig *config,
577 const FcPattern *font);
581 FcCharSetFreeze (FcCharSet *cs);
584 FcCharSetThawAll (void);
587 FcNameUnparseCharSet (FcStrBuf *buf, const FcCharSet *c);
590 FcNameParseCharSet (FcChar8 *string);
593 FcCharSetFindLeafCreate (FcCharSet *fcs, FcChar32 ucs4);
596 FcCharSetNewBank (void);
599 FcCharSetNeededBytes (const FcCharSet *c);
602 FcCharSetDistributeBytes (FcCache * metadata,
606 FcCharSetSerialize(int bank, FcCharSet *c);
609 FcCharSetUnserialize (FcCache metadata, void *block_ptr);
612 FcCharSetGetLeaf(const FcCharSet *c, int i);
615 FcCharSetGetNumbers(const FcCharSet *c);
619 FcValueListPrint (const FcValueListPtr l);
622 FcLangSetPrint (const FcLangSet *ls);
628 FcTestPrint (const FcTest *test);
631 FcExprPrint (const FcExpr *expr);
634 FcEditPrint (const FcEdit *edit);
637 FcSubstPrint (const FcSubst *subst);
645 FcFileIsDir (const FcChar8 *file);
648 FcFileScanConfig (FcFontSet *set,
657 FcDirScanConfig (FcFontSet *set,
671 FcFreeTypeIsExclusiveLang (const FcChar8 *lang);
674 FcFreeTypeHasLang (FcPattern *pattern, const FcChar8 *lang);
677 FcFreeTypeUcs4ToPrivate (FcChar32 ucs4, const FcCharMap *map);
680 FcFreeTypePrivateToUcs4 (FcChar32 private, const FcCharMap *map);
683 FcFreeTypeGetPrivateMap (FT_Encoding encoding);
688 FcFontSetNewBank (void);
691 FcFontSetNeededBytes (FcFontSet *s);
694 FcFontSetDistributeBytes (FcCache * metadata, void * block_ptr);
697 FcFontSetSerialize (int bank, FcFontSet * s);
700 FcFontSetUnserialize(FcCache metadata, FcFontSet * s, void * block_ptr);
704 FcConfigparse (void);
710 FcConfigerror (char *fmt, ...);
713 FcConfigSaveField (const char *field);
716 FcTestDestroy (FcTest *test);
719 FcExprCreateInteger (int i);
722 FcExprCreateDouble (double d);
725 FcExprCreateString (const FcChar8 *s);
728 FcExprCreateMatrix (const FcMatrix *m);
731 FcExprCreateBool (FcBool b);
734 FcExprCreateNil (void);
737 FcExprCreateField (const char *field);
740 FcExprCreateConst (const FcChar8 *constant);
743 FcExprCreateOp (FcExpr *left, FcOp op, FcExpr *right);
746 FcExprDestroy (FcExpr *e);
749 FcEditDestroy (FcEdit *e);
757 FcMemAlloc (int kind, int size);
760 FcMemFree (int kind, int size);
764 FcFreeTypeLangSet (const FcCharSet *charset,
765 const FcChar8 *exclusiveLang);
768 FcLangCompare (const FcChar8 *s1, const FcChar8 *s2);
771 FcCharSetForLang (const FcChar8 *lang);
774 FcLangSetPromote (const FcChar8 *lang);
777 FcNameParseLangSet (const FcChar8 *string);
780 FcNameUnparseLangSet (FcStrBuf *buf, const FcLangSet *ls);
783 FcLangSetNewBank (void);
786 FcLangSetNeededBytes (const FcLangSet *l);
789 FcLangSetDistributeBytes (FcCache * metadata,
793 FcLangSetSerialize (int bank, FcLangSet *l);
796 FcLangSetUnserialize (FcCache metadata, void *block_ptr);
801 FcListPatternMatchAny (const FcPattern *p,
802 const FcPattern *font);
809 FcNameBool (const FcChar8 *v, FcBool *result);
812 FcObjectDistributeBytes (FcCache * metadata,
816 FcObjectToPtr (const char * si);
819 FcObjectNeededBytes (void);
822 FcObjectUnserialize (FcCache metadata, void *block_ptr);
825 FcObjectSerialize (void);
828 FcObjectPtrU (FcObjectPtr p);
831 FcObjectPtrCompare (FcObjectPtr a, FcObjectPtr b);
834 FcObjectStaticNameFini (void);
839 FcValueCanonicalize (const FcValue *v);
842 FcValueListDestroy (FcValueListPtr l);
845 FcPatternFindElt (const FcPattern *p, const char *object);
848 FcPatternInsertElt (FcPattern *p, const char *object);
851 FcPatternAddWithBinding (FcPattern *p,
854 FcValueBinding binding,
858 FcPatternFreeze (FcPattern *p);
861 FcPatternFini (void);
864 FcPatternAppend (FcPattern *p, FcPattern *s);
867 FcStrStaticName (const char *name);
870 FcStringHash (const FcChar8 *s);
873 FcPatternNewBank (void);
876 FcPatternNeededBytes (FcPattern *p);
879 FcPatternDistributeBytes (FcCache * metadata, void * block_ptr);
882 FcValueListPtrU(FcValueListPtr p);
885 FcPatternEltU (FcPatternEltPtr pei);
888 FcValueListPtrCreateDynamic(FcValueList * p);
891 FcPatternSerialize (int bank, FcPattern * p);
894 FcPatternUnserialize (FcCache metadata, void *block_ptr);
900 extern const FcMatrix FcIdentityMatrix;
903 FcMatrixFree (FcMatrix *mat);
907 FcStrSetSort (FcStrSet * set);
910 FcStrPlus (const FcChar8 *s1, const FcChar8 *s2);
913 FcStrFree (FcChar8 *s);
916 FcStrBufInit (FcStrBuf *buf, FcChar8 *init, int size);
919 FcStrBufDestroy (FcStrBuf *buf);
922 FcStrBufDone (FcStrBuf *buf);
925 FcStrBufChar (FcStrBuf *buf, FcChar8 c);
928 FcStrBufString (FcStrBuf *buf, const FcChar8 *s);
931 FcStrBufData (FcStrBuf *buf, const FcChar8 *s, int len);
934 FcStrCmpIgnoreBlanksAndCase (const FcChar8 *s1, const FcChar8 *s2);
937 FcStrContainsIgnoreBlanksAndCase (const FcChar8 *s1, const FcChar8 *s2);
940 FcStrContainsIgnoreCase (const FcChar8 *s1, const FcChar8 *s2);
943 FcStrUsesHome (const FcChar8 *s);
946 FcStrLastSlash (const FcChar8 *path);
949 FcStrHashIgnoreCase (const FcChar8 *s);
951 #endif /* _FC_INT_H_ */