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 subdirs
; /* number of subdir strings */
263 off_t pos
; /* position of data block in file */
264 off_t count
; /* number of bytes of data in block */
265 int bank
; /* bank ID */
266 int pattern_count
; /* number of FcPatterns */
267 int patternelt_count
; /* number of FcPatternElts */
268 int valuelist_count
; /* number of FcValueLists */
269 int str_count
; /* size of strings appearing as FcValues */
270 int langset_count
; /* number of FcLangSets */
271 int charset_count
; /* number of FcCharSets */
272 int charset_numbers_count
;
273 int charset_leaf_count
;
274 int charset_leaf_idx_count
;
278 * To map adobe glyph names to unicode values, a precomputed hash
282 typedef struct _FcGlyphName
{
283 FcChar32 ucs
; /* unicode value */
284 FcChar8 name
[1]; /* name extends beyond struct */
288 * To perform case-insensitive string comparisons, a table
289 * is used which holds three different kinds of folding data.
291 * The first is a range of upper case values mapping to a range
292 * of their lower case equivalents. Within each range, the offset
293 * between upper and lower case is constant.
295 * The second is a range of upper case values which are interleaved
296 * with their lower case equivalents.
298 * The third is a set of raw unicode values mapping to a list
299 * of unicode values for comparison purposes. This allows conversion
300 * of ß to "ss" so that SS, ss and ß all match. A separate array
301 * holds the list of unicode values for each entry.
303 * These are packed into a single table. Using a binary search,
304 * the appropriate entry can be located.
307 #define FC_CASE_FOLD_RANGE 0
308 #define FC_CASE_FOLD_EVEN_ODD 1
309 #define FC_CASE_FOLD_FULL 2
311 typedef struct _FcCaseFold
{
315 short offset
; /* lower - upper for RANGE, table id for FULL */
318 #define FC_MAX_FILE_LEN 4096
320 #define FC_STORAGE_STATIC 0x80
321 #define fc_value_string(v) (((v)->type & FC_STORAGE_STATIC) ? ((FcChar8 *) v) + (v)->u.s_off : (v) -> u.s)
322 #define fc_value_charset(v) (((v)->type & FC_STORAGE_STATIC) ? (const FcCharSet *)(((char *) v) + (v)->u.c_off) : (v) -> u.c)
323 #define fc_value_langset(v) (((v)->type & FC_STORAGE_STATIC) ? (const FcLangSet *)(((char *) v) + (v)->u.l_off) : (v) -> u.l)
324 #define fc_storage_type(v) ((v)->type & ~FC_STORAGE_STATIC)
326 #define fc_alignof(type) offsetof (struct { char c; type member; }, member)
328 #define FC_CACHE_MAGIC 0xFC02FC04
331 FcChar8
*file
; /* original file name */
332 FcChar8
*new; /* temp file name -- write data here */
333 FcChar8
*lck
; /* lockfile name (used for locking) */
334 FcChar8
*tmp
; /* tmpfile name (used for locking) */
345 * File names loaded from the configuration -- saved here as the
346 * cache file must be consulted before the directories are scanned,
347 * and those directives may occur in any order
349 FcStrSet
*configDirs
; /* directories to scan for fonts */
350 FcChar8
*cache
; /* name of per-user cache file */
352 * Set of allowed blank chars -- used to
353 * trim fonts of bogus glyphs
357 * List of directories containing fonts,
358 * built by recursively scanning the set
359 * of configured directories
363 * List of directories containing cache files.
367 * Names of all of the configuration files used
368 * to create this configuration
370 FcStrSet
*configFiles
; /* config files loaded */
372 * Substitution instructions for patterns and fonts;
373 * maxObjects is used to allocate appropriate intermediate storage
374 * while performing a whole set of substitutions
376 FcSubst
*substPattern
; /* substitutions for patterns */
377 FcSubst
*substFont
; /* substitutions for fonts */
378 int maxObjects
; /* maximum number of tests in all substs */
380 * List of patterns used to control font file selection
382 FcStrSet
*acceptGlobs
;
383 FcStrSet
*rejectGlobs
;
384 FcFontSet
*acceptPatterns
;
385 FcFontSet
*rejectPatterns
;
387 * The set of fonts loaded from the listed directories; the
388 * order within the set does not determine the font selection,
389 * except in the case of identical matches in which case earlier fonts
390 * match preferrentially
392 FcFontSet
*fonts
[FcSetApplication
+ 1];
394 * Fontconfig can periodically rescan the system configuration
395 * and font directories. This rescanning occurs when font
396 * listing requests are made, but no more often than rescanInterval
399 time_t rescanTime
; /* last time information was scanned */
400 int rescanInterval
; /* interval between scans */
403 extern FcConfig
*_fcConfig
;
405 typedef struct _FcFileTime
{
410 typedef struct _FcCharMap FcCharMap
;
412 /* watch out; assumes that v is void * -PL */
413 #define ALIGN(v,type) ((void *)(((uintptr_t)(v) + fc_alignof(type) - 1) & ~(fc_alignof(type) - 1)))
420 FcCacheRead (FcConfig
*config
);
423 FcDirCacheWrite (FcFontSet
*set
, FcStrSet
* dirs
, const FcChar8
*dir
, FcConfig
*config
);
426 FcDirCacheConsume (FILE *file
, FcFontSet
*set
, FcStrSet
*dirs
,
427 const FcChar8
*dir
, char *dirname
);
430 FcDirCacheRead (FcFontSet
* set
, FcStrSet
* dirs
, const FcChar8
*dir
, FcConfig
*config
);
432 extern int *_fcBankId
, *_fcBankIdx
;
434 FcCacheBankToIndexMTF (int bank
);
437 FcCacheBankToIndex (int bank
)
439 return (_fcBankId
[*_fcBankIdx
] == bank
) ? *_fcBankIdx
: FcCacheBankToIndexMTF(bank
);
443 FcCacheFindBankDir (int bank
);
448 FcConfigAddConfigDir (FcConfig
*config
,
452 FcConfigAddFontDir (FcConfig
*config
,
456 FcConfigAddDir (FcConfig
*config
,
460 FcConfigAddCacheDir (FcConfig
*config
,
464 FcConfigGetCacheDirs (FcConfig
*config
);
467 FcConfigAddConfigFile (FcConfig
*config
,
471 FcConfigSetCache (FcConfig
*config
,
475 FcConfigAddBlank (FcConfig
*config
,
479 FcConfigAddEdit (FcConfig
*config
,
485 FcConfigSetFonts (FcConfig
*config
,
490 FcConfigCompareValue (const FcValue
*m
,
495 FcConfigGlobAdd (FcConfig
*config
,
500 FcConfigAcceptFilename (FcConfig
*config
,
501 const FcChar8
*filename
);
504 FcConfigPatternsAdd (FcConfig
*config
,
509 FcConfigAcceptFont (FcConfig
*config
,
510 const FcPattern
*font
);
513 FcConfigModifiedTime (FcConfig
*config
);
517 FcLangCharSetPopulate (void);
520 FcCharSetFreeze (FcCharSet
*cs
);
523 FcCharSetThawAll (void);
526 FcNameUnparseCharSet (FcStrBuf
*buf
, const FcCharSet
*c
);
529 FcNameParseCharSet (FcChar8
*string
);
532 FcCharSetFindLeafCreate (FcCharSet
*fcs
, FcChar32 ucs4
);
535 FcCharSetNewBank (void);
538 FcCharSetNeededBytes (const FcCharSet
*c
);
541 FcCharSetNeededBytesAlign (void);
544 FcCharSetDistributeBytes (FcCache
* metadata
,
548 FcCharSetSerialize(int bank
, FcCharSet
*c
);
551 FcCharSetUnserialize (FcCache
* metadata
, void *block_ptr
);
554 FcCharSetGetLeaf(const FcCharSet
*c
, int i
);
557 FcCharSetGetNumbers(const FcCharSet
*c
);
561 FcValueListPrint (const FcValueListPtr l
);
564 FcLangSetPrint (const FcLangSet
*ls
);
570 FcTestPrint (const FcTest
*test
);
573 FcExprPrint (const FcExpr
*expr
);
576 FcEditPrint (const FcEdit
*edit
);
579 FcSubstPrint (const FcSubst
*subst
);
581 extern int FcDebugVal
;
584 FcDebug (void) { return FcDebugVal
; }
591 FcGetDefaultLang (void);
596 FcFileIsDir (const FcChar8
*file
);
599 FcFileScanConfig (FcFontSet
*set
,
607 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 FcFontSetNeededBytesAlign (void);
646 FcFontSetDistributeBytes (FcCache
* metadata
, void * block_ptr
);
649 FcFontSetSerialize (int bank
, FcFontSet
* s
);
652 FcFontSetUnserialize(FcCache
* metadata
, FcFontSet
* s
, void * block_ptr
);
656 FcConfigparse (void);
662 FcConfigerror (char *fmt
, ...);
665 FcConfigSaveField (const char *field
);
668 FcTestDestroy (FcTest
*test
);
671 FcExprCreateInteger (int i
);
674 FcExprCreateDouble (double d
);
677 FcExprCreateString (const FcChar8
*s
);
680 FcExprCreateMatrix (const FcMatrix
*m
);
683 FcExprCreateBool (FcBool b
);
686 FcExprCreateNil (void);
689 FcExprCreateField (const char *field
);
692 FcExprCreateConst (const FcChar8
*constant
);
695 FcExprCreateOp (FcExpr
*left
, FcOp op
, FcExpr
*right
);
698 FcExprDestroy (FcExpr
*e
);
701 FcEditDestroy (FcEdit
*e
);
709 FcMemAlloc (int kind
, int size
);
712 FcMemFree (int kind
, int size
);
716 FcFreeTypeLangSet (const FcCharSet
*charset
,
717 const FcChar8
*exclusiveLang
);
720 FcLangCompare (const FcChar8
*s1
, const FcChar8
*s2
);
723 FcCharSetForLang (const FcChar8
*lang
);
726 FcLangSetPromote (const FcChar8
*lang
);
729 FcNameParseLangSet (const FcChar8
*string
);
732 FcNameUnparseLangSet (FcStrBuf
*buf
, const FcLangSet
*ls
);
735 FcLangSetNewBank (void);
738 FcLangSetNeededBytes (const FcLangSet
*l
);
741 FcLangSetNeededBytesAlign (void);
744 FcLangSetDistributeBytes (FcCache
* metadata
,
748 FcLangSetSerialize (int bank
, FcLangSet
*l
);
751 FcLangSetUnserialize (FcCache
* metadata
, void *block_ptr
);
756 FcListPatternMatchAny (const FcPattern
*p
,
757 const FcPattern
*font
);
764 FcNameBool (const FcChar8
*v
, FcBool
*result
);
767 FcObjectDistributeBytes (FcCache
* metadata
,
771 FcObjectToPtr (const char * si
);
774 FcObjectNeededBytes (void);
777 FcObjectNeededBytesAlign (void);
780 FcObjectUnserialize (FcCache
* metadata
, void *block_ptr
);
783 FcObjectSerialize (void);
786 FcObjectPtrU (FcObjectPtr p
);
789 FcObjectPtrCompare (const FcObjectPtr a
, const FcObjectPtr b
)
795 FcObjectStaticNameFini (void);
800 FcValueCanonicalize (const FcValue
*v
);
803 FcValueListDestroy (FcValueListPtr l
);
806 FcPatternFindElt (const FcPattern
*p
, const char *object
);
809 FcPatternInsertElt (FcPattern
*p
, const char *object
);
812 FcPatternAddWithBinding (FcPattern
*p
,
815 FcValueBinding binding
,
819 FcPatternFini (void);
822 FcPatternAppend (FcPattern
*p
, FcPattern
*s
);
825 FcStrStaticName (const FcChar8
*name
);
828 FcStringHash (const FcChar8
*s
);
831 FcPatternNewBank (void);
834 FcPatternNeededBytes (FcPattern
*p
);
837 FcPatternNeededBytesAlign (void);
840 FcPatternDistributeBytes (FcCache
* metadata
, void * block_ptr
);
842 /* please don't access these outside of fcpat.c! only visible so that
843 * *PtrU can be inlined. */
844 extern FcValueList
** _fcValueLists
;
845 extern FcPatternElt
** _fcPatternElts
;
847 static inline FcValueList
*
848 FcValueListPtrU (FcValueListPtr pi
)
850 if (pi
.bank
== FC_BANK_DYNAMIC
)
853 return &_fcValueLists
[FcCacheBankToIndex(pi
.bank
)][pi
.u
.stat
];
856 static inline FcPatternElt
*
857 FcPatternEltU (FcPatternEltPtr pei
)
859 if (pei
.bank
== FC_BANK_DYNAMIC
)
862 return &_fcPatternElts
[FcCacheBankToIndex(pei
.bank
)][pei
.u
.stat
];
866 FcValueListPtrCreateDynamic(FcValueList
* p
);
869 FcPatternSerialize (int bank
, FcPattern
* p
);
872 FcPatternUnserialize (FcCache
* metadata
, void *block_ptr
);
878 extern const FcMatrix FcIdentityMatrix
;
881 FcMatrixFree (FcMatrix
*mat
);
885 FcStrSetSort (FcStrSet
* set
);
888 FcStrPlus (const FcChar8
*s1
, const FcChar8
*s2
);
891 FcStrFree (FcChar8
*s
);
894 FcStrBufInit (FcStrBuf
*buf
, FcChar8
*init
, int size
);
897 FcStrBufDestroy (FcStrBuf
*buf
);
900 FcStrBufDone (FcStrBuf
*buf
);
903 FcStrBufChar (FcStrBuf
*buf
, FcChar8 c
);
906 FcStrBufString (FcStrBuf
*buf
, const FcChar8
*s
);
909 FcStrBufData (FcStrBuf
*buf
, const FcChar8
*s
, int len
);
912 FcStrCmpIgnoreBlanksAndCase (const FcChar8
*s1
, const FcChar8
*s2
);
915 FcStrContainsIgnoreBlanksAndCase (const FcChar8
*s1
, const FcChar8
*s2
);
918 FcStrContainsIgnoreCase (const FcChar8
*s1
, const FcChar8
*s2
);
921 FcStrUsesHome (const FcChar8
*s
);
924 FcStrLastSlash (const FcChar8
*path
);
927 FcStrHashIgnoreCase (const FcChar8
*s
);
929 #endif /* _FC_INT_H_ */