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>
44 #ifndef FC_CONFIG_PATH
45 #define FC_CONFIG_PATH "fonts.conf"
48 #define FC_FONT_FILE_INVALID ((FcChar8 *) ".")
49 #define FC_FONT_FILE_DIR ((FcChar8 *) ".dir")
52 #define FC_SEARCH_PATH_SEPARATOR ';'
54 #define FC_SEARCH_PATH_SEPARATOR ':'
57 #define FC_DBG_MATCH 1
58 #define FC_DBG_MATCHV 2
60 #define FC_DBG_FONTSET 8
61 #define FC_DBG_CACHE 16
62 #define FC_DBG_CACHEV 32
63 #define FC_DBG_PARSE 64
64 #define FC_DBG_SCAN 128
65 #define FC_DBG_SCANV 256
66 #define FC_DBG_MEMORY 512
67 #define FC_DBG_CONFIG 1024
69 #define FC_MEM_CHARSET 0
70 #define FC_MEM_CHARLEAF 1
71 #define FC_MEM_FONTSET 2
72 #define FC_MEM_FONTPTR 3
73 #define FC_MEM_OBJECTSET 4
74 #define FC_MEM_OBJECTPTR 5
75 #define FC_MEM_MATRIX 6
76 #define FC_MEM_PATTERN 7
77 #define FC_MEM_PATELT 8
78 #define FC_MEM_VALLIST 9
79 #define FC_MEM_SUBSTATE 10
80 #define FC_MEM_STRING 11
81 #define FC_MEM_LISTBUCK 12
82 #define FC_MEM_STRSET 13
83 #define FC_MEM_STRLIST 14
84 #define FC_MEM_CONFIG 15
85 #define FC_MEM_LANGSET 16
86 #define FC_MEM_ATOMIC 17
87 #define FC_MEM_BLANKS 18
88 #define FC_MEM_CACHE 19
89 #define FC_MEM_STRBUF 20
90 #define FC_MEM_SUBST 21
91 #define FC_MEM_OBJECTTYPE 22
92 #define FC_MEM_CONSTANT 23
93 #define FC_MEM_TEST 24
94 #define FC_MEM_EXPR 25
95 #define FC_MEM_VSTACK 26
96 #define FC_MEM_ATTR 27
97 #define FC_MEM_PSTACK 28
98 #define FC_MEM_STATICSTR 29
100 #define FC_MEM_NUM 30
102 #define FC_BANK_LANGS 0xfcfcfcfc
104 typedef enum _FcValueBinding {
105 FcValueBindingWeak, FcValueBindingStrong, FcValueBindingSame
108 typedef struct _FcValueListPtr {
112 struct _FcValueList *dyn;
116 typedef struct _FcValueList {
120 FcValueBinding binding;
123 typedef int FcObjectPtr;
125 typedef struct _FcPatternEltPtr {
129 struct _FcPatternElt *dyn;
133 typedef struct _FcPatternElt {
135 FcValueListPtr values;
141 FcPatternEltPtr elts;
147 FcOpInteger, FcOpDouble, FcOpString, FcOpMatrix, FcOpBool, FcOpCharSet,
149 FcOpField, FcOpConst,
150 FcOpAssign, FcOpAssignReplace,
151 FcOpPrependFirst, FcOpPrepend, FcOpAppend, FcOpAppendLast,
153 FcOpOr, FcOpAnd, FcOpEqual, FcOpNotEqual,
154 FcOpContains, FcOpListing, FcOpNotContains,
155 FcOpLess, FcOpLessEqual, FcOpMore, FcOpMoreEqual,
156 FcOpPlus, FcOpMinus, FcOpTimes, FcOpDivide,
157 FcOpNot, FcOpComma, FcOpFloor, FcOpCeil, FcOpRound, FcOpTrunc,
161 typedef struct _FcExpr {
173 struct _FcExpr *left, *right;
178 typedef enum _FcQual {
179 FcQualAny, FcQualAll, FcQualFirst, FcQualNotFirst
182 #define FcMatchDefault ((FcMatchKind) -1)
184 typedef struct _FcTest {
185 struct _FcTest *next;
193 typedef struct _FcEdit {
194 struct _FcEdit *next;
198 FcValueBinding binding;
201 typedef struct _FcSubst {
202 struct _FcSubst *next;
207 typedef struct _FcCharLeaf {
208 FcChar32 map[256/32];
211 #define FC_REF_CONSTANT -1
214 int ref; /* reference count */
215 int num; /* size of leaves and numbers arrays */
230 int ref; /* reference count */
241 typedef struct _FcStrBuf {
249 typedef struct _FcCache {
250 int magic; /* 0xFC02FC02 */
251 int count; /* number of bytes of data in block */
252 int bank; /* bank ID */
253 int pattern_count; /* number of FcPatterns */
254 int patternelt_count; /* number of FcPatternElts */
255 int valuelist_count; /* number of FcValueLists */
256 int str_count; /* size of strings appearing as FcValues */
257 int langset_count; /* number of FcLangSets */
258 int charset_count; /* number of FcCharSets */
259 int charset_numbers_count;
260 int charset_leaf_count;
261 int charset_leaf_idx_count;
265 * To map adobe glyph names to unicode values, a precomputed hash
269 typedef struct _FcGlyphName {
270 FcChar32 ucs; /* unicode value */
271 FcChar8 name[1]; /* name extends beyond struct */
275 * To perform case-insensitive string comparisons, a table
276 * is used which holds three different kinds of folding data.
278 * The first is a range of upper case values mapping to a range
279 * of their lower case equivalents. Within each range, the offset
280 * between upper and lower case is constant.
282 * The second is a range of upper case values which are interleaved
283 * with their lower case equivalents.
285 * The third is a set of raw unicode values mapping to a list
286 * of unicode values for comparison purposes. This allows conversion
287 * of ß to "ss" so that SS, ss and ß all match. A separate array
288 * holds the list of unicode values for each entry.
290 * These are packed into a single table. Using a binary search,
291 * the appropriate entry can be located.
294 #define FC_CASE_FOLD_RANGE 0
295 #define FC_CASE_FOLD_EVEN_ODD 1
296 #define FC_CASE_FOLD_FULL 2
298 typedef struct _FcCaseFold {
302 short offset; /* lower - upper for RANGE, table id for FULL */
305 #define FC_MAX_FILE_LEN 4096
307 #define FC_STORAGE_STATIC 0x80
308 #define fc_value_string(v) (((v)->type & FC_STORAGE_STATIC) ? ((FcChar8 *) v) + (v)->u.s_off : (v) -> u.s)
309 #define fc_value_charset(v) (((v)->type & FC_STORAGE_STATIC) ? (const FcCharSet *)(((char *) v) + (v)->u.c_off) : (v) -> u.c)
310 #define fc_value_langset(v) (((v)->type & FC_STORAGE_STATIC) ? (const FcLangSet *)(((char *) v) + (v)->u.l_off) : (v) -> u.l)
313 * The per-user ~/.fonts.cache-<version> file is loaded into
314 * this data structure. Each directory gets a substructure
315 * which is validated by comparing the directory timestamp with
316 * that saved in the cache. When valid, the entire directory cache
317 * can be immediately loaded without reading the directory. Otherwise,
318 * the files are checked individually; updated files are loaded into the
319 * cache which is then rewritten to the users home directory
322 #define FC_CACHE_MAGIC 0xFC02FC02
324 typedef struct _FcGlobalCacheDir FcGlobalCacheDir;
326 struct _FcGlobalCacheDir {
327 struct _FcGlobalCacheDir *next;
334 typedef struct _FcGlobalCache {
335 FcGlobalCacheDir *dirs;
341 FcChar8 *file; /* original file name */
342 FcChar8 *new; /* temp file name -- write data here */
343 FcChar8 *lck; /* lockfile name (used for locking) */
344 FcChar8 *tmp; /* tmpfile name (used for locking) */
355 * File names loaded from the configuration -- saved here as the
356 * cache file must be consulted before the directories are scanned,
357 * and those directives may occur in any order
359 FcStrSet *configDirs; /* directories to scan for fonts */
360 FcChar8 *cache; /* name of per-user cache file */
362 * Set of allowed blank chars -- used to
363 * trim fonts of bogus glyphs
367 * List of directories containing fonts,
368 * built by recursively scanning the set
369 * of configured directories
373 * Names of all of the configuration files used
374 * to create this configuration
376 FcStrSet *configFiles; /* config files loaded */
378 * Substitution instructions for patterns and fonts;
379 * maxObjects is used to allocate appropriate intermediate storage
380 * while performing a whole set of substitutions
382 FcSubst *substPattern; /* substitutions for patterns */
383 FcSubst *substFont; /* substitutions for fonts */
384 int maxObjects; /* maximum number of tests in all substs */
386 * List of patterns used to control font file selection
388 FcStrSet *acceptGlobs;
389 FcStrSet *rejectGlobs;
390 FcFontSet *acceptPatterns;
391 FcFontSet *rejectPatterns;
393 * The set of fonts loaded from the listed directories; the
394 * order within the set does not determine the font selection,
395 * except in the case of identical matches in which case earlier fonts
396 * match preferrentially
398 FcFontSet *fonts[FcSetApplication + 1];
400 * Fontconfig can periodically rescan the system configuration
401 * and font directories. This rescanning occurs when font
402 * listing requests are made, but no more often than rescanInterval
405 time_t rescanTime; /* last time information was scanned */
406 int rescanInterval; /* interval between scans */
409 extern FcConfig *_fcConfig;
411 typedef struct _FcFileTime {
416 typedef struct _FcCharMap FcCharMap;
423 FcGlobalCacheCreate (void);
426 FcGlobalCacheDestroy (FcGlobalCache *cache);
429 FcGlobalCacheReadDir (FcFontSet *set,
431 FcGlobalCache *cache,
436 FcGlobalCacheLoad (FcGlobalCache *cache,
438 const FcChar8 *cache_file,
442 FcGlobalCacheUpdate (FcGlobalCache *cache,
447 FcGlobalCacheSave (FcGlobalCache *cache,
448 const FcChar8 *cache_file);
451 FcCacheRead (FcConfig *config, FcGlobalCache * cache);
454 FcDirCacheWrite (FcFontSet *set, FcStrSet * dirs, const FcChar8 *dir);
457 FcDirCacheRead (FcFontSet * set, FcStrSet * dirs, const FcChar8 *dir);
460 FcCacheBankToIndex (int bank);
463 FcCacheFindBankDir (int bank);
468 FcConfigAddConfigDir (FcConfig *config,
472 FcConfigAddFontDir (FcConfig *config,
476 FcConfigAddDir (FcConfig *config,
480 FcConfigAddConfigFile (FcConfig *config,
484 FcConfigSetCache (FcConfig *config,
488 FcConfigAddBlank (FcConfig *config,
492 FcConfigAddEdit (FcConfig *config,
498 FcConfigSetFonts (FcConfig *config,
503 FcConfigCompareValue (const FcValue *m,
508 FcConfigGlobAdd (FcConfig *config,
513 FcConfigAcceptFilename (FcConfig *config,
514 const FcChar8 *filename);
517 FcConfigPatternsAdd (FcConfig *config,
522 FcConfigAcceptFont (FcConfig *config,
523 const FcPattern *font);
526 FcConfigModifiedTime (FcConfig *config);
530 FcLangCharSetPopulate (void);
533 FcCharSetFreeze (FcCharSet *cs);
536 FcCharSetThawAll (void);
539 FcNameUnparseCharSet (FcStrBuf *buf, const FcCharSet *c);
542 FcNameParseCharSet (FcChar8 *string);
545 FcCharSetFindLeafCreate (FcCharSet *fcs, FcChar32 ucs4);
548 FcCharSetNewBank (void);
551 FcCharSetNeededBytes (const FcCharSet *c);
554 FcCharSetDistributeBytes (FcCache * metadata,
558 FcCharSetSerialize(int bank, FcCharSet *c);
561 FcCharSetUnserialize (FcCache metadata, void *block_ptr);
564 FcCharSetGetLeaf(const FcCharSet *c, int i);
567 FcCharSetGetNumbers(const FcCharSet *c);
571 FcValueListPrint (const FcValueListPtr l);
574 FcLangSetPrint (const FcLangSet *ls);
580 FcTestPrint (const FcTest *test);
583 FcExprPrint (const FcExpr *expr);
586 FcEditPrint (const FcEdit *edit);
589 FcSubstPrint (const FcSubst *subst);
596 FcGetDefaultLang (void);
601 FcFileIsDir (const FcChar8 *file);
604 FcFileScanConfig (FcFontSet *set,
613 FcDirScanConfig (FcFontSet *set,
627 FcFreeTypeIsExclusiveLang (const FcChar8 *lang);
630 FcFreeTypeHasLang (FcPattern *pattern, const FcChar8 *lang);
633 FcFreeTypeUcs4ToPrivate (FcChar32 ucs4, const FcCharMap *map);
636 FcFreeTypePrivateToUcs4 (FcChar32 private, const FcCharMap *map);
639 FcFreeTypeGetPrivateMap (FT_Encoding encoding);
644 FcFontSetNewBank (void);
647 FcFontSetNeededBytes (FcFontSet *s);
650 FcFontSetDistributeBytes (FcCache * metadata, void * block_ptr);
653 FcFontSetSerialize (int bank, FcFontSet * s);
656 FcFontSetUnserialize(FcCache metadata, FcFontSet * s, void * block_ptr);
660 FcConfigparse (void);
666 FcConfigerror (char *fmt, ...);
669 FcConfigSaveField (const char *field);
672 FcTestDestroy (FcTest *test);
675 FcExprCreateInteger (int i);
678 FcExprCreateDouble (double d);
681 FcExprCreateString (const FcChar8 *s);
684 FcExprCreateMatrix (const FcMatrix *m);
687 FcExprCreateBool (FcBool b);
690 FcExprCreateNil (void);
693 FcExprCreateField (const char *field);
696 FcExprCreateConst (const FcChar8 *constant);
699 FcExprCreateOp (FcExpr *left, FcOp op, FcExpr *right);
702 FcExprDestroy (FcExpr *e);
705 FcEditDestroy (FcEdit *e);
713 FcMemAlloc (int kind, int size);
716 FcMemFree (int kind, int size);
720 FcFreeTypeLangSet (const FcCharSet *charset,
721 const FcChar8 *exclusiveLang);
724 FcLangCompare (const FcChar8 *s1, const FcChar8 *s2);
727 FcCharSetForLang (const FcChar8 *lang);
730 FcLangSetPromote (const FcChar8 *lang);
733 FcNameParseLangSet (const FcChar8 *string);
736 FcNameUnparseLangSet (FcStrBuf *buf, const FcLangSet *ls);
739 FcLangSetNewBank (void);
742 FcLangSetNeededBytes (const FcLangSet *l);
745 FcLangSetDistributeBytes (FcCache * metadata,
749 FcLangSetSerialize (int bank, FcLangSet *l);
752 FcLangSetUnserialize (FcCache metadata, void *block_ptr);
757 FcListPatternMatchAny (const FcPattern *p,
758 const FcPattern *font);
765 FcNameBool (const FcChar8 *v, FcBool *result);
768 FcObjectDistributeBytes (FcCache * metadata,
772 FcObjectToPtr (const char * si);
775 FcObjectNeededBytes (void);
778 FcObjectUnserialize (FcCache metadata, void *block_ptr);
781 FcObjectSerialize (void);
784 FcObjectPtrU (FcObjectPtr p);
787 FcObjectPtrCompare (FcObjectPtr a, FcObjectPtr b);
790 FcObjectStaticNameFini (void);
795 FcValueCanonicalize (const FcValue *v);
798 FcValueListDestroy (FcValueListPtr l);
801 FcPatternFindElt (const FcPattern *p, const char *object);
804 FcPatternInsertElt (FcPattern *p, const char *object);
807 FcPatternAddWithBinding (FcPattern *p,
810 FcValueBinding binding,
814 FcPatternFreeze (FcPattern *p);
817 FcPatternFini (void);
820 FcPatternAppend (FcPattern *p, FcPattern *s);
823 FcPatternAddFullFname (const FcPattern *p, const char *fname);
826 FcPatternTransferFullFname (const FcPattern *new, const FcPattern *orig);
829 FcStrStaticName (const FcChar8 *name);
832 FcStringHash (const FcChar8 *s);
835 FcPatternNewBank (void);
838 FcPatternNeededBytes (FcPattern *p);
841 FcPatternDistributeBytes (FcCache * metadata, void * block_ptr);
844 FcValueListPtrU(FcValueListPtr p);
847 FcPatternEltU (FcPatternEltPtr pei);
850 FcValueListPtrCreateDynamic(FcValueList * p);
853 FcPatternSerialize (int bank, FcPattern * p);
856 FcPatternUnserialize (FcCache metadata, void *block_ptr);
862 extern const FcMatrix FcIdentityMatrix;
865 FcMatrixFree (FcMatrix *mat);
869 FcStrSetSort (FcStrSet * set);
872 FcStrPlus (const FcChar8 *s1, const FcChar8 *s2);
875 FcStrFree (FcChar8 *s);
878 FcStrBufInit (FcStrBuf *buf, FcChar8 *init, int size);
881 FcStrBufDestroy (FcStrBuf *buf);
884 FcStrBufDone (FcStrBuf *buf);
887 FcStrBufChar (FcStrBuf *buf, FcChar8 c);
890 FcStrBufString (FcStrBuf *buf, const FcChar8 *s);
893 FcStrBufData (FcStrBuf *buf, const FcChar8 *s, int len);
896 FcStrCmpIgnoreBlanksAndCase (const FcChar8 *s1, const FcChar8 *s2);
899 FcStrContainsIgnoreBlanksAndCase (const FcChar8 *s1, const FcChar8 *s2);
902 FcStrContainsIgnoreCase (const FcChar8 *s1, const FcChar8 *s2);
905 FcStrUsesHome (const FcChar8 *s);
908 FcStrLastSlash (const FcChar8 *path);
911 FcStrHashIgnoreCase (const FcChar8 *s);
913 #endif /* _FC_INT_H_ */