fcint.h 33.5 KB
Newer Older
Keith Packard's avatar
Keith Packard committed
1
/*
2
 * fontconfig/src/fcint.h
Keith Packard's avatar
Keith Packard committed
3
 *
4
 * Copyright © 2000 Keith Packard
Keith Packard's avatar
Keith Packard committed
5
6
7
8
9
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
10
 * documentation, and that the name of the author(s) not be used in
Keith Packard's avatar
Keith Packard committed
11
 * advertising or publicity pertaining to distribution of the software without
12
 * specific, written prior permission.  The authors make no
Keith Packard's avatar
Keith Packard committed
13
14
15
 * representations about the suitability of this software for any purpose.  It
 * is provided "as is" without express or implied warranty.
 *
16
 * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
Keith Packard's avatar
Keith Packard committed
17
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18
 * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
Keith Packard's avatar
Keith Packard committed
19
20
21
22
23
24
25
26
27
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef _FCINT_H_
#define _FCINT_H_

28
29
30
31
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

32
33
#include "fcstdint.h"

Keith Packard's avatar
Keith Packard committed
34
35
36
37
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
38
#include <assert.h>
Keith Packard's avatar
Keith Packard committed
39
#include <errno.h>
40
#include <limits.h>
41
42
#include <float.h>
#include <math.h>
Keith Packard's avatar
Keith Packard committed
43
#include <unistd.h>
44
#include <stddef.h>
Keith Packard's avatar
Keith Packard committed
45
46
#include <sys/types.h>
#include <sys/stat.h>
47
#include <time.h>
Keith Packard's avatar
Keith Packard committed
48
#include <fontconfig/fontconfig.h>
49
#include <fontconfig/fcprivate.h>
50
#include "fcdeprecate.h"
Behdad Esfahbod's avatar
Behdad Esfahbod committed
51
52
#include "fcmutex.h"
#include "fcatomic.h"
Keith Packard's avatar
Keith Packard committed
53
54
55
56
57

#ifndef FC_CONFIG_PATH
#define FC_CONFIG_PATH "fonts.conf"
#endif

Tor Lillqvist's avatar
Tor Lillqvist committed
58
#ifdef _WIN32
59
#  include "fcwindows.h"
60
61
62
63
64
typedef UINT (WINAPI *pfnGetSystemWindowsDirectory)(LPSTR, UINT);
typedef HRESULT (WINAPI *pfnSHGetFolderPathA)(HWND, int, HANDLE, DWORD, LPSTR);
extern pfnGetSystemWindowsDirectory pGetSystemWindowsDirectory;
extern pfnSHGetFolderPathA pSHGetFolderPathA;
#  define FC_SEARCH_PATH_SEPARATOR ';'
65
#  define FC_DIR_SEPARATOR         '\\'
66
#  define FC_DIR_SEPARATOR_S       "\\"
Tor Lillqvist's avatar
Tor Lillqvist committed
67
#else
68
#  define FC_SEARCH_PATH_SEPARATOR ':'
69
#  define FC_DIR_SEPARATOR         '/'
70
#  define FC_DIR_SEPARATOR_S       "/"
Tor Lillqvist's avatar
Tor Lillqvist committed
71
72
#endif

Akira TAGOH's avatar
Akira TAGOH committed
73
74
75
76
77
78
#ifdef PATH_MAX
#define FC_PATH_MAX	PATH_MAX
#else
#define FC_PATH_MAX	128
#endif

79
80
81
82
83
84
#if __GNUC__ >= 4
#define FC_UNUSED	__attribute__((unused))
#else
#define FC_UNUSED
#endif

Keith Packard's avatar
Keith Packard committed
85
86
87
88
89
90
91
92
#define FC_DBG_MATCH	1
#define FC_DBG_MATCHV	2
#define FC_DBG_EDIT	4
#define FC_DBG_FONTSET	8
#define FC_DBG_CACHE	16
#define FC_DBG_CACHEV	32
#define FC_DBG_PARSE	64
#define FC_DBG_SCAN	128
93
#define FC_DBG_SCANV	256
94
#define FC_DBG_CONFIG	1024
95
#define FC_DBG_LANGSET	2048
96
#define FC_DBG_MATCH2	4096
Keith Packard's avatar
Keith Packard committed
97

98
#define _FC_ASSERT_STATIC1(_line, _cond) typedef int _static_assert_on_line_##_line##_failed[(_cond)?1:-1] FC_UNUSED
99
100
101
#define _FC_ASSERT_STATIC0(_line, _cond) _FC_ASSERT_STATIC1 (_line, (_cond))
#define FC_ASSERT_STATIC(_cond) _FC_ASSERT_STATIC0 (__LINE__, (_cond))

102
103
104
#define FC_MIN(a,b) ((a) < (b) ? (a) : (b))
#define FC_MAX(a,b) ((a) > (b) ? (a) : (b))

105
/* slim_internal.h */
106
#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(__ELF__) && !defined(__sun)
107
#define FcPrivate		__attribute__((__visibility__("hidden")))
108
109
#define HAVE_GNUC_ATTRIBUTE 1
#include "fcalias.h"
110
111
112
113
114
115
#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
#define FcPrivate		__hidden
#else /* not gcc >= 3.3 and not Sun Studio >= 8 */
#define FcPrivate
#endif

116
117
118
119
120
121
122
123
124
125
126
/* NLS */
#ifdef ENABLE_NLS
#include <libintl.h>
#define _(x)		(dgettext(GETTEXT_PACKAGE, x))
#else
#define dgettext(d, s)	(s)
#define _(x)		(x)
#endif

#define N_(x)	x

127
128
FC_ASSERT_STATIC (sizeof (FcRef) == sizeof (int));

