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