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