Behdad Esfahbod's avatar
Behdad Esfahbod committed
129
130
131
#define FcStrdup(s) ((FcChar8 *) strdup ((const char *) (s)))
#define FcFree(s) (free ((FcChar8 *) (s)))

132
133
134
135
/*
 * Serialized data structures use only offsets instead of pointers
 * A low bit of 1 indicates an offset.
 */
136

137
138
/* Is the provided pointer actually an offset? */
#define FcIsEncodedOffset(p)	((((intptr_t) (p)) & 1) != 0)
139

140
141
142
143
144
145
146
147
148
149
150
151
152
153
/* Encode offset in a pointer of type t */
#define FcOffsetEncode(o,t)	((t *) ((o) | 1))

/* Decode a pointer into an offset */
#define FcOffsetDecode(p)	(((intptr_t) (p)) & ~1)

/* Compute pointer offset */
#define FcPtrToOffset(b,p)	((intptr_t) (p) - (intptr_t) (b))

/* Given base address, offset and type, return a pointer */
#define FcOffsetToPtr(b,o,t)	((t *) ((intptr_t) (b) + (o)))

/* Given base address, encoded offset and type, return a pointer */
#define FcEncodedOffsetToPtr(b,p,t) FcOffsetToPtr(b,FcOffsetDecode(p),t)
154

155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/* Given base address, pointer and type, return an encoded offset */
#define FcPtrToEncodedOffset(b,p,t) FcOffsetEncode(FcPtrToOffset(b,p),t)

/* Given a structure, offset member and type, return pointer */
#define FcOffsetMember(s,m,t)	    FcOffsetToPtr(s,(s)->m,t)

/* Given a structure, encoded offset member and type, return pointer to member */
#define FcEncodedOffsetMember(s,m,t) FcOffsetToPtr(s,FcOffsetDecode((s)->m), t)

/* Given a structure, member and type, convert the member to a pointer */
#define FcPointerMember(s,m,t)	(FcIsEncodedOffset((s)->m) ? \
				 FcEncodedOffsetMember (s,m,t) : \
				 (s)->m)

/*
 * Serialized values may hold strings, charsets and langsets as pointers,
 * unfortunately FcValue is an exposed type so we can't just always use
 * offsets
 */
#define FcValueString(v)	FcPointerMember(v,u.s,FcChar8)
#define FcValueCharSet(v)	FcPointerMember(v,u.c,const FcCharSet)
#define FcValueLangSet(v)	FcPointerMember(v,u.l,const FcLangSet)
177
#define FcValueRange(v)		FcPointerMember(v,u.r,const FcRange)
178
179
180
181
182
183
184

typedef struct _FcValueList *FcValueListPtr;

typedef struct _FcValueList {
    struct _FcValueList	*next;
    FcValue		value;
    FcValueBinding	binding;
Keith Packard's avatar
Keith Packard committed
185
186
} FcValueList;

187
#define FcValueListNext(vl)	FcPointerMember(vl,next,FcValueList)
188
			
189
typedef int FcObject;
190

191
/* The 1024 is to leave some room for future added internal objects, such
Akira TAGOH's avatar
Akira TAGOH committed
192
193
 * that caches from newer fontconfig can still be used with older fontconfig
 * without getting confused. */
194
195
#define FC_EXT_OBJ_INDEX	1024
#define FC_OBJ_ID(_n_)	((_n_) & (~FC_EXT_OBJ_INDEX))
Akira TAGOH's avatar
Akira TAGOH committed
196

197
typedef struct _FcPatternElt *FcPatternEltPtr;
198

199
/*
200
 * Pattern elts are stuck in a structure connected to the pattern,
201
202
203
 * so they get moved around when the pattern is resized. Hence, the
 * values field must be a pointer/offset instead of just an offset
 */
Keith Packard's avatar
Keith Packard committed
204
typedef struct _FcPatternElt {
205
206
    FcObject		object;
    FcValueList		*values;
Keith Packard's avatar
Keith Packard committed
207
208
} FcPatternElt;

209
210
#define FcPatternEltValues(pe)	FcPointerMember(pe,values,FcValueList)

Keith Packard's avatar
Keith Packard committed
211
212
213
struct _FcPattern {
    int		    num;
    int		    size;
214
    intptr_t	    elts_offset;
215
    FcRef	    ref;
Keith Packard's avatar
Keith Packard committed
216
217
};

218
219
220
#define FcPatternElts(p)	FcOffsetMember(p,elts_offset,FcPatternElt)

#define FcFontSetFonts(fs)	FcPointerMember(fs,fonts,FcPattern *)
221

222
#define FcFontSetFont(fs,i)	(FcIsEncodedOffset((fs)->fonts) ? \
223
				 FcEncodedOffsetToPtr(fs, \
224
225
226
						      FcFontSetFonts(fs)[i], \
						      FcPattern) : \
				 fs->fonts[i])
227
						
Keith Packard's avatar
Keith Packard committed
228
typedef enum _FcOp {
Akira TAGOH's avatar
Akira TAGOH committed
229
    FcOpInteger, FcOpDouble, FcOpString, FcOpMatrix, FcOpRange, FcOpBool, FcOpCharSet, FcOpLangSet,
Keith Packard's avatar
Keith Packard committed
230
231
    FcOpNil,
    FcOpField, FcOpConst,
232
    FcOpAssign, FcOpAssignReplace,
Keith Packard's avatar
Keith Packard committed
233
    FcOpPrependFirst, FcOpPrepend, FcOpAppend, FcOpAppendLast,
234
    FcOpDelete, FcOpDeleteAll,
Keith Packard's avatar
Keith Packard committed
235
    FcOpQuest,
236
    FcOpOr, FcOpAnd, FcOpEqual, FcOpNotEqual,
237
    FcOpContains, FcOpListing, FcOpNotContains,
Keith Packard's avatar
Keith Packard committed
238
239
    FcOpLess, FcOpLessEqual, FcOpMore, FcOpMoreEqual,
    FcOpPlus, FcOpMinus, FcOpTimes, FcOpDivide,
240
241
    FcOpNot, FcOpComma, FcOpFloor, FcOpCeil, FcOpRound, FcOpTrunc,
    FcOpInvalid
Keith Packard's avatar
Keith Packard committed
242
243
} FcOp;

