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 typedef enum _FcValueBinding
{
103 FcValueBindingWeak
, FcValueBindingStrong
, FcValueBindingSame
106 typedef struct _FcValueListPtr
{
110 struct _FcValueList
*dyn
;
114 typedef struct _FcValueList
{
118 FcValueBinding binding
;
121 typedef int FcObjectPtr
;
123 typedef struct _FcPatternEltPtr
{
127 struct _FcPatternElt
*dyn
;
131 typedef struct _FcPatternElt
{
133 FcValueListPtr values
;
139 FcPatternEltPtr elts
;
145 FcOpInteger
, FcOpDouble
, FcOpString
, FcOpMatrix
, FcOpBool
, FcOpCharSet
,
147 FcOpField
, FcOpConst
,
148 FcOpAssign
, FcOpAssignReplace
,
149 FcOpPrependFirst
, FcOpPrepend
, FcOpAppend
, FcOpAppendLast
,
151 FcOpOr
, FcOpAnd
, FcOpEqual
, FcOpNotEqual
,
152 FcOpContains
, FcOpListing
, FcOpNotContains
,
153 FcOpLess
, FcOpLessEqual
, FcOpMore
, FcOpMoreEqual
,
154 FcOpPlus
, FcOpMinus
, FcOpTimes
, FcOpDivide
,
155 FcOpNot
, FcOpComma
, FcOpFloor
, FcOpCeil
, FcOpRound
, FcOpTrunc
,
159 typedef struct _FcExpr
{
171 struct _FcExpr
*left
, *right
;
176 typedef enum _FcQual
{
177 FcQualAny
, FcQualAll
, FcQualFirst
, FcQualNotFirst
180 #define FcMatchDefault ((FcMatchKind) -1)
182 typedef struct _FcTest
{
183 struct _FcTest
*next
;
191 typedef struct _FcEdit
{
192 struct _FcEdit
*next
;
196 FcValueBinding binding
;
199 typedef struct _FcSubst
{
200 struct _FcSubst
*next
;
205 typedef struct _FcCharLeaf
{
206 FcChar32 map
[256/32];
209 #define FC_REF_CONSTANT -1
212 int ref
; /* reference count */
213 int num
; /* size of leaves and numbers arrays */
228 int ref
; /* reference count */
239 typedef struct _FcStrBuf
{
247 typedef struct _FcCache
{
248 int magic
; /* 0xFC02FC02 */
249 int count
; /* number of bytes of data in block */
250 int bank
; /* bank ID */
251 int pattern_count
; /* number of FcPatterns */
252 int patternelt_count
; /* number of FcPatternElts */
253 int valuelist_count
; /* number of FcValueLists */
254 int str_count
; /* size of strings appearing as FcValues */
255 int langset_count
; /* number of FcLangSets */
256 int charset_count
; /* number of FcCharSets */
257 int charset_numbers_count
;
258 int charset_leaf_count
;
259 int charset_leaf_idx_count
;
263 * To map adobe glyph names to unicode values, a precomputed hash
267 typedef struct _FcGlyphName
{
268 FcChar32 ucs
; /* unicode value */
269 FcChar8 name
[1]; /* name extends beyond struct */
273 * To perform case-insensitive string comparisons, a table
274 * is used which holds three different kinds of folding data.
276 * The first is a range of upper case values mapping to a range
277 * of their lower case equivalents. Within each range, the offset
278 * between upper and lower case is constant.
280 * The second is a range of upper case values which are interleaved
281 * with their lower case equivalents.
283 * The third is a set of raw unicode values mapping to a list
284 * of unicode values for comparison purposes. This allows conversion
285 * of ß to "ss" so that SS, ss and ß all match. A separate array
286 * holds the list of unicode values for each entry.
288 * These are packed into a single table. Using a binary search,
289 * the appropriate entry can be located.
292 #define FC_CASE_FOLD_RANGE 0
293 #define FC_CASE_FOLD_EVEN_ODD 1
294 #define FC_CASE_FOLD_FULL 2
296 typedef struct _FcCaseFold
{
300 short offset
; /* lower - upper for RANGE, table id for FULL */
303 #define FC_MAX_FILE_LEN 4096
305 #define FC_STORAGE_STATIC 0x80
306 #define fc_value_string(v) (((v)->type & FC_STORAGE_STATIC) ? ((FcChar8 *) v) + (v)->u.s_off : (v) -> u.s)
307 #define fc_value_charset(v) (((v)->type & FC_STORAGE_STATIC) ? (const FcCharSet *)(((char *) v) + (v)->u.c_off) : (v) -> u.c)
308 #define fc_value_langset(v) (((v)->type & FC_STORAGE_STATIC) ? (const FcLangSet *)(((char *) v) + (v)->u.l_off) : (v) -> u.l)
311 * The per-user ~/.fonts.cache-<version> file is loaded into
312 * this data structure. Each directory gets a substructure
313 * which is validated by comparing the directory timestamp with
314 * that saved in the cache. When valid, the entire directory cache
315 * can be immediately loaded without reading the directory. Otherwise,
316 * the files are checked individually; updated files are loaded into the
317 * cache which is then rewritten to the users home directory
320 #define FC_CACHE_MAGIC 0xFC02FC02
322 typedef struct _FcGlobalCacheDir FcGlobalCacheDir
;
324 struct _FcGlobalCacheDir
{
325 struct _FcGlobalCacheDir
*next
;
332 typedef struct _FcGlobalCache
{
333 FcGlobalCacheDir
*dirs
;
339 FcChar8
*file
; /* original file name */
340 FcChar8
*new; /* temp file name -- write data here */
341 FcChar8
*lck
; /* lockfile name (used for locking) */
342 FcChar8
*tmp
; /* tmpfile name (used for locking) */
353 * File names loaded from the configuration -- saved here as the
354 * cache file must be consulted before the directories are scanned,
355 * and those directives may occur in any order
357 FcStrSet
*configDirs
; /* directories to scan for fonts */
358 FcChar8
*cache
; /* name of per-user cache file */
360 * Set of allowed blank chars -- used to
361 * trim fonts of bogus glyphs
365 * List of directories containing fonts,
366 * built by recursively scanning the set
367 * of configured directories
371 * Names of all of the configuration files used
372 * to create this configuration
374 FcStrSet
*configFiles
; /* config files loaded */
376 * Substitution instructions for patterns and fonts;
377 * maxObjects is used to allocate appropriate intermediate storage
378 * while performing a whole set of substitutions
380 FcSubst
*substPattern
; /* substitutions for patterns */
381 FcSubst
*substFont
; /* substitutions for fonts */
382 int maxObjects
; /* maximum number of tests in all substs */
384 * List of patterns used to control font file selection
386 FcStrSet
*acceptGlobs
;
387 FcStrSet
*rejectGlobs
;
388 FcFontSet
*acceptPatterns
;
389 FcFontSet
*rejectPatterns
;
391 * The set of fonts loaded from the listed directories; the
392 * order within the set does not determine the font selection,
393 * except in the case of identical matches in which case earlier fonts
394 * match preferrentially
396 FcFontSet
*fonts
[FcSetApplication
+ 1];
398 * Fontconfig can periodically rescan the system configuration
399 * and font directories. This rescanning occurs when font
400 * listing requests are made, but no more often than rescanInterval
403 time_t rescanTime
; /* last time information was scanned */
404 int rescanInterval
; /* interval between scans */
407 extern FcConfig
*_fcConfig
;
409 typedef struct _FcCharMap FcCharMap
;
416 FcGlobalCacheCreate (void);
419 FcGlobalCacheDestroy (FcGlobalCache
*cache
);
422 FcGlobalCacheReadDir (FcFontSet
*set
,
424 FcGlobalCache
*cache
,
429 FcGlobalCacheLoad (FcGlobalCache
*cache
,
431 const FcChar8
*cache_file
);
434 FcGlobalCacheUpdate (FcGlobalCache
*cache
,
439 FcGlobalCacheSave (FcGlobalCache
*cache
,
440 const FcChar8
*cache_file
);
443 FcCacheRead (FcConfig
*config
, FcGlobalCache
* cache
);
446 FcDirCacheWrite (FcFontSet
*set
, FcStrSet
* dirs
, const FcChar8
*dir
);
449 FcDirCacheRead (FcFontSet
* set
, FcStrSet
* dirs
, const FcChar8
*dir
);
452 FcCacheBankToIndex (int bank
);
457 FcConfigAddConfigDir (FcConfig
*config
,
461 FcConfigAddFontDir (FcConfig
*config
,
465 FcConfigAddDir (FcConfig
*config
,
469 FcConfigAddConfigFile (FcConfig
*config
,
473 FcConfigSetCache (FcConfig
*config
,
477 FcConfigAddBlank (FcConfig
*config
,
481 FcConfigAddEdit (FcConfig
*config
,
487 FcConfigSetFonts (FcConfig
*config
,
492 FcConfigCompareValue (const FcValue
*m
,
497 FcConfigGlobAdd (FcConfig
*config
,
502 FcConfigAcceptFilename (FcConfig
*config
,
503 const FcChar8
*filename
);
506 FcConfigPatternsAdd (FcConfig
*config
,
511 FcConfigAcceptFont (FcConfig
*config
,
512 const FcPattern
*font
);
516 FcCharSetFreeze (FcCharSet
*cs
);
519 FcCharSetThawAll (void);
522 FcNameUnparseCharSet (FcStrBuf
*buf
, const FcCharSet
*c
);
525 FcNameParseCharSet (FcChar8
*string
);
528 FcCharSetFindLeafCreate (FcCharSet
*fcs
, FcChar32 ucs4
);
531 FcCharSetNewBank (void);
534 FcCharSetNeededBytes (const FcCharSet
*c
);
537 FcCharSetDistributeBytes (FcCache
* metadata
,
541 FcCharSetSerialize(int bank
, FcCharSet
*c
);
544 FcCharSetUnserialize (FcCache metadata
, void *block_ptr
);
547 FcCharSetGetLeaf(const FcCharSet
*c
, int i
);
550 FcCharSetGetNumbers(const FcCharSet
*c
);
554 FcValueListPrint (const FcValueListPtr l
);
557 FcLangSetPrint (const FcLangSet
*ls
);
563 FcTestPrint (const FcTest
*test
);
566 FcExprPrint (const FcExpr
*expr
);
569 FcEditPrint (const FcEdit
*edit
);
572 FcSubstPrint (const FcSubst
*subst
);
579 FcGetDefaultLang (void);
584 FcFileIsDir (const FcChar8
*file
);
587 FcFileScanConfig (FcFontSet
*set
,
596 FcDirScanConfig (FcFontSet
*set
,
610 FcFreeTypeIsExclusiveLang (const FcChar8
*lang
);
613 FcFreeTypeHasLang (FcPattern
*pattern
, const FcChar8
*lang
);
616 FcFreeTypeUcs4ToPrivate (FcChar32 ucs4
, const FcCharMap
*map
);
619 FcFreeTypePrivateToUcs4 (FcChar32
private, const FcCharMap
*map
);
622 FcFreeTypeGetPrivateMap (FT_Encoding encoding
);
627 FcFontSetNewBank (void);
630 FcFontSetNeededBytes (FcFontSet
*s
);
633 FcFontSetDistributeBytes (FcCache
* metadata
, void * block_ptr
);
636 FcFontSetSerialize (int bank
, FcFontSet
* s
);
639 FcFontSetUnserialize(FcCache metadata
, FcFontSet
* s
, void * block_ptr
);
643 FcConfigparse (void);
649 FcConfigerror (char *fmt
, ...);
652 FcConfigSaveField (const char *field
);
655 FcTestDestroy (FcTest
*test
);
658 FcExprCreateInteger (int i
);
661 FcExprCreateDouble (double d
);
664 FcExprCreateString (const FcChar8
*s
);
667 FcExprCreateMatrix (const FcMatrix
*m
);
670 FcExprCreateBool (FcBool b
);
673 FcExprCreateNil (void);
676 FcExprCreateField (const char *field
);
679 FcExprCreateConst (const FcChar8
*constant
);
682 FcExprCreateOp (FcExpr
*left
, FcOp op
, FcExpr
*right
);
685 FcExprDestroy (FcExpr
*e
);
688 FcEditDestroy (FcEdit
*e
);
696 FcMemAlloc (int kind
, int size
);
699 FcMemFree (int kind
, int size
);
703 FcFreeTypeLangSet (const FcCharSet
*charset
,
704 const FcChar8
*exclusiveLang
);
707 FcLangCompare (const FcChar8
*s1
, const FcChar8
*s2
);
710 FcCharSetForLang (const FcChar8
*lang
);
713 FcLangSetPromote (const FcChar8
*lang
);
716 FcNameParseLangSet (const FcChar8
*string
);
719 FcNameUnparseLangSet (FcStrBuf
*buf
, const FcLangSet
*ls
);
722 FcLangSetNewBank (void);
725 FcLangSetNeededBytes (const FcLangSet
*l
);
728 FcLangSetDistributeBytes (FcCache
* metadata
,
732 FcLangSetSerialize (int bank
, FcLangSet
*l
);
735 FcLangSetUnserialize (FcCache metadata
, void *block_ptr
);
740 FcListPatternMatchAny (const FcPattern
*p
,
741 const FcPattern
*font
);
748 FcNameBool (const FcChar8
*v
, FcBool
*result
);
751 FcObjectDistributeBytes (FcCache
* metadata
,
755 FcObjectToPtr (const char * si
);
758 FcObjectNeededBytes (void);
761 FcObjectUnserialize (FcCache metadata
, void *block_ptr
);
764 FcObjectSerialize (void);
767 FcObjectPtrU (FcObjectPtr p
);
770 FcObjectPtrCompare (FcObjectPtr a
, FcObjectPtr b
);
773 FcObjectStaticNameFini (void);
778 FcValueCanonicalize (const FcValue
*v
);
781 FcValueListDestroy (FcValueListPtr l
);
784 FcPatternFindElt (const FcPattern
*p
, const char *object
);
787 FcPatternInsertElt (FcPattern
*p
, const char *object
);
790 FcPatternAddWithBinding (FcPattern
*p
,
793 FcValueBinding binding
,
797 FcPatternFreeze (FcPattern
*p
);
800 FcPatternFini (void);
803 FcPatternAppend (FcPattern
*p
, FcPattern
*s
);
806 FcStrStaticName (const FcChar8
*name
);
809 FcStringHash (const FcChar8
*s
);
812 FcPatternNewBank (void);
815 FcPatternNeededBytes (FcPattern
*p
);
818 FcPatternDistributeBytes (FcCache
* metadata
, void * block_ptr
);
821 FcValueListPtrU(FcValueListPtr p
);
824 FcPatternEltU (FcPatternEltPtr pei
);
827 FcValueListPtrCreateDynamic(FcValueList
* p
);
830 FcPatternSerialize (int bank
, FcPattern
* p
);
833 FcPatternUnserialize (FcCache metadata
, void *block_ptr
);
839 extern const FcMatrix FcIdentityMatrix
;
842 FcMatrixFree (FcMatrix
*mat
);
846 FcStrSetSort (FcStrSet
* set
);
849 FcStrPlus (const FcChar8
*s1
, const FcChar8
*s2
);
852 FcStrFree (FcChar8
*s
);
855 FcStrBufInit (FcStrBuf
*buf
, FcChar8
*init
, int size
);
858 FcStrBufDestroy (FcStrBuf
*buf
);
861 FcStrBufDone (FcStrBuf
*buf
);
864 FcStrBufChar (FcStrBuf
*buf
, FcChar8 c
);
867 FcStrBufString (FcStrBuf
*buf
, const FcChar8
*s
);
870 FcStrBufData (FcStrBuf
*buf
, const FcChar8
*s
, int len
);
873 FcStrCmpIgnoreBlanksAndCase (const FcChar8
*s1
, const FcChar8
*s2
);
876 FcStrContainsIgnoreBlanksAndCase (const FcChar8
*s1
, const FcChar8
*s2
);
879 FcStrContainsIgnoreCase (const FcChar8
*s1
, const FcChar8
*s2
);
882 FcStrUsesHome (const FcChar8
*s
);
885 FcStrLastSlash (const FcChar8
*path
);
888 FcStrHashIgnoreCase (const FcChar8
*s
);
890 #endif /* _FC_INT_H_ */