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.
30 #ifdef HAVE_INTTYPES_H
39 #include <sys/types.h>
42 #include <fontconfig/fontconfig.h>
43 #include <fontconfig/fcprivate.h>
44 #include <fontconfig/fcfreetype.h>
49 #ifndef FC_CONFIG_PATH
50 #define FC_CONFIG_PATH "fonts.conf"
53 #define FC_FONT_FILE_INVALID ((FcChar8 *) ".")
54 #define FC_FONT_FILE_DIR ((FcChar8 *) ".dir")
55 #define FC_GLOBAL_MAGIC_COOKIE "GLOBAL"
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 #define FC_BANK_DYNAMIC 0
109 #define FC_BANK_FIRST 1
110 #define FC_BANK_LANGS 0xfcfcfcfc
112 typedef enum _FcValueBinding
{
113 FcValueBindingWeak
, FcValueBindingStrong
, FcValueBindingSame
116 typedef struct _FcValueListPtr
{
120 struct _FcValueList
*dyn
;
124 typedef struct _FcValueList
{
128 FcValueBinding binding
;
131 typedef int FcObjectPtr
;
133 typedef struct _FcPatternEltPtr
{
137 struct _FcPatternElt
*dyn
;
141 typedef struct _FcPatternElt
{
143 FcValueListPtr values
;
149 FcPatternEltPtr elts
;
155 FcOpInteger
, FcOpDouble
, FcOpString
, FcOpMatrix
, FcOpBool
, FcOpCharSet
,
157 FcOpField
, FcOpConst
,
158 FcOpAssign
, FcOpAssignReplace
,
159 FcOpPrependFirst
, FcOpPrepend
, FcOpAppend
, FcOpAppendLast
,
161 FcOpOr
, FcOpAnd
, FcOpEqual
, FcOpNotEqual
,
162 FcOpContains
, FcOpListing
, FcOpNotContains
,
163 FcOpLess
, FcOpLessEqual
, FcOpMore
, FcOpMoreEqual
,
164 FcOpPlus
, FcOpMinus
, FcOpTimes
, FcOpDivide
,
165 FcOpNot
, FcOpComma
, FcOpFloor
, FcOpCeil
, FcOpRound
, FcOpTrunc
,
169 typedef struct _FcExpr
{
181 struct _FcExpr
*left
, *right
;
186 typedef enum _FcQual
{
187 FcQualAny
, FcQualAll
, FcQualFirst
, FcQualNotFirst
190 #define FcMatchDefault ((FcMatchKind) -1)
192 typedef struct _FcTest
{
193 struct _FcTest
*next
;
201 typedef struct _FcEdit
{
202 struct _FcEdit
*next
;
206 FcValueBinding binding
;
209 typedef struct _FcSubst
{
210 struct _FcSubst
*next
;
215 typedef struct _FcCharLeaf
{
216 FcChar32 map
[256/32];
219 #define FC_REF_CONSTANT -1
222 int ref
; /* reference count */
223 int num
; /* size of leaves and numbers arrays */
238 int ref
; /* reference count */
249 typedef struct _FcStrBuf
{
257 typedef struct _FcCache
{
258 int magic
; /* FC_CACHE_MAGIC */
259 int count
; /* number of bytes of data in block */
260 int bank
; /* bank ID */
261 int pattern_count
; /* number of FcPatterns */
262 int patternelt_count
; /* number of FcPatternElts */
263 int valuelist_count
; /* number of FcValueLists */
264 int str_count
; /* size of strings appearing as FcValues */
265 int langset_count
; /* number of FcLangSets */
266 int charset_count
; /* number of FcCharSets */
267 int charset_numbers_count
;
268 int charset_leaf_count
;
269 int charset_leaf_idx_count
;
273 * To map adobe glyph names to unicode values, a precomputed hash
277 typedef struct _FcGlyphName
{
278 FcChar32 ucs
; /* unicode value */
279 FcChar8 name
[1]; /* name extends beyond struct */
283 * To perform case-insensitive string comparisons, a table
284 * is used which holds three different kinds of folding data.
286 * The first is a range of upper case values mapping to a range
287 * of their lower case equivalents. Within each range, the offset
288 * between upper and lower case is constant.
290 * The second is a range of upper case values which are interleaved
291 * with their lower case equivalents.
293 * The third is a set of raw unicode values mapping to a list
294 * of unicode values for comparison purposes. This allows conversion
295 * of ß to "ss" so that SS, ss and ß all match. A separate array
296 * holds the list of unicode values for each entry.
298 * These are packed into a single table. Using a binary search,
299 * the appropriate entry can be located.
302 #define FC_CASE_FOLD_RANGE 0
303 #define FC_CASE_FOLD_EVEN_ODD 1
304 #define FC_CASE_FOLD_FULL 2
306 typedef struct _FcCaseFold
{
310 short offset
; /* lower - upper for RANGE, table id for FULL */
313 #define FC_MAX_FILE_LEN 4096
315 #define FC_STORAGE_STATIC 0x80
316 #define fc_value_string(v) (((v)->type & FC_STORAGE_STATIC) ? ((FcChar8 *) v) + (v)->u.s_off : (v) -> u.s)
317 #define fc_value_charset(v) (((v)->type & FC_STORAGE_STATIC) ? (const FcCharSet *)(((char *) v) + (v)->u.c_off) : (v) -> u.c)
318 #define fc_value_langset(v) (((v)->type & FC_STORAGE_STATIC) ? (const FcLangSet *)(((char *) v) + (v)->u.l_off) : (v) -> u.l)
319 #define fc_storage_type(v) ((v)->type & ~FC_STORAGE_STATIC)
322 * The per-user ~/.fonts.cache-<version> file is loaded into
323 * this data structure. Each directory gets a substructure
324 * which is validated by comparing the directory timestamp with
325 * that saved in the cache. When valid, the entire directory cache
326 * can be immediately loaded without reading the directory. Otherwise,
327 * the files are checked individually; updated files are loaded into the
328 * cache which is then rewritten to the users home directory
331 #define FC_CACHE_MAGIC 0xFC02FC03
333 typedef struct _FcGlobalCacheDir FcGlobalCacheDir
;
336 FcGCDirDisabled
, FcGCDirFileRead
, FcGCDirConsumed
, FcGCDirUpdated
338 struct _FcGlobalCacheDir
{
339 struct _FcGlobalCacheDir
*next
;
345 enum FcGCDirState state
;
348 typedef struct _FcGlobalCache
{
349 FcGlobalCacheDir
*dirs
;
355 FcChar8
*file
; /* original file name */
356 FcChar8
*new; /* temp file name -- write data here */
357 FcChar8
*lck
; /* lockfile name (used for locking) */
358 FcChar8
*tmp
; /* tmpfile name (used for locking) */
369 * File names loaded from the configuration -- saved here as the
370 * cache file must be consulted before the directories are scanned,
371 * and those directives may occur in any order
373 FcStrSet
*configDirs
; /* directories to scan for fonts */
374 FcChar8
*cache
; /* name of per-user cache file */
376 * Set of allowed blank chars -- used to
377 * trim fonts of bogus glyphs
381 * List of directories containing fonts,
382 * built by recursively scanning the set
383 * of configured directories
387 * Names of all of the configuration files used
388 * to create this configuration
390 FcStrSet
*configFiles
; /* config files loaded */
392 * Substitution instructions for patterns and fonts;
393 * maxObjects is used to allocate appropriate intermediate storage
394 * while performing a whole set of substitutions
396 FcSubst
*substPattern
; /* substitutions for patterns */
397 FcSubst
*substFont
; /* substitutions for fonts */
398 int maxObjects
; /* maximum number of tests in all substs */
400 * List of patterns used to control font file selection
402 FcStrSet
*acceptGlobs
;
403 FcStrSet
*rejectGlobs
;
404 FcFontSet
*acceptPatterns
;
405 FcFontSet
*rejectPatterns
;
407 * The set of fonts loaded from the listed directories; the
408 * order within the set does not determine the font selection,
409 * except in the case of identical matches in which case earlier fonts
410 * match preferrentially
412 FcFontSet
*fonts
[FcSetApplication
+ 1];
414 * Fontconfig can periodically rescan the system configuration
415 * and font directories. This rescanning occurs when font
416 * listing requests are made, but no more often than rescanInterval
419 time_t rescanTime
; /* last time information was scanned */
420 int rescanInterval
; /* interval between scans */
423 extern FcConfig
*_fcConfig
;
425 typedef struct _FcFileTime
{
430 typedef struct _FcCharMap FcCharMap
;
432 #define ALIGN(v,type) ((__typeof__(v))(((uintptr_t)(v) + __alignof__(type) - 1) & ~(__alignof__(type) - 1)))
439 FcGlobalCacheCreate (void);
442 FcGlobalCacheDestroy (FcGlobalCache
*cache
);
445 FcGlobalCacheReadDir (FcFontSet
*set
,
447 FcGlobalCache
*cache
,
452 FcGlobalCacheLoad (FcGlobalCache
*cache
,
454 const FcChar8
*cache_file
,
458 FcGlobalCacheUpdate (FcGlobalCache
*cache
,
465 FcGlobalCacheSave (FcGlobalCache
*cache
,
466 const FcChar8
*cache_file
,
470 FcCacheRead (FcConfig
*config
, FcGlobalCache
* cache
);
473 FcDirCacheWrite (FcFontSet
*set
, FcStrSet
* dirs
, const FcChar8
*dir
);
476 FcDirCacheRead (FcFontSet
* set
, FcStrSet
* dirs
, const FcChar8
*dir
, FcConfig
*config
);
478 extern int *_fcBankId
, *_fcBankIdx
;
480 FcCacheBankToIndexMTF (int bank
);
482 static __inline__
int
483 FcCacheBankToIndex (int bank
)
485 return (_fcBankId
[*_fcBankIdx
] == bank
) ? *_fcBankIdx
: FcCacheBankToIndexMTF(bank
);
489 FcCacheFindBankDir (int bank
);
494 FcConfigAddConfigDir (FcConfig
*config
,
498 FcConfigAddFontDir (FcConfig
*config
,
502 FcConfigAddDir (FcConfig
*config
,
506 FcConfigAddConfigFile (FcConfig
*config
,
510 FcConfigSetCache (FcConfig
*config
,
514 FcConfigAddBlank (FcConfig
*config
,
518 FcConfigAddEdit (FcConfig
*config
,
524 FcConfigSetFonts (FcConfig
*config
,
529 FcConfigCompareValue (const FcValue
*m
,
534 FcConfigGlobAdd (FcConfig
*config
,
539 FcConfigAcceptFilename (FcConfig
*config
,
540 const FcChar8
*filename
);
543 FcConfigPatternsAdd (FcConfig
*config
,
548 FcConfigAcceptFont (FcConfig
*config
,
549 const FcPattern
*font
);
552 FcConfigModifiedTime (FcConfig
*config
);
556 FcLangCharSetPopulate (void);
559 FcCharSetFreeze (FcCharSet
*cs
);
562 FcCharSetThawAll (void);
565 FcNameUnparseCharSet (FcStrBuf
*buf
, const FcCharSet
*c
);
568 FcNameParseCharSet (FcChar8
*string
);
571 FcCharSetFindLeafCreate (FcCharSet
*fcs
, FcChar32 ucs4
);
574 FcCharSetNewBank (void);
577 FcCharSetNeededBytes (const FcCharSet
*c
);
580 FcCharSetNeededBytesAlign (void);
583 FcCharSetDistributeBytes (FcCache
* metadata
,
587 FcCharSetSerialize(int bank
, FcCharSet
*c
);
590 FcCharSetUnserialize (FcCache
* metadata
, void *block_ptr
);
593 FcCharSetGetLeaf(const FcCharSet
*c
, int i
);
596 FcCharSetGetNumbers(const FcCharSet
*c
);
600 FcValueListPrint (const FcValueListPtr l
);
603 FcLangSetPrint (const FcLangSet
*ls
);
609 FcTestPrint (const FcTest
*test
);
612 FcExprPrint (const FcExpr
*expr
);
615 FcEditPrint (const FcEdit
*edit
);
618 FcSubstPrint (const FcSubst
*subst
);
620 extern int FcDebugVal
;
622 static __inline__
int
623 FcDebug (void) { return FcDebugVal
; }
630 FcGetDefaultLang (void);
635 FcFileIsDir (const FcChar8
*file
);
638 FcFileScanConfig (FcFontSet
*set
,
647 FcDirScanConfig (FcFontSet
*set
,
661 FcFreeTypeIsExclusiveLang (const FcChar8
*lang
);
664 FcFreeTypeHasLang (FcPattern
*pattern
, const FcChar8
*lang
);
667 FcFreeTypeUcs4ToPrivate (FcChar32 ucs4
, const FcCharMap
*map
);
670 FcFreeTypePrivateToUcs4 (FcChar32
private, const FcCharMap
*map
);
673 FcFreeTypeGetPrivateMap (FT_Encoding encoding
);
678 FcFontSetNewBank (void);
681 FcFontSetNeededBytes (FcFontSet
*s
);
684 FcFontSetNeededBytesAlign (void);
687 FcFontSetDistributeBytes (FcCache
* metadata
, void * block_ptr
);
690 FcFontSetSerialize (int bank
, FcFontSet
* s
);
693 FcFontSetUnserialize(FcCache
* metadata
, FcFontSet
* s
, void * block_ptr
);
697 FcConfigparse (void);
703 FcConfigerror (char *fmt
, ...);
706 FcConfigSaveField (const char *field
);
709 FcTestDestroy (FcTest
*test
);
712 FcExprCreateInteger (int i
);
715 FcExprCreateDouble (double d
);
718 FcExprCreateString (const FcChar8
*s
);
721 FcExprCreateMatrix (const FcMatrix
*m
);
724 FcExprCreateBool (FcBool b
);
727 FcExprCreateNil (void);
730 FcExprCreateField (const char *field
);
733 FcExprCreateConst (const FcChar8
*constant
);
736 FcExprCreateOp (FcExpr
*left
, FcOp op
, FcExpr
*right
);
739 FcExprDestroy (FcExpr
*e
);
742 FcEditDestroy (FcEdit
*e
);
750 FcMemAlloc (int kind
, int size
);
753 FcMemFree (int kind
, int size
);
757 FcFreeTypeLangSet (const FcCharSet
*charset
,
758 const FcChar8
*exclusiveLang
);
761 FcLangCompare (const FcChar8
*s1
, const FcChar8
*s2
);
764 FcCharSetForLang (const FcChar8
*lang
);
767 FcLangSetPromote (const FcChar8
*lang
);
770 FcNameParseLangSet (const FcChar8
*string
);
773 FcNameUnparseLangSet (FcStrBuf
*buf
, const FcLangSet
*ls
);
776 FcLangSetNewBank (void);
779 FcLangSetNeededBytes (const FcLangSet
*l
);
782 FcLangSetNeededBytesAlign (void);
785 FcLangSetDistributeBytes (FcCache
* metadata
,
789 FcLangSetSerialize (int bank
, FcLangSet
*l
);
792 FcLangSetUnserialize (FcCache
* metadata
, void *block_ptr
);
797 FcListPatternMatchAny (const FcPattern
*p
,
798 const FcPattern
*font
);
805 FcNameBool (const FcChar8
*v
, FcBool
*result
);
808 FcObjectDistributeBytes (FcCache
* metadata
,
812 FcObjectToPtr (const char * si
);
815 FcObjectNeededBytes (void);
818 FcObjectNeededBytesAlign (void);
821 FcObjectUnserialize (FcCache
* metadata
, void *block_ptr
);
824 FcObjectSerialize (void);
827 FcObjectPtrU (FcObjectPtr p
);
829 static __inline__
int
830 FcObjectPtrCompare (const FcObjectPtr a
, const FcObjectPtr b
)
836 FcObjectStaticNameFini (void);
841 FcValueCanonicalize (const FcValue
*v
);
844 FcValueListDestroy (FcValueListPtr l
);
847 FcPatternFindElt (const FcPattern
*p
, const char *object
);
850 FcPatternInsertElt (FcPattern
*p
, const char *object
);
853 FcPatternAddWithBinding (FcPattern
*p
,
856 FcValueBinding binding
,
860 FcPatternFreeze (FcPattern
*p
);
863 FcPatternFini (void);
866 FcPatternAppend (FcPattern
*p
, FcPattern
*s
);
869 FcPatternAddFullFname (const FcPattern
*p
, const char *fname
);
872 FcPatternTransferFullFname (const FcPattern
*new, const FcPattern
*orig
);
875 FcStrStaticName (const FcChar8
*name
);
878 FcStringHash (const FcChar8
*s
);
881 FcPatternNewBank (void);
884 FcPatternNeededBytes (FcPattern
*p
);
887 FcPatternNeededBytesAlign (void);
890 FcPatternDistributeBytes (FcCache
* metadata
, void * block_ptr
);
892 /* please don't access these outside of fcpat.c! only visible so that
893 * *PtrU can be inlined. */
894 extern FcValueList
** _fcValueLists
;
895 extern FcPatternElt
** _fcPatternElts
;
897 static __inline__ FcValueList
*
898 FcValueListPtrU (FcValueListPtr pi
)
900 if (pi
.bank
== FC_BANK_DYNAMIC
)
903 return &_fcValueLists
[FcCacheBankToIndex(pi
.bank
)][pi
.u
.stat
];
906 static __inline__ FcPatternElt
*
907 FcPatternEltU (FcPatternEltPtr pei
)
909 if (pei
.bank
== FC_BANK_DYNAMIC
)
912 return &_fcPatternElts
[FcCacheBankToIndex(pei
.bank
)][pei
.u
.stat
];
916 FcPatternEltU (FcPatternEltPtr pei
);
919 FcValueListPtrCreateDynamic(FcValueList
* p
);
922 FcPatternSerialize (int bank
, FcPattern
* p
);
925 FcPatternUnserialize (FcCache
* metadata
, void *block_ptr
);
931 extern const FcMatrix FcIdentityMatrix
;
934 FcMatrixFree (FcMatrix
*mat
);
938 FcStrSetSort (FcStrSet
* set
);
941 FcStrPlus (const FcChar8
*s1
, const FcChar8
*s2
);
944 FcStrFree (FcChar8
*s
);
947 FcStrBufInit (FcStrBuf
*buf
, FcChar8
*init
, int size
);
950 FcStrBufDestroy (FcStrBuf
*buf
);
953 FcStrBufDone (FcStrBuf
*buf
);
956 FcStrBufChar (FcStrBuf
*buf
, FcChar8 c
);
959 FcStrBufString (FcStrBuf
*buf
, const FcChar8
*s
);
962 FcStrBufData (FcStrBuf
*buf
, const FcChar8
*s
, int len
);
965 FcStrCmpIgnoreBlanksAndCase (const FcChar8
*s1
, const FcChar8
*s2
);
968 FcStrContainsIgnoreBlanksAndCase (const FcChar8
*s1
, const FcChar8
*s2
);
971 FcStrContainsIgnoreCase (const FcChar8
*s1
, const FcChar8
*s2
);
974 FcStrUsesHome (const FcChar8
*s
);
977 FcStrLastSlash (const FcChar8
*path
);
980 FcStrHashIgnoreCase (const FcChar8
*s
);
982 #endif /* _FC_INT_H_ */