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