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