]> git.wh0rd.org - fontconfig.git/blob - src/fcint.h
Track dirs containing fonts.cache files referenced from ~/.fonts.cache file
[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, FcValueBindingSame
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 void
348 FcGlobalCacheReferenceSubdir (FcGlobalCache *cache,
349 const FcChar8 *dir);
350
351 FcGlobalCacheDir *
352 FcGlobalCacheDirGet (FcGlobalCache *cache,
353 const FcChar8 *dir,
354 int len,
355 FcBool create_missing);
356
357 FcBool
358 FcGlobalCacheScanDir (FcFontSet *set,
359 FcStrSet *dirs,
360 FcGlobalCache *cache,
361 const FcChar8 *dir);
362
363 FcGlobalCacheFile *
364 FcGlobalCacheFileGet (FcGlobalCache *cache,
365 const FcChar8 *file,
366 int id,
367 int *count);
368
369
370 void
371 FcGlobalCacheLoad (FcGlobalCache *cache,
372 const FcChar8 *cache_file);
373
374 FcBool
375 FcGlobalCacheUpdate (FcGlobalCache *cache,
376 const FcChar8 *file,
377 int id,
378 const FcChar8 *name);
379
380 FcBool
381 FcGlobalCacheSave (FcGlobalCache *cache,
382 const FcChar8 *cache_file);
383
384 FcBool
385 FcDirCacheReadDir (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir);
386
387 FcBool
388 FcDirCacheWriteDir (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir);
389
390 /* fccfg.c */
391
392 FcBool
393 FcConfigAddConfigDir (FcConfig *config,
394 const FcChar8 *d);
395
396 FcBool
397 FcConfigAddFontDir (FcConfig *config,
398 const FcChar8 *d);
399
400 FcBool
401 FcConfigAddDir (FcConfig *config,
402 const FcChar8 *d);
403
404 FcBool
405 FcConfigAddConfigFile (FcConfig *config,
406 const FcChar8 *f);
407
408 FcBool
409 FcConfigSetCache (FcConfig *config,
410 const FcChar8 *c);
411
412 FcBool
413 FcConfigAddBlank (FcConfig *config,
414 FcChar32 blank);
415
416 FcBool
417 FcConfigAddEdit (FcConfig *config,
418 FcTest *test,
419 FcEdit *edit,
420 FcMatchKind kind);
421
422 void
423 FcConfigSetFonts (FcConfig *config,
424 FcFontSet *fonts,
425 FcSetName set);
426
427 FcBool
428 FcConfigCompareValue (const FcValue m,
429 FcOp op,
430 const FcValue v);
431
432 /* fccharset.c */
433 FcCharSet *
434 FcCharSetFreeze (FcCharSet *cs);
435
436 FcBool
437 FcNameUnparseCharSet (FcStrBuf *buf, const FcCharSet *c);
438
439 FcCharSet *
440 FcNameParseCharSet (FcChar8 *string);
441
442 FcCharLeaf *
443 FcCharSetFindLeafCreate (FcCharSet *fcs, FcChar32 ucs4);
444
445 /* fcdbg.c */
446 void
447 FcValueListPrint (const FcValueList *l);
448
449 void
450 FcOpPrint (FcOp op);
451
452 void
453 FcTestPrint (const FcTest *test);
454
455 void
456 FcExprPrint (const FcExpr *expr);
457
458 void
459 FcEditPrint (const FcEdit *edit);
460
461 void
462 FcSubstPrint (const FcSubst *subst);
463
464 int
465 FcDebug (void);
466
467 /* fcdir.c */
468
469 /* fcfont.c */
470 int
471 FcFontDebug (void);
472
473 /* fcfreetype.c */
474 FcBool
475 FcFreeTypeIsExclusiveLang (const FcChar8 *lang);
476
477 FcBool
478 FcFreeTypeHasLang (FcPattern *pattern, const FcChar8 *lang);
479
480 FcChar32
481 FcFreeTypeUcs4ToPrivate (FcChar32 ucs4, const FcCharMap *map);
482
483 FcChar32
484 FcFreeTypePrivateToUcs4 (FcChar32 private, const FcCharMap *map);
485
486 const FcCharMap *
487 FcFreeTypeGetPrivateMap (FT_Encoding encoding);
488
489 /* fcfs.c */
490 /* fcgram.y */
491 int
492 FcConfigparse (void);
493
494 int
495 FcConfigwrap (void);
496
497 void
498 FcConfigerror (char *fmt, ...);
499
500 char *
501 FcConfigSaveField (const char *field);
502
503 FcTest *
504 FcTestCreate (FcMatchKind kind,
505 FcQual qual,
506 const FcChar8 *field,
507 FcOp compare,
508 FcExpr *expr);
509
510 void
511 FcTestDestroy (FcTest *test);
512
513 FcExpr *
514 FcExprCreateInteger (int i);
515
516 FcExpr *
517 FcExprCreateDouble (double d);
518
519 FcExpr *
520 FcExprCreateString (const FcChar8 *s);
521
522 FcExpr *
523 FcExprCreateMatrix (const FcMatrix *m);
524
525 FcExpr *
526 FcExprCreateBool (FcBool b);
527
528 FcExpr *
529 FcExprCreateNil (void);
530
531 FcExpr *
532 FcExprCreateField (const char *field);
533
534 FcExpr *
535 FcExprCreateConst (const FcChar8 *constant);
536
537 FcExpr *
538 FcExprCreateOp (FcExpr *left, FcOp op, FcExpr *right);
539
540 void
541 FcExprDestroy (FcExpr *e);
542
543 FcEdit *
544 FcEditCreate (const char *field, FcOp op, FcExpr *expr, FcValueBinding binding);
545
546 void
547 FcEditDestroy (FcEdit *e);
548
549 /* fcinit.c */
550
551 void
552 FcMemReport (void);
553
554 void
555 FcMemAlloc (int kind, int size);
556
557 void
558 FcMemFree (int kind, int size);
559
560 /* fclang.c */
561 FcLangSet *
562 FcFreeTypeLangSet (const FcCharSet *charset,
563 const FcChar8 *exclusiveLang);
564
565 FcLangResult
566 FcLangCompare (const FcChar8 *s1, const FcChar8 *s2);
567
568 const FcCharSet *
569 FcCharSetForLang (const FcChar8 *lang);
570
571 FcLangSet *
572 FcLangSetPromote (const FcChar8 *lang);
573
574 FcLangSet *
575 FcNameParseLangSet (const FcChar8 *string);
576
577 FcBool
578 FcNameUnparseLangSet (FcStrBuf *buf, const FcLangSet *ls);
579
580 /* fclist.c */
581
582 /* fcmatch.c */
583
584 /* fcname.c */
585
586 FcBool
587 FcNameBool (FcChar8 *v, FcBool *result);
588
589 /* fcpat.c */
590 void
591 FcValueListDestroy (FcValueList *l);
592
593 FcPatternElt *
594 FcPatternFindElt (const FcPattern *p, const char *object);
595
596 FcPatternElt *
597 FcPatternInsertElt (FcPattern *p, const char *object);
598
599 FcBool
600 FcPatternAddWithBinding (FcPattern *p,
601 const char *object,
602 FcValue value,
603 FcValueBinding binding,
604 FcBool append);
605
606 FcPattern *
607 FcPatternFreeze (FcPattern *p);
608
609 /* fcrender.c */
610
611 /* fcmatrix.c */
612
613 extern const FcMatrix FcIdentityMatrix;
614
615 void
616 FcMatrixFree (FcMatrix *mat);
617
618 /* fcstr.c */
619 FcChar8 *
620 FcStrPlus (const FcChar8 *s1, const FcChar8 *s2);
621
622 void
623 FcStrFree (FcChar8 *s);
624
625 void
626 FcStrBufInit (FcStrBuf *buf, FcChar8 *init, int size);
627
628 void
629 FcStrBufDestroy (FcStrBuf *buf);
630
631 FcChar8 *
632 FcStrBufDone (FcStrBuf *buf);
633
634 FcBool
635 FcStrBufChar (FcStrBuf *buf, FcChar8 c);
636
637 FcBool
638 FcStrBufString (FcStrBuf *buf, const FcChar8 *s);
639
640 FcBool
641 FcStrBufData (FcStrBuf *buf, const FcChar8 *s, int len);
642
643 int
644 FcStrCmpIgnoreBlanksAndCase (const FcChar8 *s1, const FcChar8 *s2);
645
646 #endif /* _FC_INT_H_ */