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
);
455 FcCacheFindBankDir (int bank
);
460 FcConfigAddConfigDir (FcConfig
*config
,
464 FcConfigAddFontDir (FcConfig
*config
,
468 FcConfigAddDir (FcConfig
*config
,
472 FcConfigAddConfigFile (FcConfig
*config
,
476 FcConfigSetCache (FcConfig
*config
,
480 FcConfigAddBlank (FcConfig
*config
,
484 FcConfigAddEdit (FcConfig
*config
,
490 FcConfigSetFonts (FcConfig
*config
,
495 FcConfigCompareValue (const FcValue
*m
,
500 FcConfigGlobAdd (FcConfig
*config
,
505 FcConfigAcceptFilename (FcConfig
*config
,
506 const FcChar8
*filename
);
509 FcConfigPatternsAdd (FcConfig
*config
,
514 FcConfigAcceptFont (FcConfig
*config
,
515 const FcPattern
*font
);
519 FcCharSetFreeze (FcCharSet
*cs
);
522 FcCharSetThawAll (void);
525 FcNameUnparseCharSet (FcStrBuf
*buf
, const FcCharSet
*c
);
528 FcNameParseCharSet (FcChar8
*string
);
531 FcCharSetFindLeafCreate (FcCharSet
*fcs
, FcChar32 ucs4
);
534 FcCharSetNewBank (void);
537 FcCharSetNeededBytes (const FcCharSet
*c
);
540 FcCharSetDistributeBytes (FcCache
* metadata
,
544 FcCharSetSerialize(int bank
, FcCharSet
*c
);
547 FcCharSetUnserialize (FcCache metadata
, void *block_ptr
);
550 FcCharSetGetLeaf(const FcCharSet
*c
, int i
);
553 FcCharSetGetNumbers(const FcCharSet
*c
);
557 FcValueListPrint (const FcValueListPtr l
);
560 FcLangSetPrint (const FcLangSet
*ls
);
566 FcTestPrint (const FcTest
*test
);
569 FcExprPrint (const FcExpr
*expr
);
572 FcEditPrint (const FcEdit
*edit
);
575 FcSubstPrint (const FcSubst
*subst
);
582 FcGetDefaultLang (void);
587 FcFileIsDir (const FcChar8
*file
);
590 FcFileScanConfig (FcFontSet
*set
,
599 FcDirScanConfig (FcFontSet
*set
,
613 FcFreeTypeIsExclusiveLang (const FcChar8
*lang
);
616 FcFreeTypeHasLang (FcPattern
*pattern
, const FcChar8
*lang
);
619 FcFreeTypeUcs4ToPrivate (FcChar32 ucs4
, const FcCharMap
*map
);
622 FcFreeTypePrivateToUcs4 (FcChar32
private, const FcCharMap
*map
);
625 FcFreeTypeGetPrivateMap (FT_Encoding encoding
);
630 FcFontSetNewBank (void);
633 FcFontSetNeededBytes (FcFontSet
*s
);
636 FcFontSetDistributeBytes (FcCache
* metadata
, void * block_ptr
);
639 FcFontSetSerialize (int bank
, FcFontSet
* s
);
642 FcFontSetUnserialize(FcCache metadata
, FcFontSet
* s
, void * block_ptr
);
646 FcConfigparse (void);
652 FcConfigerror (char *fmt
, ...);
655 FcConfigSaveField (const char *field
);
658 FcTestDestroy (FcTest
*test
);
661 FcExprCreateInteger (int i
);
664 FcExprCreateDouble (double d
);
667 FcExprCreateString (const FcChar8
*s
);
670 FcExprCreateMatrix (const FcMatrix
*m
);
673 FcExprCreateBool (FcBool b
);
676 FcExprCreateNil (void);
679 FcExprCreateField (const char *field
);
682 FcExprCreateConst (const FcChar8
*constant
);
685 FcExprCreateOp (FcExpr
*left
, FcOp op
, FcExpr
*right
);
688 FcExprDestroy (FcExpr
*e
);
691 FcEditDestroy (FcEdit
*e
);
699 FcMemAlloc (int kind
, int size
);
702 FcMemFree (int kind
, int size
);
706 FcFreeTypeLangSet (const FcCharSet
*charset
,
707 const FcChar8
*exclusiveLang
);
710 FcLangCompare (const FcChar8
*s1
, const FcChar8
*s2
);
713 FcCharSetForLang (const FcChar8
*lang
);
716 FcLangSetPromote (const FcChar8
*lang
);
719 FcNameParseLangSet (const FcChar8
*string
);
722 FcNameUnparseLangSet (FcStrBuf
*buf
, const FcLangSet
*ls
);
725 FcLangSetNewBank (void);
728 FcLangSetNeededBytes (const FcLangSet
*l
);
731 FcLangSetDistributeBytes (FcCache
* metadata
,
735 FcLangSetSerialize (int bank
, FcLangSet
*l
);
738 FcLangSetUnserialize (FcCache metadata
, void *block_ptr
);
743 FcListPatternMatchAny (const FcPattern
*p
,
744 const FcPattern
*font
);
751 FcNameBool (const FcChar8
*v
, FcBool
*result
);
754 FcObjectDistributeBytes (FcCache
* metadata
,
758 FcObjectToPtr (const char * si
);
761 FcObjectNeededBytes (void);
764 FcObjectUnserialize (FcCache metadata
, void *block_ptr
);
767 FcObjectSerialize (void);
770 FcObjectPtrU (FcObjectPtr p
);
773 FcObjectPtrCompare (FcObjectPtr a
, FcObjectPtr b
);
776 FcObjectStaticNameFini (void);
781 FcValueCanonicalize (const FcValue
*v
);
784 FcValueListDestroy (FcValueListPtr l
);
787 FcPatternFindElt (const FcPattern
*p
, const char *object
);
790 FcPatternInsertElt (FcPattern
*p
, const char *object
);
793 FcPatternAddWithBinding (FcPattern
*p
,
796 FcValueBinding binding
,
800 FcPatternFreeze (FcPattern
*p
);
803 FcPatternFini (void);
806 FcPatternAppend (FcPattern
*p
, FcPattern
*s
);
809 FcPatternAddFullFname (const FcPattern
*p
, const char *fname
);
812 FcPatternFindFullFname (const FcPattern
*p
);
815 FcStrStaticName (const FcChar8
*name
);
818 FcStringHash (const FcChar8
*s
);
821 FcPatternNewBank (void);
824 FcPatternNeededBytes (FcPattern
*p
);
827 FcPatternDistributeBytes (FcCache
* metadata
, void * block_ptr
);
830 FcValueListPtrU(FcValueListPtr p
);
833 FcPatternEltU (FcPatternEltPtr pei
);
836 FcValueListPtrCreateDynamic(FcValueList
* p
);
839 FcPatternSerialize (int bank
, FcPattern
* p
);
842 FcPatternUnserialize (FcCache metadata
, void *block_ptr
);
848 extern const FcMatrix FcIdentityMatrix
;
851 FcMatrixFree (FcMatrix
*mat
);
855 FcStrSetSort (FcStrSet
* set
);
858 FcStrPlus (const FcChar8
*s1
, const FcChar8
*s2
);
861 FcStrFree (FcChar8
*s
);
864 FcStrBufInit (FcStrBuf
*buf
, FcChar8
*init
, int size
);
867 FcStrBufDestroy (FcStrBuf
*buf
);
870 FcStrBufDone (FcStrBuf
*buf
);
873 FcStrBufChar (FcStrBuf
*buf
, FcChar8 c
);
876 FcStrBufString (FcStrBuf
*buf
, const FcChar8
*s
);
879 FcStrBufData (FcStrBuf
*buf
, const FcChar8
*s
, int len
);
882 FcStrCmpIgnoreBlanksAndCase (const FcChar8
*s1
, const FcChar8
*s2
);
885 FcStrContainsIgnoreBlanksAndCase (const FcChar8
*s1
, const FcChar8
*s2
);
888 FcStrContainsIgnoreCase (const FcChar8
*s1
, const FcChar8
*s2
);
891 FcStrUsesHome (const FcChar8
*s
);
894 FcStrLastSlash (const FcChar8
*path
);
897 FcStrHashIgnoreCase (const FcChar8
*s
);
899 #endif /* _FC_INT_H_ */