244
typedef enum _FcOpFlags {
245
	FcOpFlagIgnoreBlanks = 1U << 0
246
247
248
249
250
251
} FcOpFlags;

#define FC_OP_GET_OP(_x_)	((_x_) & 0xffff)
#define FC_OP_GET_FLAGS(_x_)	(((_x_) & 0xffff0000) >> 16)
#define FC_OP(_x_,_f_)		(FC_OP_GET_OP (_x_) | ((_f_) << 16))

252
253
254
255
typedef struct _FcExprMatrix {
  struct _FcExpr *xx, *xy, *yx, *yy;
} FcExprMatrix;

256
257
258
259
260
typedef struct _FcExprName {
  FcObject	object;
  FcMatchKind	kind;
} FcExprName;

Behdad Esfahbod's avatar
Behdad Esfahbod committed
261
struct _FcRange {
262
263
264
265
    double begin;
    double end;
};

266

Keith Packard's avatar
Keith Packard committed
267
268
269
typedef struct _FcExpr {
    FcOp   op;
    union {
270
271
272
273
274
275
276
277
278
279
280
	int		ival;
	double		dval;
	const FcChar8	*sval;
	FcExprMatrix	*mexpr;
	FcBool		bval;
	FcCharSet	*cval;
	FcLangSet	*lval;
	FcRange		*rval;

	FcExprName	name;
	const FcChar8	*constant;
Keith Packard's avatar
Keith Packard committed
281
282
283
284
285
286
	struct {
	    struct _FcExpr *left, *right;
	} tree;
    } u;
} FcExpr;

287
288
289
290
291
292
typedef struct _FcExprPage FcExprPage;

struct _FcExprPage {
  FcExprPage *next_page;
  FcExpr *next;
  FcExpr exprs[(1024 - 2/* two pointers */ - 2/* malloc overhead */) * sizeof (void *) / sizeof (FcExpr)];
293
  FcExpr end[FLEXIBLE_ARRAY_MEMBER];
294
295
};

Keith Packard's avatar
Keith Packard committed
296
typedef enum _FcQual {
297
    FcQualAny, FcQualAll, FcQualFirst, FcQualNotFirst
Keith Packard's avatar
Keith Packard committed
298
299
} FcQual;

300
301
#define FcMatchDefault	((FcMatchKind) -1)

Keith Packard's avatar
Keith Packard committed
302
typedef struct _FcTest {
303
    FcMatchKind		kind;
Keith Packard's avatar
Keith Packard committed
304
    FcQual		qual;
305
    FcObject		object;
Keith Packard's avatar
Keith Packard committed
306
307
308
309
310
    FcOp		op;
    FcExpr		*expr;
} FcTest;

typedef struct _FcEdit {
311
    FcObject	    object;
Keith Packard's avatar
Keith Packard committed
312
313
    FcOp	    op;
    FcExpr	    *expr;
314
    FcValueBinding  binding;
Keith Packard's avatar
Keith Packard committed
315
316
} FcEdit;

317
318
319
320
321
322
323
324
325
326
typedef void (* FcDestroyFunc) (void *data);

typedef struct _FcPtrList	FcPtrList;
/* need to sync with FcConfigFileInfoIter at fontconfig.h */
typedef struct _FcPtrListIter {
    void *dummy1;
    void *dummy2;
    void *dummy3;
} FcPtrListIter;

327
328
329
330
331
332
333
334
335
336
337
338
339
typedef enum _FcRuleType {
    FcRuleUnknown, FcRuleTest, FcRuleEdit
} FcRuleType;

typedef struct _FcRule {
    struct _FcRule *next;
    FcRuleType      type;
    union {
	FcTest *test;
	FcEdit *edit;
    } u;
} FcRule;

340
341
342
343
344
345
346
347
typedef struct _FcRuleSet {
    FcRef	ref;
    FcChar8	*name;
    FcChar8	*description;
    FcChar8	*domain;
    FcBool	enabled;
    FcPtrList	*subst[FcMatchKindEnd];
} FcRuleSet;
Keith Packard's avatar
Keith Packard committed
348

349
typedef struct _FcCharLeaf {
Keith Packard's avatar
Keith Packard committed
350
    FcChar32	map[256/32];
351
} FcCharLeaf;
Keith Packard's avatar
Keith Packard committed
352
353

struct _FcCharSet {
354
    FcRef	    ref;	/* reference count */
355
    int		    num;	/* size of leaves and numbers arrays */
356
357
    intptr_t	    leaves_offset;
    intptr_t	    numbers_offset;
Keith Packard's avatar
Keith Packard committed
358
359
};

360
361
362
363
364
365
#define FcCharSetLeaves(c)	FcOffsetMember(c,leaves_offset,intptr_t)
#define FcCharSetLeaf(c,i)	(FcOffsetToPtr(FcCharSetLeaves(c), \
					       FcCharSetLeaves(c)[i], \
					       FcCharLeaf))
#define FcCharSetNumbers(c)	FcOffsetMember(c,numbers_offset,FcChar16)

