]> git.wh0rd.org - fontconfig.git/blob - src/fcint.h
Add ref counting to font config patterns so that FcFontSort return values
[fontconfig.git] / src / fcint.h
1 /*
2 * $XFree86: xc/lib/fontconfig/src/fcint.h,v 1.13 2002/06/03 08:31:15 keithp Exp $
3 *
4 * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
5 *
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.
15 *
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.
23 */
24
25 #ifndef _FCINT_H_
26 #define _FCINT_H_
27
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <ctype.h>
32 #include <errno.h>
33 #include <unistd.h>
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <time.h>
37 #include <fontconfig/fontconfig.h>
38 #include <fontconfig/fcprivate.h>
39 #include <fontconfig/fcfreetype.h>
40 #ifdef HAVE_CONFIG_H
41 #include <config.h>
42 #endif
43
44 typedef struct _FcMatcher {
45 char *object;
46 double (*compare) (char *object, FcValue value1, FcValue value2);
47 int priority;
48 } FcMatcher;
49
50 typedef struct _FcSymbolic {
51 const char *name;
52 int value;
53 } FcSymbolic;
54
55 #ifndef FC_CONFIG_PATH
56 #define FC_CONFIG_PATH "fonts.conf"
57 #endif
58
59 #define FC_FONT_FILE_INVALID ((FcChar8 *) ".")
60 #define FC_FONT_FILE_DIR ((FcChar8 *) ".dir")
61
62 #define FC_DBG_MATCH 1
63 #define FC_DBG_MATCHV 2
64 #define FC_DBG_EDIT 4
65 #define FC_DBG_FONTSET 8
66 #define FC_DBG_CACHE 16
67 #define FC_DBG_CACHEV 32
68 #define FC_DBG_PARSE 64
69 #define FC_DBG_SCAN 128
70 #define FC_DBG_MEMORY 512
71
72 #define FC_MEM_CHARSET 0
73 #define FC_MEM_CHARNODE 1
74 #define FC_MEM_FONTSET 2
75 #define FC_MEM_FONTPTR 3
76 #define FC_MEM_OBJECTSET 4
77 #define FC_MEM_OBJECTPTR 5
78 #define FC_MEM_MATRIX 6
79 #define FC_MEM_PATTERN 7
80 #define FC_MEM_PATELT 8
81 #define FC_MEM_VALLIST 9
82 #define FC_MEM_SUBSTATE 10
83 #define FC_MEM_STRING 11
84 #define FC_MEM_LISTBUCK 12
85 #define FC_MEM_NUM 13
86 #define FC_MEM_STRSET 14
87 #define FC_MEM_STRLIST 15
88 #define FC_MEM_CONFIG 16
89
90 typedef struct _FcValueList {
91 struct _FcValueList *next;
92 FcValue value;
93 } FcValueList;
94
95 typedef struct _FcPatternElt {
96 const char *object;
97 FcValueList *values;
98 } FcPatternElt;
99
100 struct _FcPattern {
101 int num;
102 int size;
103 int ref;
104 FcPatternElt *elts;
105 };
106
107 typedef enum _FcOp {
108 FcOpInteger, FcOpDouble, FcOpString, FcOpMatrix, FcOpBool, FcOpCharSet,
109 FcOpNil,
110 FcOpField, FcOpConst,
111 FcOpAssign, FcOpAssignReplace,
112 FcOpPrependFirst, FcOpPrepend, FcOpAppend, FcOpAppendLast,
113 FcOpQuest,
114 FcOpOr, FcOpAnd, FcOpEqual, FcOpNotEqual, FcOpContains,
115 FcOpLess, FcOpLessEqual, FcOpMore, FcOpMoreEqual,
116 FcOpPlus, FcOpMinus, FcOpTimes, FcOpDivide,
117 FcOpNot, FcOpComma, FcOpInvalid
118 } FcOp;
119
120 typedef struct _FcExpr {
121 FcOp op;
122 union {
123 int ival;
124 double dval;
125 FcChar8 *sval;
126 FcMatrix *mval;
127 FcBool bval;
128 FcCharSet *cval;
129 char *field;
130 FcChar8 *constant;
131 struct {
132 struct _FcExpr *left, *right;
133 } tree;
134 } u;
135 } FcExpr;
136
137 typedef enum _FcQual {
138 FcQualAny, FcQualAll, FcQualFirst, FcQualNotFirst
139 } FcQual;
140
141 typedef struct _FcTest {
142 struct _FcTest *next;
143 FcQual qual;
144 const char *field;
145 FcOp op;
146 FcExpr *expr;
147 } FcTest;
148
149 typedef struct _FcEdit {
150 struct _FcEdit *next;
151 const char *field;
152 FcOp op;
153 FcExpr *expr;
154 } FcEdit;
155
156 typedef struct _FcSubst {
157 struct _FcSubst *next;
158 FcTest *test;
159 FcEdit *edit;
160 } FcSubst;
161
162 typedef struct _FcCharLeaf {
163 FcChar32 map[256/32];
164 } FcCharLeaf;
165
166 struct _FcCharSet {
167 int ref; /* reference count */
168 FcBool constant; /* in hash table constant */
169 int num; /* size of leaves and numbers arrays */
170 FcCharLeaf **leaves;
171 FcChar16 *numbers;
172 };
173
174 struct _FcStrSet {
175 int ref; /* reference count */
176 int num;
177 int size;
178 FcChar8 **strs;
179 };
180
181 struct _FcStrList {
182 FcStrSet *set;
183 int n;
184 };
185
186 typedef struct _FcStrBuf {
187 FcChar8 *buf;
188 FcBool allocated;
189 FcBool failed;
190 int len;
191 int size;
192 } FcStrBuf;
193
194 typedef struct _FcFileCacheEnt {
195 struct _FcFileCacheEnt *next;
196 unsigned int hash;
197 FcChar8 *file;
198 int id;
199 time_t time;
200 FcChar8 *name;
201 FcBool referenced;
202 } FcFileCacheEnt;
203
204 #define FC_FILE_CACHE_HASH_SIZE 509
205
206 struct _FcFileCache {
207 FcFileCacheEnt *ents[FC_FILE_CACHE_HASH_SIZE];
208 FcBool updated;
209 int entries;
210 int referenced;
211 };
212
213 struct _FcAtomic {
214 FcChar8 *file; /* original file name */
215 FcChar8 *new; /* temp file name -- write data here */
216 FcChar8 *lck; /* lockfile name (used for locking) */
217 FcChar8 *tmp; /* tmpfile name (used for locking) */
218 };
219
220 struct _FcBlanks {
221 int nblank;
222 int sblank;
223 FcChar32 *blanks;
224 };
225
226 struct _FcConfig {
227 /*
228 * File names loaded from the configuration -- saved here as the
229 * cache file must be consulted before the directories are scanned,
230 * and those directives may occur in any order
231 */
232 FcStrSet *configDirs; /* directories to scan for fonts */
233 FcChar8 *cache; /* name of per-user cache file */
234 /*
235 * Set of allowed blank chars -- used to
236 * trim fonts of bogus glyphs
237 */
238 FcBlanks *blanks;
239 /*
240 * List of directories containing fonts,
241 * built by recursively scanning the set
242 * of configured directories
243 */
244 FcStrSet *fontDirs;
245 /*
246 * Names of all of the configuration files used
247 * to create this configuration
248 */
249 FcStrSet *configFiles; /* config files loaded */
250 /*
251 * Substitution instructions for patterns and fonts;
252 * maxObjects is used to allocate appropriate intermediate storage
253 * while performing a whole set of substitutions
254 */
255 FcSubst *substPattern; /* substitutions for patterns */
256 FcSubst *substFont; /* substitutions for fonts */
257 int maxObjects; /* maximum number of tests in all substs */
258 /*
259 * The set of fonts loaded from the listed directories; the
260 * order within the set does not determine the font selection,
261 * except in the case of identical matches in which case earlier fonts
262 * match preferrentially
263 */
264 FcFontSet *fonts[FcSetApplication + 1];
265 /*
266 * Fontconfig can periodically rescan the system configuration
267 * and font directories. This rescanning occurs when font
268 * listing requests are made, but no more often than rescanInterval
269 * seconds apart.
270 */
271 time_t rescanTime; /* last time information was scanned */
272 int rescanInterval; /* interval between scans */
273 };
274
275 extern FcConfig *_fcConfig;
276
277 /* fcblanks.c */
278
279 /* fccache.c */
280
281 FcFileCache *
282 FcFileCacheCreate (void);
283
284 FcChar8 *
285 FcFileCacheFind (FcFileCache *cache,
286 const FcChar8 *file,
287 int id,
288 int *count);
289
290 void
291 FcFileCacheDestroy (FcFileCache *cache);
292
293 FcBool
294 FcFileCacheValid (const FcChar8 *cache_file);
295
296 void
297 FcFileCacheLoad (FcFileCache *cache,
298 const FcChar8 *cache_file);
299
300 FcBool
301 FcFileCacheUpdate (FcFileCache *cache,
302 const FcChar8 *file,
303 int id,
304 const FcChar8 *name);
305
306 FcBool
307 FcFileCacheSave (FcFileCache *cache,
308 const FcChar8 *cache_file);
309
310 FcBool
311 FcFileCacheReadDir (FcFontSet *set, FcStrSet *dirs, const FcChar8 *cache_file);
312
313 FcBool
314 FcFileCacheWriteDir (FcFontSet *set, FcStrSet *dirs, const FcChar8 *cache_file);
315
316 /* fccfg.c */
317
318 FcBool
319 FcConfigAddConfigDir (FcConfig *config,
320 const FcChar8 *d);
321
322 FcBool
323 FcConfigAddFontDir (FcConfig *config,
324 const FcChar8 *d);
325
326 FcBool
327 FcConfigAddDir (FcConfig *config,
328 const FcChar8 *d);
329
330 FcBool
331 FcConfigAddConfigFile (FcConfig *config,
332 const FcChar8 *f);
333
334 FcBool
335 FcConfigSetCache (FcConfig *config,
336 const FcChar8 *c);
337
338 FcBool
339 FcConfigAddBlank (FcConfig *config,
340 FcChar32 blank);
341
342 FcBool
343 FcConfigAddEdit (FcConfig *config,
344 FcTest *test,
345 FcEdit *edit,
346 FcMatchKind kind);
347
348 void
349 FcConfigSetFonts (FcConfig *config,
350 FcFontSet *fonts,
351 FcSetName set);
352
353 FcBool
354 FcConfigCompareValue (const FcValue m,
355 FcOp op,
356 const FcValue v);
357
358 /* fccharset.c */
359 FcBool
360 FcNameUnparseCharSet (FcStrBuf *buf, const FcCharSet *c);
361
362 FcCharSet *
363 FcNameParseCharSet (FcChar8 *string);
364
365 /* fcdbg.c */
366 void
367 FcValueListPrint (FcValueList *l);
368
369 void
370 FcOpPrint (FcOp op);
371
372 void
373 FcTestPrint (FcTest *test);
374
375 void
376 FcExprPrint (FcExpr *expr);
377
378 void
379 FcEditPrint (FcEdit *edit);
380
381 void
382 FcSubstPrint (FcSubst *subst);
383
384 int
385 FcDebug (void);
386
387 /* fcdir.c */
388
389 /* fcfont.c */
390 int
391 FcFontDebug (void);
392
393 /* fcfs.c */
394 /* fcgram.y */
395 int
396 FcConfigparse (void);
397
398 int
399 FcConfigwrap (void);
400
401 void
402 FcConfigerror (char *fmt, ...);
403
404 char *
405 FcConfigSaveField (const char *field);
406
407 FcTest *
408 FcTestCreate (FcQual qual, const FcChar8 *field, FcOp compare, FcExpr *expr);
409
410 void
411 FcTestDestroy (FcTest *test);
412
413 FcExpr *
414 FcExprCreateInteger (int i);
415
416 FcExpr *
417 FcExprCreateDouble (double d);
418
419 FcExpr *
420 FcExprCreateString (const FcChar8 *s);
421
422 FcExpr *
423 FcExprCreateMatrix (const FcMatrix *m);
424
425 FcExpr *
426 FcExprCreateBool (FcBool b);
427
428 FcExpr *
429 FcExprCreateNil (void);
430
431 FcExpr *
432 FcExprCreateField (const char *field);
433
434 FcExpr *
435 FcExprCreateConst (const FcChar8 *constant);
436
437 FcExpr *
438 FcExprCreateOp (FcExpr *left, FcOp op, FcExpr *right);
439
440 void
441 FcExprDestroy (FcExpr *e);
442
443 FcEdit *
444 FcEditCreate (const char *field, FcOp op, FcExpr *expr);
445
446 void
447 FcEditDestroy (FcEdit *e);
448
449 /* fcinit.c */
450
451 void
452 FcMemReport (void);
453
454 void
455 FcMemAlloc (int kind, int size);
456
457 void
458 FcMemFree (int kind, int size);
459
460 /* fclist.c */
461
462 /* fcmatch.c */
463
464 /* fcname.c */
465
466 FcBool
467 FcNameBool (FcChar8 *v, FcBool *result);
468
469 /* fcpat.c */
470 void
471 FcValueListDestroy (FcValueList *l);
472
473 FcPatternElt *
474 FcPatternFindElt (const FcPattern *p, const char *object);
475
476 FcPatternElt *
477 FcPatternInsertElt (FcPattern *p, const char *object);
478
479 /* fcrender.c */
480
481 /* fcmatrix.c */
482 void
483 FcMatrixFree (FcMatrix *mat);
484
485 /* fcstr.c */
486 FcChar8 *
487 FcStrPlus (const FcChar8 *s1, const FcChar8 *s2);
488
489 void
490 FcStrFree (FcChar8 *s);
491
492 void
493 FcStrBufInit (FcStrBuf *buf, FcChar8 *init, int size);
494
495 void
496 FcStrBufDestroy (FcStrBuf *buf);
497
498 FcChar8 *
499 FcStrBufDone (FcStrBuf *buf);
500
501 FcBool
502 FcStrBufChar (FcStrBuf *buf, FcChar8 c);
503
504 FcBool
505 FcStrBufString (FcStrBuf *buf, const FcChar8 *s);
506
507 FcBool
508 FcStrBufData (FcStrBuf *buf, const FcChar8 *s, int len);
509
510 #endif /* _FC_INT_H_ */