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