]> git.wh0rd.org - fontconfig.git/blob - src/fcint.h
Was losing local cached dirs in global cache list
[fontconfig.git] / src / fcint.h
1 /*
2 * $XFree86: xc/lib/fontconfig/src/fcint.h,v 1.27 2002/08/31 22:17:32 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_CHARLEAF 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_STRSET 13
81 #define FC_MEM_STRLIST 14
82 #define FC_MEM_CONFIG 15
83 #define FC_MEM_LANGSET 16
84 #define FC_MEM_ATOMIC 17
85 #define FC_MEM_BLANKS 18
86 #define FC_MEM_CACHE 19
87 #define FC_MEM_STRBUF 20
88 #define FC_MEM_SUBST 21
89 #define FC_MEM_OBJECTTYPE 22
90 #define FC_MEM_CONSTANT 23
91 #define FC_MEM_TEST 24
92 #define FC_MEM_EXPR 25
93 #define FC_MEM_VSTACK 26
94 #define FC_MEM_ATTR 27
95 #define FC_MEM_PSTACK 28
96
97 #define FC_MEM_NUM 29
98
99 typedef enum _FcValueBinding {
100 FcValueBindingWeak, FcValueBindingStrong
101 } FcValueBinding;
102
103 typedef struct _FcValueList {
104 struct _FcValueList *next;
105 FcValue value;
106 FcValueBinding binding;
107 } FcValueList;
108
109 typedef struct _FcPatternElt {
110 const char *object;
111 FcValueList *values;
112 } FcPatternElt;
113
114
115 struct _FcPattern {
116 int num;
117 int size;
118 FcPatternElt *elts;
119 int ref;
120 };
121
122 typedef enum _FcOp {
123 FcOpInteger, FcOpDouble, FcOpString, FcOpMatrix, FcOpBool, FcOpCharSet,
124 FcOpNil,
125 FcOpField, FcOpConst,
126 FcOpAssign, FcOpAssignReplace,
127 FcOpPrependFirst, FcOpPrepend, FcOpAppend, FcOpAppendLast,
128 FcOpQuest,
129 FcOpOr, FcOpAnd, FcOpEqual, FcOpNotEqual, FcOpContains, FcOpNotContains,
130 FcOpLess, FcOpLessEqual, FcOpMore, FcOpMoreEqual,
131 FcOpPlus, FcOpMinus, FcOpTimes, FcOpDivide,
132 FcOpNot, FcOpComma, FcOpInvalid
133 } FcOp;
134
135 typedef struct _FcExpr {
136 FcOp op;
137 union {
138 int ival;
139 double dval;
140 FcChar8 *sval;
141 FcMatrix *mval;
142 FcBool bval;
143 FcCharSet *cval;
144 char *field;
145 FcChar8 *constant;
146 struct {
147 struct _FcExpr *left, *right;
148 } tree;
149 } u;
150 } FcExpr;
151
152 typedef enum _FcQual {
153 FcQualAny, FcQualAll, FcQualFirst, FcQualNotFirst
154 } FcQual;
155
156 #define FcMatchDefault ((FcMatchKind) -1)
157
158 typedef struct _FcTest {
159 struct _FcTest *next;
160 FcMatchKind kind;
161 FcQual qual;
162 const char *field;
163 FcOp op;
164 FcExpr *expr;
165 } FcTest;
166
167 typedef struct _FcEdit {
168 struct _FcEdit *next;
169 const char *field;
170 FcOp op;
171 FcExpr *expr;
172 FcValueBinding binding;
173 } FcEdit;
174
175 typedef struct _FcSubst {
176 struct _FcSubst *next;
177 FcTest *test;
178 FcEdit *edit;
179 } FcSubst;
180
181 typedef struct _FcCharLeaf {
182 FcChar32 map[256/32];
183 } FcCharLeaf;
184
185 #define FC_REF_CONSTANT -1
186
187 struct _FcCharSet {
188 int ref; /* reference count */
189 int num; /* size of leaves and numbers arrays */
190 FcCharLeaf **leaves;
191 FcChar16 *numbers;
192 };
193
194 struct _FcStrSet {
195 int ref; /* reference count */
196 int num;
197 int size;
198 FcChar8 **strs;
199 };
200
201 struct _FcStrList {
202 FcStrSet *set;
203 int n;
204 };
205
206 typedef struct _FcStrBuf {
207 FcChar8 *buf;
208 FcBool allocated;
209 FcBool failed;
210 int len;
211 int size;
212 } FcStrBuf;
213
214 /*
215 * The per-user ~/.fonts.cache-<version> file is loaded into
216 * this data structure. Each directory gets a substructure
217 * which is validated by comparing the directory timestamp with
218 * that saved in the cache. When valid, the entire directory cache
219 * can be immediately loaded without reading the directory. Otherwise,
220 * the files are checked individually; updated files are loaded into the
221 * cache which is then rewritten to the users home directory
222 */
223
224 #define FC_GLOBAL_CACHE_DIR_HASH_SIZE 37
225 #define FC_GLOBAL_CACHE_FILE_HASH_SIZE 67
226
227 typedef struct _FcGlobalCacheInfo {
228 unsigned int hash;
229 FcChar8 *file;
230 time_t time;
231 FcBool referenced;
232 } FcGlobalCacheInfo;
233
234 typedef struct _FcGlobalCacheFile {
235 struct _FcGlobalCacheFile *next;
236 FcGlobalCacheInfo info;
237 int id;
238 FcChar8 *name;
239 } FcGlobalCacheFile;
240
241 typedef struct _FcGlobalCacheDir FcGlobalCacheDir;
242
243 typedef struct _FcGlobalCacheSubdir {
244 struct _FcGlobalCacheSubdir *next;
245 FcGlobalCacheDir *ent;
246 } FcGlobalCacheSubdir;
247
248 struct _FcGlobalCacheDir {
249 struct _FcGlobalCacheDir *next;
250 FcGlobalCacheInfo info;
251 int len;
252 FcGlobalCacheFile *ents[FC_GLOBAL_CACHE_FILE_HASH_SIZE];
253 FcGlobalCacheSubdir *subdirs;
254 };
255
256 typedef struct _FcGlobalCache {
257 FcGlobalCacheDir *ents[FC_GLOBAL_CACHE_DIR_HASH_SIZE];
258 FcBool updated;
259 FcBool broken;
260 int entries;
261 int referenced;
262 } FcGlobalCache;
263
264 struct _FcAtomic {
265 FcChar8 *file; /* original file name */
266 FcChar8 *new; /* temp file name -- write data here */
267 FcChar8 *lck; /* lockfile name (used for locking) */
268 FcChar8 *tmp; /* tmpfile name (used for locking) */
269 };
270
271 struct _FcBlanks {
272 int nblank;
273 int sblank;
274 FcChar32 *blanks;
275 };
276
277 struct _FcConfig {
278 /*
279 * File names loaded from the configuration -- saved here as the
280 * cache file must be consulted before the directories are scanned,
281 * and those directives may occur in any order
282 */
283 FcStrSet *configDirs; /* directories to scan for fonts */
284 FcChar8 *cache; /* name of per-user cache file */
285 /*
286 * Set of allowed blank chars -- used to
287 * trim fonts of bogus glyphs
288 */
289 FcBlanks *blanks;
290 /*
291 * List of directories containing fonts,
292 * built by recursively scanning the set
293 * of configured directories
294 */
295 FcStrSet *fontDirs;
296 /*
297 * Names of all of the configuration files used
298 * to create this configuration
299 */
300 FcStrSet *configFiles; /* config files loaded */
301 /*
302 * Substitution instructions for patterns and fonts;
303 * maxObjects is used to allocate appropriate intermediate storage
304 * while performing a whole set of substitutions
305 */
306 FcSubst *substPattern; /* substitutions for patterns */
307 FcSubst *substFont; /* substitutions for fonts */
308 int maxObjects; /* maximum number of tests in all substs */
309 /*
310 * The set of fonts loaded from the listed directories; the
311 * order within the set does not determine the font selection,
312 * except in the case of identical matches in which case earlier fonts
313 * match preferrentially
314 */
315 FcFontSet *fonts[FcSetApplication + 1];
316 /*
317 * Fontconfig can periodically rescan the system configuration
318 * and font directories. This rescanning occurs when font
319 * listing requests are made, but no more often than rescanInterval
320 * seconds apart.
321 */
322 time_t rescanTime; /* last time information was scanned */
323 int rescanInterval; /* interval between scans */
324 };
325
326 extern FcConfig *_fcConfig;
327
328 typedef struct _FcCharMap FcCharMap;
329
330 /* fcblanks.c */
331
332 /* fccache.c */
333
334 FcGlobalCache *
335 FcGlobalCacheCreate (void);
336
337 void
338 FcGlobalCacheDestroy (FcGlobalCache *cache);
339
340 FcBool
341 FcGlobalCacheCheckTime (FcGlobalCacheInfo *info);
342
343 void
344 FcGlobalCacheReferenced (FcGlobalCache *cache,
345 FcGlobalCacheInfo *info);
346
347 FcGlobalCacheDir *
348 FcGlobalCacheDirGet (FcGlobalCache *cache,
349 const FcChar8 *dir,
350 int len,
351 FcBool create_missing);
352
353 FcBool
354 FcGlobalCacheScanDir (FcFontSet *set,
355 FcStrSet *dirs,
356 FcGlobalCache *cache,
357 const FcChar8 *dir);
358
359 FcGlobalCacheFile *
360 FcGlobalCacheFileGet (FcGlobalCache *cache,
361 const FcChar8 *file,
362 int id,
363 int *count);
364
365
366 void
367 FcGlobalCacheLoad (FcGlobalCache *cache,
368 const FcChar8 *cache_file);
369
370 FcBool
371 FcGlobalCacheUpdate (FcGlobalCache *cache,
372 const FcChar8 *file,
373 int id,
374 const FcChar8 *name);
375
376 FcBool
377 FcGlobalCacheSave (FcGlobalCache *cache,
378 const FcChar8 *cache_file);
379
380 FcBool
381 FcDirCacheReadDir (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir);
382
383 FcBool
384 FcDirCacheWriteDir (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir);
385
386 /* fccfg.c */
387
388 FcBool
389 FcConfigAddConfigDir (FcConfig *config,
390 const FcChar8 *d);
391
392 FcBool
393 FcConfigAddFontDir (FcConfig *config,
394 const FcChar8 *d);
395
396 FcBool
397 FcConfigAddDir (FcConfig *config,
398 const FcChar8 *d);
399
400 FcBool
401 FcConfigAddConfigFile (FcConfig *config,
402 const FcChar8 *f);
403
404 FcBool
405 FcConfigSetCache (FcConfig *config,
406 const FcChar8 *c);
407
408 FcBool
409 FcConfigAddBlank (FcConfig *config,
410 FcChar32 blank);
411
412 FcBool
413 FcConfigAddEdit (FcConfig *config,
414 FcTest *test,
415 FcEdit *edit,
416 FcMatchKind kind);
417
418 void
419 FcConfigSetFonts (FcConfig *config,
420 FcFontSet *fonts,
421 FcSetName set);
422
423 FcBool
424 FcConfigCompareValue (const FcValue m,
425 FcOp op,
426 const FcValue v);
427
428 /* fccharset.c */
429 FcCharSet *
430 FcCharSetFreeze (FcCharSet *cs);
431
432 FcBool
433 FcNameUnparseCharSet (FcStrBuf *buf, const FcCharSet *c);
434
435 FcCharSet *
436 FcNameParseCharSet (FcChar8 *string);
437
438 FcChar32
439 FcFreeTypeUcs4ToPrivate (FcChar32 ucs4, const FcCharMap *map);
440
441 FcChar32
442 FcFreeTypePrivateToUcs4 (FcChar32 private, const FcCharMap *map);
443
444 const FcCharMap *
445 FcFreeTypeGetPrivateMap (FT_Encoding encoding);
446
447 /* fcdbg.c */
448 void
449 FcValueListPrint (const FcValueList *l);
450
451 void
452 FcOpPrint (FcOp op);
453
454 void
455 FcTestPrint (const FcTest *test);
456
457 void
458 FcExprPrint (const FcExpr *expr);
459
460 void
461 FcEditPrint (const FcEdit *edit);
462
463 void
464 FcSubstPrint (const FcSubst *subst);
465
466 int
467 FcDebug (void);
468
469 /* fcdir.c */
470
471 /* fcfont.c */
472 int
473 FcFontDebug (void);
474
475 /* fcfreetype.c */
476 FcBool
477 FcFreeTypeIsExclusiveLang (const FcChar8 *lang);
478
479 FcBool
480 FcFreeTypeHasLang (FcPattern *pattern, const FcChar8 *lang);
481
482 /* fcfs.c */
483 /* fcgram.y */
484 int
485 FcConfigparse (void);
486
487 int
488 FcConfigwrap (void);
489
490 void
491 FcConfigerror (char *fmt, ...);
492
493 char *
494 FcConfigSaveField (const char *field);
495
496 FcTest *
497 FcTestCreate (FcMatchKind kind,
498 FcQual qual,
499 const FcChar8 *field,
500 FcOp compare,
501 FcExpr *expr);
502
503 void
504 FcTestDestroy (FcTest *test);
505
506 FcExpr *
507 FcExprCreateInteger (int i);
508
509 FcExpr *
510 FcExprCreateDouble (double d);
511
512 FcExpr *
513 FcExprCreateString (const FcChar8 *s);
514
515 FcExpr *
516 FcExprCreateMatrix (const FcMatrix *m);
517
518 FcExpr *
519 FcExprCreateBool (FcBool b);
520
521 FcExpr *
522 FcExprCreateNil (void);
523
524 FcExpr *
525 FcExprCreateField (const char *field);
526
527 FcExpr *
528 FcExprCreateConst (const FcChar8 *constant);
529
530 FcExpr *
531 FcExprCreateOp (FcExpr *left, FcOp op, FcExpr *right);
532
533 void
534 FcExprDestroy (FcExpr *e);
535
536 FcEdit *
537 FcEditCreate (const char *field, FcOp op, FcExpr *expr, FcValueBinding binding);
538
539 void
540 FcEditDestroy (FcEdit *e);
541
542 /* fcinit.c */
543
544 void
545 FcMemReport (void);
546
547 void
548 FcMemAlloc (int kind, int size);
549
550 void
551 FcMemFree (int kind, int size);
552
553 /* fclang.c */
554 FcLangSet *
555 FcFreeTypeLangSet (const FcCharSet *charset,
556 const FcChar8 *exclusiveLang);
557
558 FcLangResult
559 FcLangCompare (const FcChar8 *s1, const FcChar8 *s2);
560
561 const FcCharSet *
562 FcCharSetForLang (const FcChar8 *lang);
563
564 FcLangSet *
565 FcLangSetPromote (const FcChar8 *lang);
566
567 FcLangSet *
568 FcNameParseLangSet (const FcChar8 *string);
569
570 FcBool
571 FcNameUnparseLangSet (FcStrBuf *buf, const FcLangSet *ls);
572
573 /* fclist.c */
574
575 /* fcmatch.c */
576
577 /* fcname.c */
578
579 FcBool
580 FcNameBool (FcChar8 *v, FcBool *result);
581
582 /* fcpat.c */
583 void
584 FcValueListDestroy (FcValueList *l);
585
586 FcPatternElt *
587 FcPatternFindElt (const FcPattern *p, const char *object);
588
589 FcPatternElt *
590 FcPatternInsertElt (FcPattern *p, const char *object);
591
592 FcBool
593 FcPatternAddWithBinding (FcPattern *p,
594 const char *object,
595 FcValue value,
596 FcValueBinding binding,
597 FcBool append);
598
599 FcPattern *
600 FcPatternFreeze (FcPattern *p);
601
602 /* fcrender.c */
603
604 /* fcmatrix.c */
605
606 extern const FcMatrix FcIdentityMatrix;
607
608 void
609 FcMatrixFree (FcMatrix *mat);
610
611 /* fcstr.c */
612 FcChar8 *
613 FcStrPlus (const FcChar8 *s1, const FcChar8 *s2);
614
615 void
616 FcStrFree (FcChar8 *s);
617
618 void
619 FcStrBufInit (FcStrBuf *buf, FcChar8 *init, int size);
620
621 void
622 FcStrBufDestroy (FcStrBuf *buf);
623
624 FcChar8 *
625 FcStrBufDone (FcStrBuf *buf);
626
627 FcBool
628 FcStrBufChar (FcStrBuf *buf, FcChar8 c);
629
630 FcBool
631 FcStrBufString (FcStrBuf *buf, const FcChar8 *s);
632
633 FcBool
634 FcStrBufData (FcStrBuf *buf, const FcChar8 *s, int len);
635
636 int
637 FcStrCmpIgnoreBlanksAndCase (const FcChar8 *s1, const FcChar8 *s2);
638
639 #endif /* _FC_INT_H_ */