]> git.wh0rd.org - fontconfig.git/blob - src/fcint.h
Rewrite global cache handling code in fontconfig to eliminate per-file
[fontconfig.git] / src / fcint.h
1 /*
2 * $XFree86: xc/lib/fontconfig/src/fcint.h,v 1.16 2002/07/06 23:47:44 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 _FcSymbolic {
45 const char *name;
46 int value;
47 } FcSymbolic;
48
49 #ifndef FC_CONFIG_PATH
50 #define FC_CONFIG_PATH "fonts.conf"
51 #endif
52
53 #define FC_FONT_FILE_INVALID ((FcChar8 *) ".")
54 #define FC_FONT_FILE_DIR ((FcChar8 *) ".dir")
55
56 #define FC_DBG_MATCH 1
57 #define FC_DBG_MATCHV 2
58 #define FC_DBG_EDIT 4
59 #define FC_DBG_FONTSET 8
60 #define FC_DBG_CACHE 16
61 #define FC_DBG_CACHEV 32
62 #define FC_DBG_PARSE 64
63 #define FC_DBG_SCAN 128
64 #define FC_DBG_SCANV 256
65 #define FC_DBG_MEMORY 512
66
67 #define FC_MEM_CHARSET 0
68 #define FC_MEM_CHARNODE 1
69 #define FC_MEM_FONTSET 2
70 #define FC_MEM_FONTPTR 3
71 #define FC_MEM_OBJECTSET 4
72 #define FC_MEM_OBJECTPTR 5
73 #define FC_MEM_MATRIX 6
74 #define FC_MEM_PATTERN 7
75 #define FC_MEM_PATELT 8
76 #define FC_MEM_VALLIST 9
77 #define FC_MEM_SUBSTATE 10
78 #define FC_MEM_STRING 11
79 #define FC_MEM_LISTBUCK 12
80 #define FC_MEM_NUM 13
81 #define FC_MEM_STRSET 14
82 #define FC_MEM_STRLIST 15
83 #define FC_MEM_CONFIG 16
84
85 typedef enum _FcValueBinding {
86 FcValueBindingWeak, FcValueBindingStrong
87 } FcValueBinding;
88
89 typedef struct _FcValueList {
90 struct _FcValueList *next;
91 FcValue value;
92 FcValueBinding binding;
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 FcPatternElt *elts;
104 int ref;
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 typedef enum _FcLangResult {
167 FcLangEqual, FcLangDifferentCountry, FcLangDifferentLang
168 } FcLangResult;
169
170 struct _FcCharSet {
171 int ref; /* reference count */
172 FcBool constant; /* in hash table constant */
173 int num; /* size of leaves and numbers arrays */
174 FcCharLeaf **leaves;
175 FcChar16 *numbers;
176 };
177
178 struct _FcStrSet {
179 int ref; /* reference count */
180 int num;
181 int size;
182 FcChar8 **strs;
183 };
184
185 struct _FcStrList {
186 FcStrSet *set;
187 int n;
188 };
189
190 typedef struct _FcStrBuf {
191 FcChar8 *buf;
192 FcBool allocated;
193 FcBool failed;
194 int len;
195 int size;
196 } FcStrBuf;
197
198 /*
199 * The per-user ~/.fonts.cache file is loaded into
200 * this data structure. Each directory gets a substructure
201 * which is validated by comparing the directory timestamp with
202 * that saved in the cache. When valid, the entire directory cache
203 * can be immediately loaded without reading the directory. Otherwise,
204 * the files are checked individually; updated files are loaded into the
205 * cache which is then rewritten to the users home directory
206 */
207
208 #define FC_GLOBAL_CACHE_DIR_HASH_SIZE 37
209 #define FC_GLOBAL_CACHE_FILE_HASH_SIZE 67
210
211 typedef struct _FcGlobalCacheInfo {
212 unsigned int hash;
213 FcChar8 *file;
214 time_t time;
215 FcBool referenced;
216 } FcGlobalCacheInfo;
217
218 typedef struct _FcGlobalCacheFile {
219 struct _FcGlobalCacheFile *next;
220 FcGlobalCacheInfo info;
221 int id;
222 FcChar8 *name;
223 } FcGlobalCacheFile;
224
225 typedef struct _FcGlobalCacheSubdir {
226 struct _FcGlobalCacheSubdir *next;
227 FcChar8 *file;
228 } FcGlobalCacheSubdir;
229
230 typedef struct _FcGlobalCacheDir {
231 struct _FcGlobalCacheDir *next;
232 FcGlobalCacheInfo info;
233 int len;
234 FcGlobalCacheFile *ents[FC_GLOBAL_CACHE_FILE_HASH_SIZE];
235 FcGlobalCacheSubdir *subdirs;
236 } FcGlobalCacheDir;
237
238 typedef struct _FcGlobalCache {
239 FcGlobalCacheDir *ents[FC_GLOBAL_CACHE_DIR_HASH_SIZE];
240 FcBool updated;
241 FcBool broken;
242 int entries;
243 int referenced;
244 } FcGlobalCache;
245
246 struct _FcAtomic {
247 FcChar8 *file; /* original file name */
248 FcChar8 *new; /* temp file name -- write data here */
249 FcChar8 *lck; /* lockfile name (used for locking) */
250 FcChar8 *tmp; /* tmpfile name (used for locking) */
251 };
252
253 struct _FcBlanks {
254 int nblank;
255 int sblank;
256 FcChar32 *blanks;
257 };
258
259 struct _FcConfig {
260 /*
261 * File names loaded from the configuration -- saved here as the
262 * cache file must be consulted before the directories are scanned,
263 * and those directives may occur in any order
264 */
265 FcStrSet *configDirs; /* directories to scan for fonts */
266 FcChar8 *cache; /* name of per-user cache file */
267 /*
268 * Set of allowed blank chars -- used to
269 * trim fonts of bogus glyphs
270 */
271 FcBlanks *blanks;
272 /*
273 * List of directories containing fonts,
274 * built by recursively scanning the set
275 * of configured directories
276 */
277 FcStrSet *fontDirs;
278 /*
279 * Names of all of the configuration files used
280 * to create this configuration
281 */
282 FcStrSet *configFiles; /* config files loaded */
283 /*
284 * Substitution instructions for patterns and fonts;
285 * maxObjects is used to allocate appropriate intermediate storage
286 * while performing a whole set of substitutions
287 */
288 FcSubst *substPattern; /* substitutions for patterns */
289 FcSubst *substFont; /* substitutions for fonts */
290 int maxObjects; /* maximum number of tests in all substs */
291 /*
292 * The set of fonts loaded from the listed directories; the
293 * order within the set does not determine the font selection,
294 * except in the case of identical matches in which case earlier fonts
295 * match preferrentially
296 */
297 FcFontSet *fonts[FcSetApplication + 1];
298 /*
299 * Fontconfig can periodically rescan the system configuration
300 * and font directories. This rescanning occurs when font
301 * listing requests are made, but no more often than rescanInterval
302 * seconds apart.
303 */
304 time_t rescanTime; /* last time information was scanned */
305 int rescanInterval; /* interval between scans */
306 };
307
308 extern FcConfig *_fcConfig;
309
310 typedef struct _FcCharMap FcCharMap;
311
312 /* fcblanks.c */
313
314 /* fccache.c */
315
316 FcGlobalCache *
317 FcGlobalCacheCreate (void);
318
319 void
320 FcGlobalCacheDestroy (FcGlobalCache *cache);
321
322 FcBool
323 FcGlobalCacheCheckTime (FcGlobalCacheInfo *info);
324
325 void
326 FcGlobalCacheReferenced (FcGlobalCache *cache,
327 FcGlobalCacheInfo *info);
328
329 FcGlobalCacheDir *
330 FcGlobalCacheDirGet (FcGlobalCache *cache,
331 const FcChar8 *dir,
332 int len,
333 FcBool create_missing);
334
335 FcBool
336 FcGlobalCacheScanDir (FcFontSet *set,
337 FcStrSet *dirs,
338 FcGlobalCache *cache,
339 const FcChar8 *dir);
340
341 FcGlobalCacheFile *
342 FcGlobalCacheFileGet (FcGlobalCache *cache,
343 const FcChar8 *file,
344 int id,
345 int *count);
346
347
348 void
349 FcGlobalCacheLoad (FcGlobalCache *cache,
350 const FcChar8 *cache_file);
351
352 FcBool
353 FcGlobalCacheUpdate (FcGlobalCache *cache,
354 const FcChar8 *file,
355 int id,
356 const FcChar8 *name);
357
358 FcBool
359 FcGlobalCacheSave (FcGlobalCache *cache,
360 const FcChar8 *cache_file);
361
362 FcBool
363 FcDirCacheValid (const FcChar8 *cache_file);
364
365 FcBool
366 FcDirCacheReadDir (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir);
367
368 FcBool
369 FcDirCacheWriteDir (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir);
370
371 /* fccfg.c */
372
373 FcBool
374 FcConfigAddConfigDir (FcConfig *config,
375 const FcChar8 *d);
376
377 FcBool
378 FcConfigAddFontDir (FcConfig *config,
379 const FcChar8 *d);
380
381 FcBool
382 FcConfigAddDir (FcConfig *config,
383 const FcChar8 *d);
384
385 FcBool
386 FcConfigAddConfigFile (FcConfig *config,
387 const FcChar8 *f);
388
389 FcBool
390 FcConfigSetCache (FcConfig *config,
391 const FcChar8 *c);
392
393 FcBool
394 FcConfigAddBlank (FcConfig *config,
395 FcChar32 blank);
396
397 FcBool
398 FcConfigAddEdit (FcConfig *config,
399 FcTest *test,
400 FcEdit *edit,
401 FcMatchKind kind);
402
403 void
404 FcConfigSetFonts (FcConfig *config,
405 FcFontSet *fonts,
406 FcSetName set);
407
408 FcBool
409 FcConfigCompareValue (const FcValue m,
410 FcOp op,
411 const FcValue v);
412
413 /* fccharset.c */
414 FcCharSet *
415 FcCharSetFreeze (FcCharSet *cs);
416
417 FcBool
418 FcNameUnparseCharSet (FcStrBuf *buf, const FcCharSet *c);
419
420 FcCharSet *
421 FcNameParseCharSet (FcChar8 *string);
422
423 FcChar32
424 FcFreeTypeUcs4ToPrivate (FcChar32 ucs4, const FcCharMap *map);
425
426 FcChar32
427 FcFreeTypePrivateToUcs4 (FcChar32 private, const FcCharMap *map);
428
429 const FcCharMap *
430 FcFreeTypeGetPrivateMap (FT_Encoding encoding);
431
432 /* fcdbg.c */
433 void
434 FcValueListPrint (FcValueList *l);
435
436 void
437 FcOpPrint (FcOp op);
438
439 void
440 FcTestPrint (FcTest *test);
441
442 void
443 FcExprPrint (FcExpr *expr);
444
445 void
446 FcEditPrint (FcEdit *edit);
447
448 void
449 FcSubstPrint (FcSubst *subst);
450
451 int
452 FcDebug (void);
453
454 /* fcdir.c */
455
456 /* fcfont.c */
457 int
458 FcFontDebug (void);
459
460 /* fcfreetype.c */
461 FcBool
462 FcFreeTypeIsExclusiveLang (const FcChar8 *lang);
463
464 FcBool
465 FcFreeTypeHasLang (FcPattern *pattern, const FcChar8 *lang);
466
467 /* fcfs.c */
468 /* fcgram.y */
469 int
470 FcConfigparse (void);
471
472 int
473 FcConfigwrap (void);
474
475 void
476 FcConfigerror (char *fmt, ...);
477
478 char *
479 FcConfigSaveField (const char *field);
480
481 FcTest *
482 FcTestCreate (FcQual qual, const FcChar8 *field, FcOp compare, FcExpr *expr);
483
484 void
485 FcTestDestroy (FcTest *test);
486
487 FcExpr *
488 FcExprCreateInteger (int i);
489
490 FcExpr *
491 FcExprCreateDouble (double d);
492
493 FcExpr *
494 FcExprCreateString (const FcChar8 *s);
495
496 FcExpr *
497 FcExprCreateMatrix (const FcMatrix *m);
498
499 FcExpr *
500 FcExprCreateBool (FcBool b);
501
502 FcExpr *
503 FcExprCreateNil (void);
504
505 FcExpr *
506 FcExprCreateField (const char *field);
507
508 FcExpr *
509 FcExprCreateConst (const FcChar8 *constant);
510
511 FcExpr *
512 FcExprCreateOp (FcExpr *left, FcOp op, FcExpr *right);
513
514 void
515 FcExprDestroy (FcExpr *e);
516
517 FcEdit *
518 FcEditCreate (const char *field, FcOp op, FcExpr *expr);
519
520 void
521 FcEditDestroy (FcEdit *e);
522
523 /* fcinit.c */
524
525 void
526 FcMemReport (void);
527
528 void
529 FcMemAlloc (int kind, int size);
530
531 void
532 FcMemFree (int kind, int size);
533
534 /* fclang.c */
535 FcBool
536 FcFreeTypeSetLang (FcPattern *pattern,
537 FcCharSet *charset,
538 const FcChar8 *exclusiveLang);
539
540 FcLangResult
541 FcLangCompare (const FcChar8 *s1, const FcChar8 *s2);
542
543 const FcCharSet *
544 FcCharSetForLang (const FcChar8 *lang);
545
546 /* fclist.c */
547
548 /* fcmatch.c */
549
550 /* fcname.c */
551
552 FcBool
553 FcNameBool (FcChar8 *v, FcBool *result);
554
555 /* fcpat.c */
556 void
557 FcValueListDestroy (FcValueList *l);
558
559 FcPatternElt *
560 FcPatternFindElt (const FcPattern *p, const char *object);
561
562 FcPatternElt *
563 FcPatternInsertElt (FcPattern *p, const char *object);
564
565 FcBool
566 FcPatternAddWithBinding (FcPattern *p,
567 const char *object,
568 FcValue value,
569 FcValueBinding binding,
570 FcBool append);
571
572 /* fcrender.c */
573
574 /* fcmatrix.c */
575
576 extern const FcMatrix FcIdentityMatrix;
577
578 void
579 FcMatrixFree (FcMatrix *mat);
580
581 /* fcstr.c */
582 FcChar8 *
583 FcStrPlus (const FcChar8 *s1, const FcChar8 *s2);
584
585 void
586 FcStrFree (FcChar8 *s);
587
588 void
589 FcStrBufInit (FcStrBuf *buf, FcChar8 *init, int size);
590
591 void
592 FcStrBufDestroy (FcStrBuf *buf);
593
594 FcChar8 *
595 FcStrBufDone (FcStrBuf *buf);
596
597 FcBool
598 FcStrBufChar (FcStrBuf *buf, FcChar8 c);
599
600 FcBool
601 FcStrBufString (FcStrBuf *buf, const FcChar8 *s);
602
603 FcBool
604 FcStrBufData (FcStrBuf *buf, const FcChar8 *s, int len);
605
606 int
607 FcStrCmpIgnoreBlanksAndCase (const FcChar8 *s1, const FcChar8 *s2);
608
609 #endif /* _FC_INT_H_ */