Add walloon, update fclang.c to include recent language additions
[platform/upstream/fontconfig.git] / src / fcint.h
1 /*
2  * $XFree86: xc/lib/fontconfig/src/fcint.h,v 1.13 2002/06/03 08:31:15 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     FcValueBinding          binding;
92     FcValue                 value;
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     int             ref;
104     FcPatternElt    *elts;
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 } FcEdit;
155
156 typedef struct _FcSubst {
157     struct _FcSubst     *next;
158     FcTest              *test;
159     FcEdit              *edit;
160 } FcSubst;
161
162 typedef struct _FcCharLeaf {
163     FcChar32    map[256/32];
164 } FcCharLeaf;
165
166 typedef enum _FcLangResult {
167     FcLangEqual, FcLangDifferentCountry, FcLangDifferentLang
168 } FcLangResult;
169
170 struct _FcCharSet {
171     int             ref;        /* reference count */
172     FcBool          constant;   /* in hash table constant */
173     int             num;        /* size of leaves and numbers arrays */
174     FcCharLeaf      **leaves;
175     FcChar16        *numbers;
176 };
177
178 struct _FcStrSet {
179     int             ref;        /* reference count */
180     int             num;
181     int             size;
182     FcChar8         **strs;
183 };
184
185 struct _FcStrList {
186     FcStrSet        *set;
187     int             n;
188 };
189
190 typedef struct _FcStrBuf {
191     FcChar8 *buf;
192     FcBool  allocated;
193     FcBool  failed;
194     int     len;
195     int     size;
196 } FcStrBuf;
197
198 typedef struct _FcFileCacheEnt {
199     struct _FcFileCacheEnt *next;
200     unsigned int            hash;
201     FcChar8                 *file;
202     int                     id;
203     time_t                  time;
204     FcChar8                 *name;
205     FcBool                  referenced;
206 } FcFileCacheEnt;
207
208 #define FC_FILE_CACHE_HASH_SIZE   509
209
210 struct _FcFileCache {
211     FcFileCacheEnt      *ents[FC_FILE_CACHE_HASH_SIZE];
212     FcBool              updated;
213     int                 entries;
214     int                 referenced;
215 };
216
217 struct _FcAtomic {
218     FcChar8     *file;          /* original file name */
219     FcChar8     *new;           /* temp file name -- write data here */
220     FcChar8     *lck;           /* lockfile name (used for locking) */
221     FcChar8     *tmp;           /* tmpfile name (used for locking) */
222 };
223
224 struct _FcBlanks {
225     int         nblank;
226     int         sblank;
227     FcChar32    *blanks;
228 };
229
230 struct _FcConfig {
231     /*
232      * File names loaded from the configuration -- saved here as the
233      * cache file must be consulted before the directories are scanned,
234      * and those directives may occur in any order
235      */
236     FcStrSet    *configDirs;        /* directories to scan for fonts */
237     FcChar8     *cache;             /* name of per-user cache file */
238     /*
239      * Set of allowed blank chars -- used to
240      * trim fonts of bogus glyphs
241      */
242     FcBlanks    *blanks;
243     /*
244      * List of directories containing fonts,
245      * built by recursively scanning the set 
246      * of configured directories
247      */
248     FcStrSet    *fontDirs;
249     /*
250      * Names of all of the configuration files used
251      * to create this configuration
252      */
253     FcStrSet    *configFiles;       /* config files loaded */
254     /*
255      * Substitution instructions for patterns and fonts;
256      * maxObjects is used to allocate appropriate intermediate storage
257      * while performing a whole set of substitutions
258      */
259     FcSubst     *substPattern;      /* substitutions for patterns */
260     FcSubst     *substFont;         /* substitutions for fonts */
261     int         maxObjects;         /* maximum number of tests in all substs */
262     /*
263      * The set of fonts loaded from the listed directories; the
264      * order within the set does not determine the font selection,
265      * except in the case of identical matches in which case earlier fonts
266      * match preferrentially
267      */
268     FcFontSet   *fonts[FcSetApplication + 1];
269     /*
270      * Fontconfig can periodically rescan the system configuration
271      * and font directories.  This rescanning occurs when font
272      * listing requests are made, but no more often than rescanInterval
273      * seconds apart.
274      */
275     time_t      rescanTime;         /* last time information was scanned */
276     int         rescanInterval;     /* interval between scans */
277 };
278  
279 extern FcConfig *_fcConfig;
280
281 /* fcblanks.c */
282
283 /* fccache.c */
284
285 FcFileCache *
286 FcFileCacheCreate (void);
287
288 FcChar8 *
289 FcFileCacheFind (FcFileCache    *cache,
290                  const FcChar8  *file,
291                  int            id,
292                  int            *count);
293
294 void
295 FcFileCacheDestroy (FcFileCache *cache);
296
297 FcBool
298 FcFileCacheValid (const FcChar8 *cache_file);
299
300 void
301 FcFileCacheLoad (FcFileCache    *cache,
302                  const FcChar8  *cache_file);
303
304 FcBool
305 FcFileCacheUpdate (FcFileCache      *cache,
306                    const FcChar8    *file,
307                    int              id,
308                    const FcChar8    *name);
309
310 FcBool
311 FcFileCacheSave (FcFileCache    *cache,
312                  const FcChar8  *cache_file);
313
314 FcBool
315 FcFileCacheReadDir (FcFontSet *set, FcStrSet *dirs, const FcChar8 *cache_file);
316
317 FcBool
318 FcFileCacheWriteDir (FcFontSet *set, FcStrSet *dirs, const FcChar8 *cache_file);
319     
320 /* fccfg.c */
321
322 FcBool
323 FcConfigAddConfigDir (FcConfig      *config,
324                       const FcChar8 *d);
325
326 FcBool
327 FcConfigAddFontDir (FcConfig        *config,
328                     const FcChar8   *d);
329
330 FcBool
331 FcConfigAddDir (FcConfig        *config,
332                 const FcChar8   *d);
333
334 FcBool
335 FcConfigAddConfigFile (FcConfig         *config,
336                        const FcChar8    *f);
337
338 FcBool
339 FcConfigSetCache (FcConfig      *config,
340                   const FcChar8 *c);
341
342 FcBool
343 FcConfigAddBlank (FcConfig      *config,
344                   FcChar32      blank);
345
346 FcBool
347 FcConfigAddEdit (FcConfig       *config,
348                  FcTest         *test,
349                  FcEdit         *edit,
350                  FcMatchKind    kind);
351
352 void
353 FcConfigSetFonts (FcConfig      *config,
354                   FcFontSet     *fonts,
355                   FcSetName     set);
356
357 FcBool
358 FcConfigCompareValue (const FcValue m,
359                       FcOp          op,
360                       const FcValue v);
361
362 /* fccharset.c */
363 FcCharSet *
364 FcCharSetFreeze (FcCharSet *cs);
365
366 FcBool
367 FcNameUnparseCharSet (FcStrBuf *buf, const FcCharSet *c);
368
369 FcCharSet *
370 FcNameParseCharSet (FcChar8 *string);
371
372 /* fcdbg.c */
373 void
374 FcValueListPrint (FcValueList *l);
375
376 void
377 FcOpPrint (FcOp op);
378
379 void
380 FcTestPrint (FcTest *test);
381
382 void
383 FcExprPrint (FcExpr *expr);
384
385 void
386 FcEditPrint (FcEdit *edit);
387
388 void
389 FcSubstPrint (FcSubst *subst);
390
391 int
392 FcDebug (void);
393
394 /* fcdir.c */
395
396 /* fcfont.c */
397 int
398 FcFontDebug (void);
399     
400 /* fcfreetype.c */
401 FcBool
402 FcFreeTypeHasLang (FcPattern *pattern, const FcChar8 *lang);
403
404 /* fcfs.c */
405 /* fcgram.y */
406 int
407 FcConfigparse (void);
408
409 int
410 FcConfigwrap (void);
411     
412 void
413 FcConfigerror (char *fmt, ...);
414     
415 char *
416 FcConfigSaveField (const char *field);
417
418 FcTest *
419 FcTestCreate (FcQual qual, const FcChar8 *field, FcOp compare, FcExpr *expr);
420
421 void
422 FcTestDestroy (FcTest *test);
423
424 FcExpr *
425 FcExprCreateInteger (int i);
426
427 FcExpr *
428 FcExprCreateDouble (double d);
429
430 FcExpr *
431 FcExprCreateString (const FcChar8 *s);
432
433 FcExpr *
434 FcExprCreateMatrix (const FcMatrix *m);
435
436 FcExpr *
437 FcExprCreateBool (FcBool b);
438
439 FcExpr *
440 FcExprCreateNil (void);
441
442 FcExpr *
443 FcExprCreateField (const char *field);
444
445 FcExpr *
446 FcExprCreateConst (const FcChar8 *constant);
447
448 FcExpr *
449 FcExprCreateOp (FcExpr *left, FcOp op, FcExpr *right);
450
451 void
452 FcExprDestroy (FcExpr *e);
453
454 FcEdit *
455 FcEditCreate (const char *field, FcOp op, FcExpr *expr);
456
457 void
458 FcEditDestroy (FcEdit *e);
459
460 /* fcinit.c */
461
462 void
463 FcMemReport (void);
464
465 void
466 FcMemAlloc (int kind, int size);
467
468 void
469 FcMemFree (int kind, int size);
470
471 /* fclang.c */
472 FcBool
473 FcFreeTypeSetLang (FcPattern *pattern, FcCharSet *charset);
474
475 FcLangResult
476 FcLangCompare (const FcChar8 *s1, const FcChar8 *s2);
477     
478 const FcCharSet *
479 FcCharSetForLang (const FcChar8 *lang);
480
481 /* fclist.c */
482
483 /* fcmatch.c */
484
485 /* fcname.c */
486
487 FcBool
488 FcNameBool (FcChar8 *v, FcBool *result);
489
490 /* fcpat.c */
491 void
492 FcValueListDestroy (FcValueList *l);
493     
494 FcPatternElt *
495 FcPatternFindElt (const FcPattern *p, const char *object);
496
497 FcPatternElt *
498 FcPatternInsertElt (FcPattern *p, const char *object);
499
500 FcBool
501 FcPatternAddWithBinding  (FcPattern         *p,
502                           const char        *object,
503                           FcValue           value,
504                           FcValueBinding    binding,
505                           FcBool            append);
506
507 /* fcrender.c */
508
509 /* fcmatrix.c */
510 void
511 FcMatrixFree (FcMatrix *mat);
512
513 /* fcstr.c */
514 FcChar8 *
515 FcStrPlus (const FcChar8 *s1, const FcChar8 *s2);
516     
517 void
518 FcStrFree (FcChar8 *s);
519
520 void
521 FcStrBufInit (FcStrBuf *buf, FcChar8 *init, int size);
522
523 void
524 FcStrBufDestroy (FcStrBuf *buf);
525
526 FcChar8 *
527 FcStrBufDone (FcStrBuf *buf);
528
529 FcBool
530 FcStrBufChar (FcStrBuf *buf, FcChar8 c);
531
532 FcBool
533 FcStrBufString (FcStrBuf *buf, const FcChar8 *s);
534
535 FcBool
536 FcStrBufData (FcStrBuf *buf, const FcChar8 *s, int len);
537
538 int
539 FcStrCmpIgnoreBlanksAndCase (const FcChar8 *s1, const FcChar8 *s2);
540
541 #endif /* _FC_INT_H_ */