]> git.wh0rd.org - fontconfig.git/blob - src/fcint.h
cf86ad417a2ab07e24e65e563defe4d4f3e11f22
[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 FcFontSet *acceptPatterns;
333 FcFontSet *rejectPatterns;
334 /*
335 * The set of fonts loaded from the listed directories; the
336 * order within the set does not determine the font selection,
337 * except in the case of identical matches in which case earlier fonts
338 * match preferrentially
339 */
340 FcFontSet *fonts[FcSetApplication + 1];
341 /*
342 * Fontconfig can periodically rescan the system configuration
343 * and font directories. This rescanning occurs when font
344 * listing requests are made, but no more often than rescanInterval
345 * seconds apart.
346 */
347 time_t rescanTime; /* last time information was scanned */
348 int rescanInterval; /* interval between scans */
349 };
350
351 extern FcConfig *_fcConfig;
352
353 typedef struct _FcCharMap FcCharMap;
354
355 /* fcblanks.c */
356
357 /* fccache.c */
358
359 FcGlobalCache *
360 FcGlobalCacheCreate (void);
361
362 void
363 FcGlobalCacheDestroy (FcGlobalCache *cache);
364
365 FcBool
366 FcGlobalCacheCheckTime (const FcChar8*file, FcGlobalCacheInfo *info);
367
368 void
369 FcGlobalCacheReferenced (FcGlobalCache *cache,
370 FcGlobalCacheInfo *info);
371
372 void
373 FcGlobalCacheReferenceSubdir (FcGlobalCache *cache,
374 const FcChar8 *dir);
375
376 FcGlobalCacheDir *
377 FcGlobalCacheDirGet (FcGlobalCache *cache,
378 const FcChar8 *dir,
379 int len,
380 FcBool create_missing);
381
382 FcBool
383 FcGlobalCacheScanDir (FcFontSet *set,
384 FcStrSet *dirs,
385 FcGlobalCache *cache,
386 const FcChar8 *dir,
387 FcConfig *config);
388
389 FcGlobalCacheFile *
390 FcGlobalCacheFileGet (FcGlobalCache *cache,
391 const FcChar8 *file,
392 int id,
393 int *count);
394
395
396 void
397 FcGlobalCacheLoad (FcGlobalCache *cache,
398 const FcChar8 *cache_file);
399
400 FcBool
401 FcGlobalCacheUpdate (FcGlobalCache *cache,
402 const FcChar8 *file,
403 int id,
404 const FcChar8 *name);
405
406 FcBool
407 FcGlobalCacheSave (FcGlobalCache *cache,
408 const FcChar8 *cache_file);
409
410 FcBool
411 FcDirCacheReadDir (FcFontSet *set,
412 FcStrSet *dirs,
413 const FcChar8 *dir,
414 FcConfig *config);
415
416 FcBool
417 FcDirCacheWriteDir (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir);
418
419 /* fccfg.c */
420
421 FcBool
422 FcConfigAddConfigDir (FcConfig *config,
423 const FcChar8 *d);
424
425 FcBool
426 FcConfigAddFontDir (FcConfig *config,
427 const FcChar8 *d);
428
429 FcBool
430 FcConfigAddDir (FcConfig *config,
431 const FcChar8 *d);
432
433 FcBool
434 FcConfigAddConfigFile (FcConfig *config,
435 const FcChar8 *f);
436
437 FcBool
438 FcConfigSetCache (FcConfig *config,
439 const FcChar8 *c);
440
441 FcBool
442 FcConfigAddBlank (FcConfig *config,
443 FcChar32 blank);
444
445 FcBool
446 FcConfigAddEdit (FcConfig *config,
447 FcTest *test,
448 FcEdit *edit,
449 FcMatchKind kind);
450
451 void
452 FcConfigSetFonts (FcConfig *config,
453 FcFontSet *fonts,
454 FcSetName set);
455
456 FcBool
457 FcConfigCompareValue (const FcValue m,
458 FcOp op,
459 const FcValue v);
460
461 FcBool
462 FcConfigGlobAdd (FcConfig *config,
463 const FcChar8 *glob,
464 FcBool accept);
465
466 FcBool
467 FcConfigAcceptFilename (FcConfig *config,
468 const FcChar8 *filename);
469
470 FcBool
471 FcConfigPatternsAdd (FcConfig *config,
472 FcPattern *pattern,
473 FcBool accept);
474
475 FcBool
476 FcConfigAcceptFont (FcConfig *config,
477 const FcPattern *font);
478
479 /* fccharset.c */
480 FcCharSet *
481 FcCharSetFreeze (FcCharSet *cs);
482
483 void
484 FcCharSetThawAll (void);
485
486 FcBool
487 FcNameUnparseCharSet (FcStrBuf *buf, const FcCharSet *c);
488
489 FcCharSet *
490 FcNameParseCharSet (FcChar8 *string);
491
492 FcCharLeaf *
493 FcCharSetFindLeafCreate (FcCharSet *fcs, FcChar32 ucs4);
494
495 /* fcdbg.c */
496 void
497 FcValueListPrint (const FcValueList *l);
498
499 void
500 FcLangSetPrint (const FcLangSet *ls);
501
502 void
503 FcOpPrint (FcOp op);
504
505 void
506 FcTestPrint (const FcTest *test);
507
508 void
509 FcExprPrint (const FcExpr *expr);
510
511 void
512 FcEditPrint (const FcEdit *edit);
513
514 void
515 FcSubstPrint (const FcSubst *subst);
516
517 int
518 FcDebug (void);
519
520 /* fcdir.c */
521
522 FcBool
523 FcFileScanConfig (FcFontSet *set,
524 FcStrSet *dirs,
525 FcFileCache *cache,
526 FcBlanks *blanks,
527 const FcChar8 *file,
528 FcBool force,
529 FcConfig *config);
530
531 FcBool
532 FcDirScanConfig (FcFontSet *set,
533 FcStrSet *dirs,
534 FcFileCache *cache,
535 FcBlanks *blanks,
536 const FcChar8 *dir,
537 FcBool force,
538 FcConfig *config);
539
540 /* fcfont.c */
541 int
542 FcFontDebug (void);
543
544 /* fcfreetype.c */
545 FcBool
546 FcFreeTypeIsExclusiveLang (const FcChar8 *lang);
547
548 FcBool
549 FcFreeTypeHasLang (FcPattern *pattern, const FcChar8 *lang);
550
551 FcChar32
552 FcFreeTypeUcs4ToPrivate (FcChar32 ucs4, const FcCharMap *map);
553
554 FcChar32
555 FcFreeTypePrivateToUcs4 (FcChar32 private, const FcCharMap *map);
556
557 const FcCharMap *
558 FcFreeTypeGetPrivateMap (FT_Encoding encoding);
559
560 /* fcfs.c */
561 /* fcgram.y */
562 int
563 FcConfigparse (void);
564
565 int
566 FcConfigwrap (void);
567
568 void
569 FcConfigerror (char *fmt, ...);
570
571 char *
572 FcConfigSaveField (const char *field);
573
574 FcTest *
575 FcTestCreate (FcMatchKind kind,
576 FcQual qual,
577 const FcChar8 *field,
578 FcOp compare,
579 FcExpr *expr);
580
581 void
582 FcTestDestroy (FcTest *test);
583
584 FcExpr *
585 FcExprCreateInteger (int i);
586
587 FcExpr *
588 FcExprCreateDouble (double d);
589
590 FcExpr *
591 FcExprCreateString (const FcChar8 *s);
592
593 FcExpr *
594 FcExprCreateMatrix (const FcMatrix *m);
595
596 FcExpr *
597 FcExprCreateBool (FcBool b);
598
599 FcExpr *
600 FcExprCreateNil (void);
601
602 FcExpr *
603 FcExprCreateField (const char *field);
604
605 FcExpr *
606 FcExprCreateConst (const FcChar8 *constant);
607
608 FcExpr *
609 FcExprCreateOp (FcExpr *left, FcOp op, FcExpr *right);
610
611 void
612 FcExprDestroy (FcExpr *e);
613
614 FcEdit *
615 FcEditCreate (const char *field, FcOp op, FcExpr *expr, FcValueBinding binding);
616
617 void
618 FcEditDestroy (FcEdit *e);
619
620 /* fcinit.c */
621
622 void
623 FcMemReport (void);
624
625 void
626 FcMemAlloc (int kind, int size);
627
628 void
629 FcMemFree (int kind, int size);
630
631 /* fclang.c */
632 FcLangSet *
633 FcFreeTypeLangSet (const FcCharSet *charset,
634 const FcChar8 *exclusiveLang);
635
636 FcLangResult
637 FcLangCompare (const FcChar8 *s1, const FcChar8 *s2);
638
639 const FcCharSet *
640 FcCharSetForLang (const FcChar8 *lang);
641
642 FcLangSet *
643 FcLangSetPromote (const FcChar8 *lang);
644
645 FcLangSet *
646 FcNameParseLangSet (const FcChar8 *string);
647
648 FcBool
649 FcNameUnparseLangSet (FcStrBuf *buf, const FcLangSet *ls);
650
651 /* fclist.c */
652
653 FcBool
654 FcListPatternMatchAny (const FcPattern *p,
655 const FcPattern *font);
656
657 /* fcmatch.c */
658
659 /* fcname.c */
660
661 FcBool
662 FcNameBool (FcChar8 *v, FcBool *result);
663
664 /* fcpat.c */
665 void
666 FcValueListDestroy (FcValueList *l);
667
668 FcPatternElt *
669 FcPatternFindElt (const FcPattern *p, const char *object);
670
671 FcPatternElt *
672 FcPatternInsertElt (FcPattern *p, const char *object);
673
674 FcBool
675 FcPatternAddWithBinding (FcPattern *p,
676 const char *object,
677 FcValue value,
678 FcValueBinding binding,
679 FcBool append);
680
681 FcPattern *
682 FcPatternFreeze (FcPattern *p);
683
684 void
685 FcPatternThawAll (void);
686
687 FcBool
688 FcPatternAppend (FcPattern *p, FcPattern *s);
689
690 const char *
691 FcObjectStaticName (const char *name);
692
693 /* fcrender.c */
694
695 /* fcmatrix.c */
696
697 extern const FcMatrix FcIdentityMatrix;
698
699 void
700 FcMatrixFree (FcMatrix *mat);
701
702 /* fcstr.c */
703 FcChar8 *
704 FcStrPlus (const FcChar8 *s1, const FcChar8 *s2);
705
706 void
707 FcStrFree (FcChar8 *s);
708
709 void
710 FcStrBufInit (FcStrBuf *buf, FcChar8 *init, int size);
711
712 void
713 FcStrBufDestroy (FcStrBuf *buf);
714
715 FcChar8 *
716 FcStrBufDone (FcStrBuf *buf);
717
718 FcBool
719 FcStrBufChar (FcStrBuf *buf, FcChar8 c);
720
721 FcBool
722 FcStrBufString (FcStrBuf *buf, const FcChar8 *s);
723
724 FcBool
725 FcStrBufData (FcStrBuf *buf, const FcChar8 *s, int len);
726
727 int
728 FcStrCmpIgnoreBlanksAndCase (const FcChar8 *s1, const FcChar8 *s2);
729
730 const FcChar8 *
731 FcStrContainsIgnoreBlanksAndCase (const FcChar8 *s1, const FcChar8 *s2);
732
733 const FcChar8 *
734 FcStrContainsIgnoreCase (const FcChar8 *s1, const FcChar8 *s2);
735
736 FcBool
737 FcStrUsesHome (const FcChar8 *s);
738
739 FcChar8 *
740 FcStrLastSlash (const FcChar8 *path);
741
742 #endif /* _FC_INT_H_ */