Patrick Haller's avatar
Patrick Haller committed
366
367
368
369
370
371
372
#define FCSS_DEFAULT            0 /* default behavior */
#define FCSS_ALLOW_DUPLICATES   1 /* allows for duplicate strings in the set */
#define FCSS_GROW_BY_64         2 /* grows buffer by 64 elements instead of 1 */

#define FcStrSetHasControlBit(s,c)  (s->control & c)
#define FcStrSetHasControlBits(s,c) ( (c) == (s->control & (c)) )

373
struct _FcStrSet {
374
    FcRef	    ref;	/* reference count */
375
376
    int		    num;
    int		    size;
377
    FcChar8	    **strs;
Patrick Haller's avatar
Patrick Haller committed
378
    unsigned int    control;    /* control bits for set behavior */
379
380
381
382
383
384
385
};

struct _FcStrList {
    FcStrSet	    *set;
    int		    n;
};

386
typedef struct _FcStrBuf {
Keith Packard's avatar
Keith Packard committed
387
388
389
390
391
    FcChar8 *buf;
    FcBool  allocated;
    FcBool  failed;
    int	    len;
    int	    size;
392
    FcChar8 buf_static[16 * sizeof (void *)];
393
} FcStrBuf;
Keith Packard's avatar
Keith Packard committed
394

Akira TAGOH's avatar
Akira TAGOH committed
395
396
397
398
399
400
401
typedef struct _FcHashTable	FcHashTable;

typedef FcChar32 (* FcHashFunc)	   (const void *data);
typedef int	 (* FcCompareFunc) (const void *v1, const void *v2);
typedef FcBool	 (* FcCopyFunc)	   (const void *src, void **dest);


402
struct _FcCache {
Behdad Esfahbod's avatar
Behdad Esfahbod committed
403
    unsigned int magic;              /* FC_CACHE_MAGIC_MMAP or FC_CACHE_ALLOC */
404
    int		version;	    /* FC_CACHE_VERSION_NUMBER */
405
    intptr_t	size;		    /* size of file */
406
407
408
409
    intptr_t	dir;		    /* offset to dir name */
    intptr_t	dirs;		    /* offset to subdirs */
    int		dirs_count;	    /* number of subdir strings */
    intptr_t	set;		    /* offset to font set */
410
    int		checksum;	    /* checksum of directory state */
Akira TAGOH's avatar
Akira TAGOH committed
411
    int64_t	checksum_nano;	    /* checksum of directory state */
412
};
413

414
415
#undef FcCacheDir
#undef FcCacheSubdir
416
417
418
#define FcCacheDir(c)	FcOffsetMember(c,dir,FcChar8)
#define FcCacheDirs(c)	FcOffsetMember(c,dirs,intptr_t)
#define FcCacheSet(c)	FcOffsetMember(c,set,FcFontSet)
419
420
#define FcCacheSubdir(c,i)  FcOffsetToPtr (FcCacheDirs(c),\
					   FcCacheDirs(c)[i], \
421
					   FcChar8)
422
423
424
425
426
427
428

/*
 * Used while constructing a directory cache object
 */

#define FC_SERIALIZE_HASH_SIZE	8191

Behdad Esfahbod's avatar
Behdad Esfahbod committed
429
430
431
432
433
434
435
436
typedef union _FcAlign {
    double	d;
    int		i;
    intptr_t	ip;
    FcBool	b;
    void	*p;
} FcAlign;

437
438
439
440
441
442
typedef struct _FcSerializeBucket {
    struct _FcSerializeBucket *next;
    const void	*object;
    intptr_t	offset;
} FcSerializeBucket;

443
444
typedef struct _FcCharSetFreezer FcCharSetFreezer;

445
446
typedef struct _FcSerialize {
    intptr_t		size;
447
    FcCharSetFreezer	*cs_freezer;
448
449
450
    void		*linear;
    FcSerializeBucket	*buckets[FC_SERIALIZE_HASH_SIZE];
} FcSerialize;
451

452
453
454
455
456
457
458
459
460
461
/*
 * To map adobe glyph names to unicode values, a precomputed hash
 * table is used
 */

typedef struct _FcGlyphName {
    FcChar32	ucs;		/* unicode value */
    FcChar8	name[1];	/* name extends beyond struct */
} FcGlyphName;

462
463
464
/*
 * To perform case-insensitive string comparisons, a table
 * is used which holds three different kinds of folding data.
465
 *
466
467
468
469
470
471
 * The first is a range of upper case values mapping to a range
 * of their lower case equivalents.  Within each range, the offset
 * between upper and lower case is constant.
 *
 * The second is a range of upper case values which are interleaved
 * with their lower case equivalents.
472
 *
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
 * The third is a set of raw unicode values mapping to a list
 * of unicode values for comparison purposes.  This allows conversion
 * of ß to "ss" so that SS, ss and ß all match.  A separate array
 * holds the list of unicode values for each entry.
 *
 * These are packed into a single table.  Using a binary search,
 * the appropriate entry can be located.
 */

#define FC_CASE_FOLD_RANGE	    0
#define FC_CASE_FOLD_EVEN_ODD	    1
#define FC_CASE_FOLD_FULL	    2

typedef struct _FcCaseFold {
    FcChar32	upper;
    FcChar16	method : 2;
    FcChar16	count : 14;
    short    	offset;	    /* lower - upper for RANGE, table id for FULL */
} FcCaseFold;

493
494
#define FC_MAX_FILE_LEN	    4096

495
496
#define FC_CACHE_MAGIC_MMAP	    0xFC02FC04
#define FC_CACHE_MAGIC_ALLOC	    0xFC02FC05
497

