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