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)
324 #define fc_alignof(type) offsetof (struct { char c; type member; }, member)
327 * The per-user ~/.fonts.cache-<version> file is loaded into
328 * this data structure. Each directory gets a substructure
329 * which is validated by comparing the directory timestamp with
330 * that saved in the cache. When valid, the entire directory cache
331 * can be immediately loaded without reading the directory. Otherwise,
332 * the files are checked individually; updated files are loaded into the
333 * cache which is then rewritten to the users home directory
336 #define FC_CACHE_MAGIC 0xFC02FC04
338 typedef struct _FcGlobalCacheDir FcGlobalCacheDir
;
341 FcGCDirDisabled
, FcGCDirFileRead
, FcGCDirConsumed
, FcGCDirUpdated
343 struct _FcGlobalCacheDir
{
344 struct _FcGlobalCacheDir
*next
;
350 enum FcGCDirState state
;
353 typedef struct _FcGlobalCache
{
354 FcGlobalCacheDir
*dirs
;
360 FcChar8
*file
; /* original file name */
361 FcChar8
*new; /* temp file name -- write data here */
362 FcChar8
*lck
; /* lockfile name (used for locking) */
363 FcChar8
*tmp
; /* tmpfile name (used for locking) */
374 * File names loaded from the configuration -- saved here as the
375 * cache file must be consulted before the directories are scanned,
376 * and those directives may occur in any order
378 FcStrSet
*configDirs
; /* directories to scan for fonts */
379 FcChar8
*cache
; /* name of per-user cache file */
381 * Set of allowed blank chars -- used to
382 * trim fonts of bogus glyphs
386 * List of directories containing fonts,
387 * built by recursively scanning the set
388 * of configured directories
392 * List of directories containing cache files.
396 * Names of all of the configuration files used
397 * to create this configuration
399 FcStrSet
*configFiles
; /* config files loaded */
401 * Substitution instructions for patterns and fonts;
402 * maxObjects is used to allocate appropriate intermediate storage
403 * while performing a whole set of substitutions
405 FcSubst
*substPattern
; /* substitutions for patterns */
406 FcSubst
*substFont
; /* substitutions for fonts */
407 int maxObjects
; /* maximum number of tests in all substs */
409 * List of patterns used to control font file selection
411 FcStrSet
*acceptGlobs
;
412 FcStrSet
*rejectGlobs
;
413 FcFontSet
*acceptPatterns
;
414 FcFontSet
*rejectPatterns
;
416 * The set of fonts loaded from the listed directories; the
417 * order within the set does not determine the font selection,
418 * except in the case of identical matches in which case earlier fonts
419 * match preferrentially
421 FcFontSet
*fonts
[FcSetApplication
+ 1];
423 * Fontconfig can periodically rescan the system configuration
424 * and font directories. This rescanning occurs when font
425 * listing requests are made, but no more often than rescanInterval
428 time_t rescanTime
; /* last time information was scanned */
429 int rescanInterval
; /* interval between scans */
432 extern FcConfig
*_fcConfig
;
434 typedef struct _FcFileTime
{
439 typedef struct _FcCharMap FcCharMap
;
441 /* watch out; assumes that v is void * -PL */
442 #define ALIGN(v,type) ((void *)(((uintptr_t)(v) + fc_alignof(type) - 1) & ~(fc_alignof(type) - 1)))
449 FcGlobalCacheCreate (void);
452 FcGlobalCacheDestroy (FcGlobalCache
*cache
);
455 FcGlobalCacheReadDir (FcFontSet
*set
,
457 FcGlobalCache
*cache
,
462 FcGlobalCacheLoad (FcGlobalCache
*cache
,
464 const FcChar8
*cache_file
,
468 FcGlobalCacheUpdate (FcGlobalCache
*cache
,
475 FcGlobalCacheSave (FcGlobalCache
*cache
,
476 const FcChar8
*cache_file
,
480 FcCacheRead (FcConfig
*config
, FcGlobalCache
* cache
);
483 FcDirCacheWrite (FcFontSet
*set
, FcStrSet
* dirs
, const FcChar8
*dir
, FcConfig
*config
);
486 FcDirCacheRead (FcFontSet
* set
, FcStrSet
* dirs
, const FcChar8
*dir
, FcConfig
*config
);
488 extern int *_fcBankId
, *_fcBankIdx
;
490 FcCacheBankToIndexMTF (int bank
);
493 FcCacheBankToIndex (int bank
)
495 return (_fcBankId
[*_fcBankIdx
] == bank
) ? *_fcBankIdx
: FcCacheBankToIndexMTF(bank
);
499 FcCacheFindBankDir (int bank
);
504 FcConfigAddConfigDir (FcConfig
*config
,
508 FcConfigAddFontDir (FcConfig
*config
,
512 FcConfigAddDir (FcConfig
*config
,
516 FcConfigAddCacheDir (FcConfig
*config
,
520 FcConfigGetCacheDirs (FcConfig
*config
);
523 FcConfigAddConfigFile (FcConfig
*config
,
527 FcConfigSetCache (FcConfig
*config
,
531 FcConfigAddBlank (FcConfig
*config
,
535 FcConfigAddEdit (FcConfig
*config
,
541 FcConfigSetFonts (FcConfig
*config
,
546 FcConfigCompareValue (const FcValue
*m
,
551 FcConfigGlobAdd (FcConfig
*config
,
556 FcConfigAcceptFilename (FcConfig
*config
,
557 const FcChar8
*filename
);
560 FcConfigPatternsAdd (FcConfig
*config
,
565 FcConfigAcceptFont (FcConfig
*config
,
566 const FcPattern
*font
);
569 FcConfigModifiedTime (FcConfig
*config
);
573 FcLangCharSetPopulate (void);
576 FcCharSetFreeze (FcCharSet
*cs
);
579 FcCharSetThawAll (void);
582 FcNameUnparseCharSet (FcStrBuf
*buf
, const FcCharSet
*c
);
585 FcNameParseCharSet (FcChar8
*string
);
588 FcCharSetFindLeafCreate (FcCharSet
*fcs
, FcChar32 ucs4
);
591 FcCharSetNewBank (void);
594 FcCharSetNeededBytes (const FcCharSet
*c
);
597 FcCharSetNeededBytesAlign (void);
600 FcCharSetDistributeBytes (FcCache
* metadata
,
604 FcCharSetSerialize(int bank
, FcCharSet
*c
);
607 FcCharSetUnserialize (FcCache
* metadata
, void *block_ptr
);
610 FcCharSetGetLeaf(const FcCharSet
*c
, int i
);
613 FcCharSetGetNumbers(const FcCharSet
*c
);
617 FcValueListPrint (const FcValueListPtr l
);
620 FcLangSetPrint (const FcLangSet
*ls
);
626 FcTestPrint (const FcTest
*test
);
629 FcExprPrint (const FcExpr
*expr
);
632 FcEditPrint (const FcEdit
*edit
);
635 FcSubstPrint (const FcSubst
*subst
);
637 extern int FcDebugVal
;
640 FcDebug (void) { return FcDebugVal
; }
647 FcGetDefaultLang (void);
652 FcFileIsDir (const FcChar8
*file
);
655 FcFileScanConfig (FcFontSet
*set
,
664 FcDirScanConfig (FcFontSet
*set
,
678 FcFreeTypeIsExclusiveLang (const FcChar8
*lang
);
681 FcFreeTypeHasLang (FcPattern
*pattern
, const FcChar8
*lang
);
684 FcFreeTypeUcs4ToPrivate (FcChar32 ucs4
, const FcCharMap
*map
);
687 FcFreeTypePrivateToUcs4 (FcChar32
private, const FcCharMap
*map
);
690 FcFreeTypeGetPrivateMap (FT_Encoding encoding
);
695 FcFontSetNewBank (void);
698 FcFontSetNeededBytes (FcFontSet
*s
);
701 FcFontSetNeededBytesAlign (void);
704 FcFontSetDistributeBytes (FcCache
* metadata
, void * block_ptr
);
707 FcFontSetSerialize (int bank
, FcFontSet
* s
);
710 FcFontSetUnserialize(FcCache
* metadata
, FcFontSet
* s
, void * block_ptr
);
714 FcConfigparse (void);
720 FcConfigerror (char *fmt
, ...);
723 FcConfigSaveField (const char *field
);
726 FcTestDestroy (FcTest
*test
);
729 FcExprCreateInteger (int i
);
732 FcExprCreateDouble (double d
);
735 FcExprCreateString (const FcChar8
*s
);
738 FcExprCreateMatrix (const FcMatrix
*m
);
741 FcExprCreateBool (FcBool b
);
744 FcExprCreateNil (void);
747 FcExprCreateField (const char *field
);
750 FcExprCreateConst (const FcChar8
*constant
);
753 FcExprCreateOp (FcExpr
*left
, FcOp op
, FcExpr
*right
);
756 FcExprDestroy (FcExpr
*e
);
759 FcEditDestroy (FcEdit
*e
);
767 FcMemAlloc (int kind
, int size
);
770 FcMemFree (int kind
, int size
);
774 FcFreeTypeLangSet (const FcCharSet
*charset
,
775 const FcChar8
*exclusiveLang
);
778 FcLangCompare (const FcChar8
*s1
, const FcChar8
*s2
);
781 FcCharSetForLang (const FcChar8
*lang
);
784 FcLangSetPromote (const FcChar8
*lang
);
787 FcNameParseLangSet (const FcChar8
*string
);
790 FcNameUnparseLangSet (FcStrBuf
*buf
, const FcLangSet
*ls
);
793 FcLangSetNewBank (void);
796 FcLangSetNeededBytes (const FcLangSet
*l
);
799 FcLangSetNeededBytesAlign (void);
802 FcLangSetDistributeBytes (FcCache
* metadata
,
806 FcLangSetSerialize (int bank
, FcLangSet
*l
);
809 FcLangSetUnserialize (FcCache
* metadata
, void *block_ptr
);
814 FcListPatternMatchAny (const FcPattern
*p
,
815 const FcPattern
*font
);
822 FcNameBool (const FcChar8
*v
, FcBool
*result
);
825 FcObjectDistributeBytes (FcCache
* metadata
,
829 FcObjectToPtr (const char * si
);
832 FcObjectNeededBytes (void);
835 FcObjectNeededBytesAlign (void);
838 FcObjectUnserialize (FcCache
* metadata
, void *block_ptr
);
841 FcObjectSerialize (void);
844 FcObjectPtrU (FcObjectPtr p
);
847 FcObjectPtrCompare (const FcObjectPtr a
, const FcObjectPtr b
)
853 FcObjectStaticNameFini (void);
858 FcValueCanonicalize (const FcValue
*v
);
861 FcValueListDestroy (FcValueListPtr l
);
864 FcPatternFindElt (const FcPattern
*p
, const char *object
);
867 FcPatternInsertElt (FcPattern
*p
, const char *object
);
870 FcPatternAddWithBinding (FcPattern
*p
,
873 FcValueBinding binding
,
877 FcPatternFini (void);
880 FcPatternAppend (FcPattern
*p
, FcPattern
*s
);
883 FcStrStaticName (const FcChar8
*name
);
886 FcStringHash (const FcChar8
*s
);
889 FcPatternNewBank (void);
892 FcPatternNeededBytes (FcPattern
*p
);
895 FcPatternNeededBytesAlign (void);
898 FcPatternDistributeBytes (FcCache
* metadata
, void * block_ptr
);
900 /* please don't access these outside of fcpat.c! only visible so that
901 * *PtrU can be inlined. */
902 extern FcValueList
** _fcValueLists
;
903 extern FcPatternElt
** _fcPatternElts
;
905 static inline FcValueList
*
906 FcValueListPtrU (FcValueListPtr pi
)
908 if (pi
.bank
== FC_BANK_DYNAMIC
)
911 return &_fcValueLists
[FcCacheBankToIndex(pi
.bank
)][pi
.u
.stat
];
914 static inline FcPatternElt
*
915 FcPatternEltU (FcPatternEltPtr pei
)
917 if (pei
.bank
== FC_BANK_DYNAMIC
)
920 return &_fcPatternElts
[FcCacheBankToIndex(pei
.bank
)][pei
.u
.stat
];
924 FcValueListPtrCreateDynamic(FcValueList
* p
);
927 FcPatternSerialize (int bank
, FcPattern
* p
);
930 FcPatternUnserialize (FcCache
* metadata
, void *block_ptr
);
936 extern const FcMatrix FcIdentityMatrix
;
939 FcMatrixFree (FcMatrix
*mat
);
943 FcStrSetSort (FcStrSet
* set
);
946 FcStrPlus (const FcChar8
*s1
, const FcChar8
*s2
);
949 FcStrFree (FcChar8
*s
);
952 FcStrBufInit (FcStrBuf
*buf
, FcChar8
*init
, int size
);
955 FcStrBufDestroy (FcStrBuf
*buf
);
958 FcStrBufDone (FcStrBuf
*buf
);
961 FcStrBufChar (FcStrBuf
*buf
, FcChar8 c
);
964 FcStrBufString (FcStrBuf
*buf
, const FcChar8
*s
);
967 FcStrBufData (FcStrBuf
*buf
, const FcChar8
*s
, int len
);
970 FcStrCmpIgnoreBlanksAndCase (const FcChar8
*s1
, const FcChar8
*s2
);
973 FcStrContainsIgnoreBlanksAndCase (const FcChar8
*s1
, const FcChar8
*s2
);
976 FcStrContainsIgnoreCase (const FcChar8
*s1
, const FcChar8
*s2
);
979 FcStrUsesHome (const FcChar8
*s
);
982 FcStrLastSlash (const FcChar8
*path
);
985 FcStrHashIgnoreCase (const FcChar8
*s
);
987 #endif /* _FC_INT_H_ */