498
499
500
501
502
503
504
struct _FcAtomic {
    FcChar8	*file;		/* original file name */
    FcChar8	*new;		/* temp file name -- write data here */
    FcChar8	*lck;		/* lockfile name (used for locking) */
    FcChar8	*tmp;		/* tmpfile name (used for locking) */
};

Keith Packard's avatar
Keith Packard committed
505
506
507
508
509
510
struct _FcConfig {
    /*
     * File names loaded from the configuration -- saved here as the
     * cache file must be consulted before the directories are scanned,
     * and those directives may occur in any order
     */
511
512
513
    FcStrSet	*configDirs;	    /* directories to scan for fonts */
    /*
     * List of directories containing fonts,
514
     * built by recursively scanning the set
515
516
517
     * of configured directories
     */
    FcStrSet	*fontDirs;
518
519
520
521
    /*
     * List of directories containing cache files.
     */
    FcStrSet	*cacheDirs;
Keith Packard's avatar
Keith Packard committed
522
523
524
525
    /*
     * Names of all of the configuration files used
     * to create this configuration
     */
526
    FcStrSet	*configFiles;	    /* config files loaded */
Keith Packard's avatar
Keith Packard committed
527
528
529
530
    /*
     * Substitution instructions for patterns and fonts;
     * maxObjects is used to allocate appropriate intermediate storage
     * while performing a whole set of substitutions
531
532
533
534
     *
     * 0.. substitutions for patterns
     * 1.. substitutions for fonts
     * 2.. substitutions for scanned fonts
Keith Packard's avatar
Keith Packard committed
535
     */
536
    FcPtrList	*subst[FcMatchKindEnd];
Keith Packard's avatar
Keith Packard committed
537
    int		maxObjects;	    /* maximum number of tests in all substs */
538
539
540
541
542
    /*
     * List of patterns used to control font file selection
     */
    FcStrSet	*acceptGlobs;
    FcStrSet	*rejectGlobs;
543
544
    FcFontSet	*acceptPatterns;
    FcFontSet	*rejectPatterns;
Keith Packard's avatar
Keith Packard committed
545
546
547
548
549
550
551
    /*
     * The set of fonts loaded from the listed directories; the
     * order within the set does not determine the font selection,
     * except in the case of identical matches in which case earlier fonts
     * match preferrentially
     */
    FcFontSet	*fonts[FcSetApplication + 1];
552
553
554
555
556
557
558
559
    /*
     * Fontconfig can periodically rescan the system configuration
     * and font directories.  This rescanning occurs when font
     * listing requests are made, but no more often than rescanInterval
     * seconds apart.
     */
    time_t	rescanTime;	    /* last time information was scanned */
    int		rescanInterval;	    /* interval between scans */
560

561
    FcRef	ref;                /* reference count */
562

563
564
565
    FcExprPage  *expr_pool;	    /* pool of FcExpr's */

    FcChar8     *sysRoot;	    /* override the system root directory */
566
567
    FcStrSet	*availConfigFiles;  /* config files available */
    FcPtrList	*rulesetList;	    /* List of rulesets being installed */
Akira TAGOH's avatar
Akira TAGOH committed
568
    FcHashTable *uuid_table;	    /* UUID table for cachedirs */
Keith Packard's avatar
Keith Packard committed
569
};
570

571
572
573
574
575
typedef struct _FcFileTime {
    time_t  time;
    FcBool  set;
} FcFileTime;

576
577
typedef struct _FcCharMap FcCharMap;

578
579
580
581
582
583
584
typedef struct _FcStatFS    FcStatFS;

struct _FcStatFS {
    FcBool is_remote_fs;
    FcBool is_mtime_broken;
};

585
586
587
588
589
590
591
592
593
594
595
typedef struct _FcValuePromotionBuffer FcValuePromotionBuffer;

struct _FcValuePromotionBuffer {
  union {
    double d;
    int i;
    long l;
    char c[256]; /* Enlarge as needed */
  } u;
};

Keith Packard's avatar
Keith Packard committed
596
597
/* fccache.c */

598
FcPrivate FcCache *
599
600
FcDirCacheScan (const FcChar8 *dir, FcConfig *config);

601
FcPrivate FcCache *
602
FcDirCacheBuild (FcFontSet *set, const FcChar8 *dir, struct stat *dir_stat, FcStrSet *dirs);
603

604
605
606
FcPrivate FcCache *
FcDirCacheRebuild (FcCache *cache, struct stat *dir_stat, FcStrSet *dirs);

607
FcPrivate FcBool
608
FcDirCacheWrite (FcCache *cache, FcConfig *config);
609

610
611
612
FcPrivate FcBool
FcDirCacheCreateTagFile (const FcChar8 *cache_dir);

Keith Packard's avatar
Keith Packard committed
613
614
615
616
617
618
FcPrivate void
FcCacheObjectReference (void *object);

FcPrivate void
FcCacheObjectDereference (void *object);

619
620
621
FcPrivate void *
FcCacheAllocate (FcCache *cache, size_t len);

622
623
FcPrivate void
FcCacheFini (void);
624

625

626
FcPrivate void
627
628
FcDirCacheReference (FcCache *cache, int nref);

Akira TAGOH's avatar
Akira TAGOH committed
629
630
631
632
633
634
635
FcPrivate int
FcDirCacheLock (const FcChar8 *dir,
		FcConfig      *config);

FcPrivate void
FcDirCacheUnlock (int fd);

Keith Packard's avatar
Keith Packard committed
636
637
/* fccfg.c */

638
639
640
641
642
643
FcPrivate FcBool
FcConfigInit (void);

FcPrivate void
FcConfigFini (void);

644
645
646
647
648
649
650
651
652
FcPrivate FcChar8 *
FcConfigXdgCacheHome (void);

FcPrivate FcChar8 *
FcConfigXdgConfigHome (void);

