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