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 FcCacheForce(FcBool force);
448 FcCacheSerialize (int bank, FcConfig * config);
451 FcCacheRead (FcConfig *config);
454 FcDirCacheRead (FcFontSet * set, const FcChar8 *dir);
457 FcDirCacheWrite (int bank, FcFontSet *set, const FcChar8 *dir);
460 FcCacheBankCount (void);
463 FcCacheHaveBank (int bank);
466 FcCacheBankToIndex (int bank);
471 FcConfigAddConfigDir (FcConfig *config,
475 FcConfigAddFontDir (FcConfig *config,
479 FcConfigAddDir (FcConfig *config,
483 FcConfigAddConfigFile (FcConfig *config,
487 FcConfigSetCache (FcConfig *config,
491 FcConfigAddBlank (FcConfig *config,
495 FcConfigAddEdit (FcConfig *config,
501 FcConfigSetFonts (FcConfig *config,
506 FcConfigCompareValue (const FcValue *m,
511 FcConfigGlobAdd (FcConfig *config,
516 FcConfigAcceptFilename (FcConfig *config,
517 const FcChar8 *filename);
520 FcConfigPatternsAdd (FcConfig *config,
525 FcConfigAcceptFont (FcConfig *config,
526 const FcPattern *font);
530 FcCharSetFreeze (FcCharSet *cs);
533 FcCharSetThawAll (void);
536 FcNameUnparseCharSet (FcStrBuf *buf, const FcCharSet *c);
539 FcNameParseCharSet (FcChar8 *string);
542 FcCharSetFindLeafCreate (FcCharSet *fcs, FcChar32 ucs4);
545 FcCharSetNewBank (void);
548 FcCharSetNeededBytes (const FcCharSet *c);
551 FcCharSetDistributeBytes (FcCache * metadata,
555 FcCharSetSerialize(int bank, FcCharSet *c);
558 FcCharSetUnserialize (FcCache metadata, void *block_ptr);
561 FcCharSetGetLeaf(const FcCharSet *c, int i);
564 FcCharSetGetNumbers(const FcCharSet *c);
568 FcValueListPrint (const FcValueListPtr l);
571 FcLangSetPrint (const FcLangSet *ls);
577 FcTestPrint (const FcTest *test);
580 FcExprPrint (const FcExpr *expr);
583 FcEditPrint (const FcEdit *edit);
586 FcSubstPrint (const FcSubst *subst);
594 FcFileIsDir (const FcChar8 *file);
597 FcFileScanConfig (FcFontSet *set,
606 FcDirScanConfig (FcFontSet *set,
620 FcFreeTypeIsExclusiveLang (const FcChar8 *lang);
623 FcFreeTypeHasLang (FcPattern *pattern, const FcChar8 *lang);
626 FcFreeTypeUcs4ToPrivate (FcChar32 ucs4, const FcCharMap *map);
629 FcFreeTypePrivateToUcs4 (FcChar32 private, const FcCharMap *map);
632 FcFreeTypeGetPrivateMap (FT_Encoding encoding);
637 FcFontSetNewBank (void);
640 FcFontSetNeededBytes (FcFontSet *s);
643 FcFontSetDistributeBytes (FcCache * metadata, void * block_ptr);
646 FcFontSetSerialize (int bank, FcFontSet * s);
649 FcFontSetUnserialize(FcCache metadata, FcFontSet * s, void * block_ptr);
653 FcConfigparse (void);
659 FcConfigerror (char *fmt, ...);
662 FcConfigSaveField (const char *field);
665 FcTestDestroy (FcTest *test);
668 FcExprCreateInteger (int i);
671 FcExprCreateDouble (double d);
674 FcExprCreateString (const FcChar8 *s);
677 FcExprCreateMatrix (const FcMatrix *m);
680 FcExprCreateBool (FcBool b);
683 FcExprCreateNil (void);
686 FcExprCreateField (const char *field);
689 FcExprCreateConst (const FcChar8 *constant);
692 FcExprCreateOp (FcExpr *left, FcOp op, FcExpr *right);
695 FcExprDestroy (FcExpr *e);
698 FcEditDestroy (FcEdit *e);
706 FcMemAlloc (int kind, int size);
709 FcMemFree (int kind, int size);
713 FcFreeTypeLangSet (const FcCharSet *charset,
714 const FcChar8 *exclusiveLang);
717 FcLangCompare (const FcChar8 *s1, const FcChar8 *s2);
720 FcCharSetForLang (const FcChar8 *lang);
723 FcLangSetPromote (const FcChar8 *lang);
726 FcNameParseLangSet (const FcChar8 *string);
729 FcNameUnparseLangSet (FcStrBuf *buf, const FcLangSet *ls);
732 FcLangSetNewBank (void);
735 FcLangSetNeededBytes (const FcLangSet *l);
738 FcLangSetDistributeBytes (FcCache * metadata,
742 FcLangSetSerialize (int bank, FcLangSet *l);
745 FcLangSetUnserialize (FcCache metadata, void *block_ptr);
750 FcListPatternMatchAny (const FcPattern *p,
751 const FcPattern *font);
758 FcNameBool (const FcChar8 *v, FcBool *result);
761 FcObjectNewBank(void);
764 FcObjectDistributeBytes (FcCache * metadata,
768 FcObjectToPtr (const char * si);
771 FcObjectNeededBytes (FcObjectPtr p);
774 FcObjectUnserialize (FcCache metadata, FcConfig * config, void *block_ptr);
777 FcObjectSerialize (FcObjectPtr s);
782 FcValueCanonicalize (const FcValue *v);
785 FcValueListDestroy (FcValueListPtr l);
788 FcPatternFindElt (const FcPattern *p, const char *object);
791 FcPatternInsertElt (FcPattern *p, const char *object);
794 FcPatternAddWithBinding (FcPattern *p,
797 FcValueBinding binding,
801 FcPatternFreeze (FcPattern *p);
804 FcPatternFini (void);
807 FcPatternAppend (FcPattern *p, FcPattern *s);
810 FcObjectStaticName (const char *name);
813 FcObjectPtrU (FcObjectPtr p);
816 FcObjectPtrCompare (FcObjectPtr a, FcObjectPtr b);
819 FcPatternNewBank (void);
822 FcPatternNeededBytes (FcPattern *p);
825 FcPatternDistributeBytes (FcCache * metadata, void * block_ptr);
828 FcValueListPtrU(FcValueListPtr p);
831 FcPatternEltU (FcPatternEltPtr pei);
834 FcValueListPtrCreateDynamic(FcValueList * p);
837 FcPatternSerialize (int bank, FcPattern * p);
840 FcPatternUnserialize (FcCache metadata, void *block_ptr);
846 extern const FcMatrix FcIdentityMatrix;
849 FcMatrixFree (FcMatrix *mat);
853 FcStrSetSort (FcStrSet * set);
856 FcStrPlus (const FcChar8 *s1, const FcChar8 *s2);
859 FcStrFree (FcChar8 *s);
862 FcStrBufInit (FcStrBuf *buf, FcChar8 *init, int size);
865 FcStrBufDestroy (FcStrBuf *buf);
868 FcStrBufDone (FcStrBuf *buf);
871 FcStrBufChar (FcStrBuf *buf, FcChar8 c);
874 FcStrBufString (FcStrBuf *buf, const FcChar8 *s);
877 FcStrBufData (FcStrBuf *buf, const FcChar8 *s, int len);
880 FcStrCmpIgnoreBlanksAndCase (const FcChar8 *s1, const FcChar8 *s2);
883 FcStrContainsIgnoreBlanksAndCase (const FcChar8 *s1, const FcChar8 *s2);
886 FcStrContainsIgnoreCase (const FcChar8 *s1, const FcChar8 *s2);
889 FcStrUsesHome (const FcChar8 *s);
892 FcStrLastSlash (const FcChar8 *path);
895 FcStrHashIgnoreCase (const FcChar8 *s);
897 #endif /* _FC_INT_H_ */