FcPrivate FcChar8 *
FcConfigXdgDataHome (void);

653
654
655
FcPrivate FcExpr *
FcConfigAllocExpr (FcConfig *config);

656
FcPrivate FcBool
657
658
659
FcConfigAddConfigDir (FcConfig	    *config,
		      const FcChar8 *d);

660
FcPrivate FcBool
661
662
663
FcConfigAddFontDir (FcConfig	    *config,
		    const FcChar8   *d);

664
FcPrivate FcBool
665
666
667
FcConfigAddCacheDir (FcConfig	    *config,
		     const FcChar8  *d);

668
FcPrivate FcBool
669
670
FcConfigAddConfigFile (FcConfig		*config,
		       const FcChar8	*f);
Keith Packard's avatar
Keith Packard committed
671

672
FcPrivate FcBool
Keith Packard's avatar
Keith Packard committed
673
674
675
FcConfigAddBlank (FcConfig	*config,
		  FcChar32    	blank);

676
677
678
FcBool
FcConfigAddRule (FcConfig	*config,
		 FcRule		*rule,
Keith Packard's avatar
Keith Packard committed
679
680
		 FcMatchKind	kind);

681
FcPrivate void
Keith Packard's avatar
Keith Packard committed
682
683
684
685
FcConfigSetFonts (FcConfig	*config,
		  FcFontSet	*fonts,
		  FcSetName	set);

686
FcPrivate FcBool
687
FcConfigCompareValue (const FcValue *m,
688
		      unsigned int   op_,
689
		      const FcValue *v);
Keith Packard's avatar
Keith Packard committed
690

691
FcPrivate FcBool
692
693
694
695
FcConfigGlobAdd (FcConfig	*config,
		 const FcChar8	*glob,
		 FcBool		accept);

696
FcPrivate FcBool
697
698
699
FcConfigAcceptFilename (FcConfig	*config,
			const FcChar8	*filename);

700
FcPrivate FcBool
701
702
703
704
FcConfigPatternsAdd (FcConfig	*config,
		     FcPattern	*pattern,
		     FcBool	accept);

705
FcPrivate FcBool
706
707
708
FcConfigAcceptFont (FcConfig	    *config,
		    const FcPattern *font);

709
FcPrivate FcFileTime
710
711
FcConfigModifiedTime (FcConfig *config);

712
FcPrivate FcBool
713
FcConfigAddCache (FcConfig *config, FcCache *cache,
714
		  FcSetName set, FcStrSet *dirSet, FcChar8 *forDir);
715

716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
FcPrivate FcRuleSet *
FcRuleSetCreate (const FcChar8 *name);

FcPrivate void
FcRuleSetDestroy (FcRuleSet *rs);

FcPrivate void
FcRuleSetReference (FcRuleSet *rs);

FcPrivate void
FcRuleSetEnable (FcRuleSet	*rs,
		 FcBool		flag);

FcPrivate void
FcRuleSetAddDescription (FcRuleSet	*rs,
			 const FcChar8	*domain,
			 const FcChar8	*description);

FcPrivate int
FcRuleSetAdd (FcRuleSet		*rs,
	      FcRule		*rule,
	      FcMatchKind	kind);

739
/* fcserialize.c */
740
FcPrivate intptr_t
741
FcAlignSize (intptr_t size);
742

743
FcPrivate FcSerialize *
744
745
FcSerializeCreate (void);

746
FcPrivate void
747
748
FcSerializeDestroy (FcSerialize *serialize);

749
FcPrivate FcBool
750
751
FcSerializeAlloc (FcSerialize *serialize, const void *object, int size);

752
FcPrivate intptr_t
753
754
FcSerializeReserve (FcSerialize *serialize, int size);

755
FcPrivate intptr_t
756
757
FcSerializeOffset (FcSerialize *serialize, const void *object);

758
FcPrivate void *
759
760
FcSerializePtr (FcSerialize *serialize, const void *object);

761
FcPrivate FcBool
762
763
FcLangSetSerializeAlloc (FcSerialize *serialize, const FcLangSet *l);

764
FcPrivate FcLangSet *
765
766
FcLangSetSerialize(FcSerialize *serialize, const FcLangSet *l);

Keith Packard's avatar
Keith Packard committed
767
/* fccharset.c */
768
769
770
FcPrivate FcCharSet *
FcCharSetPromote (FcValuePromotionBuffer *vbuf);

771
FcPrivate void
772
773
FcLangCharSetPopulate (void);

774
FcPrivate FcCharSetFreezer *
775
776
FcCharSetFreezerCreate (void);

777
FcPrivate const FcCharSet *
778
779
FcCharSetFreeze (FcCharSetFreezer *freezer, const FcCharSet *fcs);

780
FcPrivate void
781
FcCharSetFreezerDestroy (FcCharSetFreezer *freezer);
782

783
FcPrivate FcBool
784
FcNameUnparseCharSet (FcStrBuf *buf, const FcCharSet *c);
Keith Packard's avatar
Keith Packard committed
785

786
FcPrivate FcCharSet *
Keith Packard's avatar
Keith Packard committed
787
FcNameParseCharSet (FcChar8 *string);
788

789
790
791
792
793
FcPrivate FcBool
FcNameUnparseValue (FcStrBuf    *buf,
                    FcValue     *v0,
		    FcChar8     *escape);

794
795
796
797
FcPrivate FcBool
FcNameUnparseValueList (FcStrBuf	*buf,
			FcValueListPtr	v,
			FcChar8		*escape);
Keith Packard's avatar
Keith Packard committed
798

799
FcPrivate FcCharLeaf *
800
FcCharSetFindLeafCreate (FcCharSet *fcs, FcChar32 ucs4);
801

