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
{
252 int patternelt_count
;
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
,
430 const FcChar8
*cache_file
);
433 FcGlobalCacheUpdate (FcGlobalCache
*cache
,
438 FcGlobalCacheSave (FcGlobalCache
*cache
,
439 const FcChar8
*cache_file
);
442 FcCacheRead (FcConfig
*config
, FcGlobalCache
* cache
);
445 FcDirCacheWrite (FcFontSet
*set
, const FcChar8
*dir
);
448 FcCacheBankToIndex (int bank
);
453 FcConfigAddConfigDir (FcConfig
*config
,
457 FcConfigAddFontDir (FcConfig
*config
,
461 FcConfigAddDir (FcConfig
*config
,
465 FcConfigAddConfigFile (FcConfig
*config
,
469 FcConfigSetCache (FcConfig
*config
,
473 FcConfigAddBlank (FcConfig
*config
,
477 FcConfigAddEdit (FcConfig
*config
,
483 FcConfigSetFonts (FcConfig
*config
,
488 FcConfigCompareValue (const FcValue
*m
,
493 FcConfigGlobAdd (FcConfig
*config
,
498 FcConfigAcceptFilename (FcConfig
*config
,
499 const FcChar8
*filename
);
502 FcConfigPatternsAdd (FcConfig
*config
,
507 FcConfigAcceptFont (FcConfig
*config
,
508 const FcPattern
*font
);
512 FcCharSetFreeze (FcCharSet
*cs
);
515 FcCharSetThawAll (void);
518 FcNameUnparseCharSet (FcStrBuf
*buf
, const FcCharSet
*c
);
521 FcNameParseCharSet (FcChar8
*string
);
524 FcCharSetFindLeafCreate (FcCharSet
*fcs
, FcChar32 ucs4
);
527 FcCharSetNewBank (void);
530 FcCharSetNeededBytes (const FcCharSet
*c
);
533 FcCharSetDistributeBytes (FcCache
* metadata
,
537 FcCharSetSerialize(int bank
, FcCharSet
*c
);
540 FcCharSetUnserialize (FcCache metadata
, void *block_ptr
);
543 FcCharSetGetLeaf(const FcCharSet
*c
, int i
);
546 FcCharSetGetNumbers(const FcCharSet
*c
);
550 FcValueListPrint (const FcValueListPtr l
);
553 FcLangSetPrint (const FcLangSet
*ls
);
559 FcTestPrint (const FcTest
*test
);
562 FcExprPrint (const FcExpr
*expr
);
565 FcEditPrint (const FcEdit
*edit
);
568 FcSubstPrint (const FcSubst
*subst
);
576 FcFileIsDir (const FcChar8
*file
);
579 FcFileScanConfig (FcFontSet
*set
,
588 FcDirScanConfig (FcFontSet
*set
,
602 FcFreeTypeIsExclusiveLang (const FcChar8
*lang
);
605 FcFreeTypeHasLang (FcPattern
*pattern
, const FcChar8
*lang
);
608 FcFreeTypeUcs4ToPrivate (FcChar32 ucs4
, const FcCharMap
*map
);
611 FcFreeTypePrivateToUcs4 (FcChar32
private, const FcCharMap
*map
);
614 FcFreeTypeGetPrivateMap (FT_Encoding encoding
);
619 FcFontSetNewBank (void);
622 FcFontSetNeededBytes (FcFontSet
*s
);
625 FcFontSetDistributeBytes (FcCache
* metadata
, void * block_ptr
);
628 FcFontSetSerialize (int bank
, FcFontSet
* s
);
631 FcFontSetUnserialize(FcCache metadata
, FcFontSet
* s
, void * block_ptr
);
635 FcConfigparse (void);
641 FcConfigerror (char *fmt
, ...);
644 FcConfigSaveField (const char *field
);
647 FcTestDestroy (FcTest
*test
);
650 FcExprCreateInteger (int i
);
653 FcExprCreateDouble (double d
);
656 FcExprCreateString (const FcChar8
*s
);
659 FcExprCreateMatrix (const FcMatrix
*m
);
662 FcExprCreateBool (FcBool b
);
665 FcExprCreateNil (void);
668 FcExprCreateField (const char *field
);
671 FcExprCreateConst (const FcChar8
*constant
);
674 FcExprCreateOp (FcExpr
*left
, FcOp op
, FcExpr
*right
);
677 FcExprDestroy (FcExpr
*e
);
680 FcEditDestroy (FcEdit
*e
);
688 FcMemAlloc (int kind
, int size
);
691 FcMemFree (int kind
, int size
);
695 FcFreeTypeLangSet (const FcCharSet
*charset
,
696 const FcChar8
*exclusiveLang
);
699 FcLangCompare (const FcChar8
*s1
, const FcChar8
*s2
);
702 FcCharSetForLang (const FcChar8
*lang
);
705 FcLangSetPromote (const FcChar8
*lang
);
708 FcNameParseLangSet (const FcChar8
*string
);
711 FcNameUnparseLangSet (FcStrBuf
*buf
, const FcLangSet
*ls
);
714 FcLangSetNewBank (void);
717 FcLangSetNeededBytes (const FcLangSet
*l
);
720 FcLangSetDistributeBytes (FcCache
* metadata
,
724 FcLangSetSerialize (int bank
, FcLangSet
*l
);
727 FcLangSetUnserialize (FcCache metadata
, void *block_ptr
);
732 FcListPatternMatchAny (const FcPattern
*p
,
733 const FcPattern
*font
);
740 FcNameBool (const FcChar8
*v
, FcBool
*result
);
743 FcObjectDistributeBytes (FcCache
* metadata
,
747 FcObjectToPtr (const char * si
);
750 FcObjectNeededBytes (void);
753 FcObjectUnserialize (FcCache metadata
, void *block_ptr
);
756 FcObjectSerialize (void);
759 FcObjectPtrU (FcObjectPtr p
);
762 FcObjectPtrCompare (FcObjectPtr a
, FcObjectPtr b
);
765 FcObjectStaticNameFini (void);
770 FcValueCanonicalize (const FcValue
*v
);
773 FcValueListDestroy (FcValueListPtr l
);
776 FcPatternFindElt (const FcPattern
*p
, const char *object
);
779 FcPatternInsertElt (FcPattern
*p
, const char *object
);
782 FcPatternAddWithBinding (FcPattern
*p
,
785 FcValueBinding binding
,
789 FcPatternFreeze (FcPattern
*p
);
792 FcPatternFini (void);
795 FcPatternAppend (FcPattern
*p
, FcPattern
*s
);
798 FcStrStaticName (const char *name
);
801 FcStringHash (const FcChar8
*s
);
804 FcPatternNewBank (void);
807 FcPatternNeededBytes (FcPattern
*p
);
810 FcPatternDistributeBytes (FcCache
* metadata
, void * block_ptr
);
813 FcValueListPtrU(FcValueListPtr p
);
816 FcPatternEltU (FcPatternEltPtr pei
);
819 FcValueListPtrCreateDynamic(FcValueList
* p
);
822 FcPatternSerialize (int bank
, FcPattern
* p
);
825 FcPatternUnserialize (FcCache metadata
, void *block_ptr
);
831 extern const FcMatrix FcIdentityMatrix
;
834 FcMatrixFree (FcMatrix
*mat
);
838 FcStrSetSort (FcStrSet
* set
);
841 FcStrPlus (const FcChar8
*s1
, const FcChar8
*s2
);
844 FcStrFree (FcChar8
*s
);
847 FcStrBufInit (FcStrBuf
*buf
, FcChar8
*init
, int size
);
850 FcStrBufDestroy (FcStrBuf
*buf
);
853 FcStrBufDone (FcStrBuf
*buf
);
856 FcStrBufChar (FcStrBuf
*buf
, FcChar8 c
);
859 FcStrBufString (FcStrBuf
*buf
, const FcChar8
*s
);
862 FcStrBufData (FcStrBuf
*buf
, const FcChar8
*s
, int len
);
865 FcStrCmpIgnoreBlanksAndCase (const FcChar8
*s1
, const FcChar8
*s2
);
868 FcStrContainsIgnoreBlanksAndCase (const FcChar8
*s1
, const FcChar8
*s2
);
871 FcStrContainsIgnoreCase (const FcChar8
*s1
, const FcChar8
*s2
);
874 FcStrUsesHome (const FcChar8
*s
);
877 FcStrLastSlash (const FcChar8
*path
);
880 FcStrHashIgnoreCase (const FcChar8
*s
);
882 #endif /* _FC_INT_H_ */