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