802
FcPrivate FcBool
803
FcCharSetSerializeAlloc(FcSerialize *serialize, const FcCharSet *cs);
804

805
FcPrivate FcCharSet *
806
FcCharSetSerialize(FcSerialize *serialize, const FcCharSet *cs);
807

808
FcPrivate FcChar16 *
809
810
FcCharSetGetNumbers(const FcCharSet *c);

Akira TAGOH's avatar
Akira TAGOH committed
811
812
813
814
815
816
817
/* fccompat.c */
FcPrivate int
FcOpen(const char *pathname, int flags, ...);

FcPrivate int
FcMakeTempfile (char *template);

818
819
820
FcPrivate int32_t
FcRandom (void);

821
822
823
FcPrivate FcBool
FcMakeDirectory (const FcChar8 *dir);

824
825
826
827
828
FcPrivate ssize_t
FcReadLink (const FcChar8 *pathname,
	    FcChar8       *buf,
	    size_t         bufsiz);

Keith Packard's avatar
Keith Packard committed
829
/* fcdbg.c */
830
831
832
833

FcPrivate void
FcValuePrintFile (FILE *f, const FcValue v);

834
FcPrivate void
835
836
837
838
839
840
841
FcValuePrintWithPosition (const FcValue v, FcBool show_pos_mark);

FcPrivate void
FcValueListPrintWithPosition (FcValueListPtr l, const FcValueListPtr pos);

FcPrivate void
FcValueListPrint (FcValueListPtr l);
Keith Packard's avatar
Keith Packard committed
842

843
FcPrivate void
844
845
FcLangSetPrint (const FcLangSet *ls);

846
FcPrivate void
Keith Packard's avatar
Keith Packard committed
847
848
FcOpPrint (FcOp op);

849
FcPrivate void
850
FcTestPrint (const FcTest *test);
Keith Packard's avatar
Keith Packard committed
851

852
FcPrivate void
853
FcExprPrint (const FcExpr *expr);
Keith Packard's avatar
Keith Packard committed
854

855
FcPrivate void
856
FcEditPrint (const FcEdit *edit);
Keith Packard's avatar
Keith Packard committed
857

858
FcPrivate void
859
FcRulePrint (const FcRule *rule);
Keith Packard's avatar
Keith Packard committed
860

861
FcPrivate void
862
FcCharSetPrint (const FcCharSet *c);
863

Akira TAGOH's avatar
Akira TAGOH committed
864
865
866
FcPrivate void
FcPatternPrint2 (FcPattern *p1, FcPattern *p2, const FcObjectSet *os);

867
extern FcPrivate int FcDebugVal;
868

869
#define FcDebug() (FcDebugVal)
870

871
FcPrivate void
872
FcInitDebug (void);
Keith Packard's avatar
Keith Packard committed
873

874
/* fcdefault.c */
875
FcPrivate FcChar8 *
876
877
FcGetDefaultLang (void);

Behdad Esfahbod's avatar
Behdad Esfahbod committed
878
879
880
FcPrivate FcChar8 *
FcGetPrgname (void);

881
882
883
FcPrivate void
FcDefaultFini (void);

Keith Packard's avatar
Keith Packard committed
884
885
/* fcdir.c */

886
887
888
FcPrivate FcBool
FcFileIsLink (const FcChar8 *file);

889
890
891
FcPrivate FcBool
FcFileIsFile (const FcChar8 *file);

892
FcPrivate FcBool
893
894
895
896
897
FcFileScanConfig (FcFontSet	*set,
		  FcStrSet	*dirs,
		  const FcChar8 *file,
		  FcConfig	*config);

898
FcPrivate FcBool
899
900
FcDirScanConfig (FcFontSet	*set,
		 FcStrSet	*dirs,
901
		 const FcChar8	*dir,
902
		 FcBool		force,
903
		 FcConfig	*config);
904

Keith Packard's avatar
Keith Packard committed
905
/* fcfont.c */
906
FcPrivate int
Keith Packard's avatar
Keith Packard committed
907
FcFontDebug (void);
908

Keith Packard's avatar
Keith Packard committed
909
/* fcfs.c */
910

911
FcPrivate FcBool
912
FcFontSetSerializeAlloc (FcSerialize *serialize, const FcFontSet *s);
913

914
FcPrivate FcFontSet *
915
FcFontSetSerialize (FcSerialize *serialize, const FcFontSet * s);
Keith Packard's avatar
Keith Packard committed
916

917
918
919
FcPrivate FcFontSet *
FcFontSetDeserialize (const FcFontSet *set);

920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
/* fcplist.c */
FcPrivate FcPtrList *
FcPtrListCreate (FcDestroyFunc func);

FcPrivate void
FcPtrListDestroy (FcPtrList *list);

FcPrivate void
FcPtrListIterInit (const FcPtrList	*list,
		   FcPtrListIter	*iter);

FcPrivate void
FcPtrListIterInitAtLast (FcPtrList	*list,
			 FcPtrListIter	*iter);

FcPrivate FcBool
FcPtrListIterNext (const FcPtrList	*list,
		   FcPtrListIter	*iter);

FcPrivate FcBool
FcPtrListIterIsValid (const FcPtrList		*list,
		      const FcPtrListIter	*iter);

FcPrivate void *
FcPtrListIterGetValue (const FcPtrList		*list,
		       const FcPtrListIter	*iter);

FcPrivate FcBool
FcPtrListIterAdd (FcPtrList	*list,
		  FcPtrListIter	*iter,
		void		*data);

FcPrivate FcBool
FcPtrListIterRemove (FcPtrList		*list,
		     FcPtrListIter	*iter);

