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