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