956
957
958
959
960
961
962
/* fcinit.c */
FcPrivate FcConfig *
FcInitLoadOwnConfig (FcConfig *config);

FcPrivate FcConfig *
FcInitLoadOwnConfigAndFonts (FcConfig *config);

963
/* fcxml.c */
Akira TAGOH's avatar
Akira TAGOH committed
964
965
966
FcPrivate void
FcConfigPathFini (void);

967
FcPrivate void
Keith Packard's avatar
Keith Packard committed
968
969
FcTestDestroy (FcTest *test);

970
FcPrivate void
Keith Packard's avatar
Keith Packard committed
971
972
FcEditDestroy (FcEdit *e);

973
974
975
void
FcRuleDestroy (FcRule *rule);

976
/* fclang.c */
977
FcPrivate FcLangSet *
978
FcFreeTypeLangSet (const FcCharSet  *charset,
979
		   const FcChar8    *exclusiveLang);
980

981
FcPrivate FcLangResult
982
FcLangCompare (const FcChar8 *s1, const FcChar8 *s2);
983

984
FcPrivate FcLangSet *
985
FcLangSetPromote (const FcChar8 *lang, FcValuePromotionBuffer *buf);
986

987
FcPrivate FcLangSet *
988
989
FcNameParseLangSet (const FcChar8 *string);

990
FcPrivate FcBool
991
992
FcNameUnparseLangSet (FcStrBuf *buf, const FcLangSet *ls);

993
FcPrivate FcChar8 *
994
995
FcNameUnparseEscaped (FcPattern *pat, FcBool escape);

996
997
998
999
1000
1001
1002
1003
1004
FcPrivate FcBool
FcConfigParseOnly (FcConfig		*config,
		   const FcChar8	*name,
		   FcBool		complain);

FcPrivate FcChar8 *
FcConfigRealFilename (FcConfig		*config,
		      const FcChar8	*url);

Keith Packard's avatar
Keith Packard committed
1005
1006
/* fclist.c */

1007
FcPrivate FcBool
1008
1009
1010
FcListPatternMatchAny (const FcPattern *p,
		       const FcPattern *font);

Keith Packard's avatar
Keith Packard committed
1011
1012
1013
1014
/* fcmatch.c */

/* fcname.c */

1015
1016
enum {
  FC_INVALID_OBJECT = 0,
1017
#define FC_OBJECT(NAME, Type, Cmp) FC_##NAME##_OBJECT,
1018
1019
1020
1021
1022
#include "fcobjs.h"
#undef FC_OBJECT
  FC_ONE_AFTER_MAX_BASE_OBJECT
#define FC_MAX_BASE_OBJECT (FC_ONE_AFTER_MAX_BASE_OBJECT - 1)
};
1023

1024
1025
1026
FcPrivate FcBool
FcNameConstantWithObjectCheck (const FcChar8 *string, const char *object, int *result);

1027
FcPrivate FcBool
1028
FcNameBool (const FcChar8 *v, FcBool *result);
1029

1030
FcPrivate FcBool
1031
FcObjectValidType (FcObject object, FcType type);
1032

1033
FcPrivate FcObject
1034
FcObjectFromName (const char * name);
1035

1036
FcPrivate const char *
1037
FcObjectName (FcObject object);
1038

1039
1040
1041
FcPrivate FcObjectSet *
FcObjectGetSet (void);

1042
#define FcObjectCompare(a, b)	((int) a - (int) b)
1043

Keith Packard's avatar
Keith Packard committed
1044
/* fcpat.c */
1045

1046
FcPrivate FcValue
1047
1048
FcValueCanonicalize (const FcValue *v);

1049
1050
1051
FcPrivate FcValueListPtr
FcValueListCreate (void);

1052
FcPrivate void
1053
1054
FcValueListDestroy (FcValueListPtr l);

1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
FcPrivate FcValueListPtr
FcValueListPrepend (FcValueListPtr vallist,
		    FcValue        value,
		    FcValueBinding binding);

FcPrivate FcValueListPtr
FcValueListAppend (FcValueListPtr vallist,
		   FcValue        value,
		   FcValueBinding binding);

FcPrivate FcValueListPtr
FcValueListDuplicate(FcValueListPtr orig);

1068
FcPrivate FcPatternElt *
1069
FcPatternObjectFindElt (const FcPattern *p, FcObject object);
1070

1071
FcPrivate FcPatternElt *
1072
FcPatternObjectInsertElt (FcPattern *p, FcObject object);
Keith Packard's avatar
Keith Packard committed
1073

1074
1075
1076
1077
1078
1079
FcPrivate FcBool
FcPatternObjectListAdd (FcPattern	*p,
			FcObject	object,
			FcValueListPtr	list,
			FcBool		append);

1080
FcPrivate FcBool
1081
1082
1083
1084
1085
FcPatternObjectAddWithBinding  (FcPattern	*p,
				FcObject	object,
				FcValue		value,
				FcValueBinding  binding,
				FcBool		append);
1086

1087
FcPrivate FcBool
1088
FcPatternObjectAdd (FcPattern *p, FcObject object, FcValue value, FcBool append);
1089

1090
FcPrivate FcBool
1091
FcPatternObjectAddWeak (FcPattern *p, FcObject object, FcValue value, FcBool append);
1092

1093
1094
1095
FcPrivate FcResult
FcPatternObjectGetWithBinding (const FcPattern *p, FcObject object, int id, FcValue *v, FcValueBinding *b);

1096
FcPrivate FcResult
1097
FcPatternObjectGet (const FcPattern *p, FcObject object, int id, FcValue *v);
1098

1099
FcPrivate FcBool
1100
FcPatternObjectDel (FcPattern *p, FcObject object);
1101

1102
FcPrivate FcBool