]> git.wh0rd.org Git - fontconfig.git/blob - src/fcint.h
Optimize after profiling. Fix FcStrCmp to return correct sign
[fontconfig.git] / src / fcint.h
1 /*
2  * $XFree86: xc/lib/fontconfig/src/fcint.h,v 1.8 2002/05/21 17:06:22 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 #ifdef HAVE_CONFIG_H
40 #include <config.h>
41 #endif
42
43 typedef struct _FcMatcher {
44     char    *object;
45     double  (*compare) (char *object, FcValue value1, FcValue value2);
46     int     priority;
47 } FcMatcher;
48
49 typedef struct _FcSymbolic {
50     const char  *name;
51     int         value;
52 } FcSymbolic;
53
54 #ifndef FC_CONFIG_PATH
55 #define FC_CONFIG_PATH "fonts.conf"
56 #endif
57
58 #define FC_FONT_FILE_INVALID    ((FcChar8 *) ".")
59 #define FC_FONT_FILE_DIR        ((FcChar8 *) ".dir")
60
61 #define FC_DBG_MATCH    1
62 #define FC_DBG_MATCHV   2
63 #define FC_DBG_EDIT     4
64 #define FC_DBG_FONTSET  8
65 #define FC_DBG_CACHE    16
66 #define FC_DBG_CACHEV   32
67 #define FC_DBG_PARSE    64
68 #define FC_DBG_SCAN     128
69 #define FC_DBG_MEMORY   512
70
71 #define FC_MEM_CHARSET      0
72 #define FC_MEM_CHARNODE     1
73 #define FC_MEM_FONTSET      2
74 #define FC_MEM_FONTPTR      3
75 #define FC_MEM_OBJECTSET    4
76 #define FC_MEM_OBJECTPTR    5
77 #define FC_MEM_MATRIX       6
78 #define FC_MEM_PATTERN      7
79 #define FC_MEM_PATELT       8
80 #define FC_MEM_VALLIST      9
81 #define FC_MEM_SUBSTATE     10
82 #define FC_MEM_STRING       11
83 #define FC_MEM_LISTBUCK     12
84 #define FC_MEM_NUM          13
85 #define FC_MEM_STRSET       14
86 #define FC_MEM_STRLIST      15
87 #define FC_MEM_CONFIG       16
88
89 typedef struct _FcValueList {
90     struct _FcValueList    *next;
91     FcValue                 value;
92 } FcValueList;
93
94 typedef struct _FcPatternElt {
95     const char      *object;
96     FcValueList    *values;
97 } FcPatternElt;
98
99 struct _FcPattern {
100     int             num;
101     int             size;
102     FcPatternElt   *elts;
103 };
104
105 typedef enum _FcOp {
106     FcOpInteger, FcOpDouble, FcOpString, FcOpMatrix, FcOpBool, FcOpCharSet, 
107     FcOpNil,
108     FcOpField, FcOpConst,
109     FcOpAssign, FcOpAssignReplace, 
110     FcOpPrependFirst, FcOpPrepend, FcOpAppend, FcOpAppendLast,
111     FcOpQuest,
112     FcOpOr, FcOpAnd, FcOpEqual, FcOpNotEqual, FcOpContains,
113     FcOpLess, FcOpLessEqual, FcOpMore, FcOpMoreEqual,
114     FcOpPlus, FcOpMinus, FcOpTimes, FcOpDivide,
115     FcOpNot, FcOpComma, FcOpInvalid
116 } FcOp;
117
118 typedef struct _FcExpr {
119     FcOp   op;
120     union {
121         int         ival;
122         double      dval;
123         FcChar8     *sval;
124         FcMatrix    *mval;
125         FcBool      bval;
126         FcCharSet   *cval;
127         char        *field;
128         FcChar8     *constant;
129         struct {
130             struct _FcExpr *left, *right;
131         } tree;
132     } u;
133 } FcExpr;
134
135 typedef enum _FcQual {
136     FcQualAny, FcQualAll
137 } FcQual;
138
139 typedef struct _FcTest {
140     struct _FcTest      *next;
141     FcQual              qual;
142     const char          *field;
143     FcOp                op;
144     FcExpr              *expr;
145 } FcTest;
146
147 typedef struct _FcEdit {
148     struct _FcEdit *next;
149     const char      *field;
150     FcOp            op;
151     FcExpr          *expr;
152 } FcEdit;
153
154 typedef struct _FcSubst {
155     struct _FcSubst     *next;
156     FcTest              *test;
157     FcEdit              *edit;
158 } FcSubst;
159
160 typedef struct _FcCharLeaf FcCharLeaf;
161 typedef struct _FcCharBranch FcCharBranch;
162 typedef union  _FcCharNode FcCharNode;
163
164 struct _FcCharLeaf {
165     FcChar32    map[256/32];
166 };
167
168 union _FcCharNode {
169     FcCharBranch    *branch;
170     FcCharLeaf      *leaf;
171 };
172
173 struct _FcCharBranch {
174     FcCharNode      nodes[256];
175     FcChar8         next[256];
176 };
177
178 struct _FcCharSet {
179     int             levels;
180     int             ref;        /* reference count */
181     FcBool          constant;   /* shared constant */
182     FcCharNode      node;
183 };
184
185 struct _FcStrSet {
186     int             ref;        /* reference count */
187     int             num;
188     int             size;
189     FcChar8         **strs;
190 };
191
192 struct _FcStrList {
193     FcStrSet        *set;
194     int             n;
195 };
196
197 typedef struct _FcStrBuf {
198     FcChar8 *buf;
199     FcBool  allocated;
200     FcBool  failed;
201     int     len;
202     int     size;
203 } FcStrBuf;
204
205 typedef struct _FcFileCacheEnt {
206     struct _FcFileCacheEnt *next;
207     unsigned int            hash;
208     FcChar8                 *file;
209     int                     id;
210     time_t                  time;
211     FcChar8                 *name;
212     FcBool                  referenced;
213 } FcFileCacheEnt;
214
215 #define FC_FILE_CACHE_HASH_SIZE   509
216
217 struct _FcFileCache {
218     FcFileCacheEnt      *ents[FC_FILE_CACHE_HASH_SIZE];
219     FcBool              updated;
220     int                 entries;
221     int                 referenced;
222 };
223
224 struct _FcAtomic {
225     FcChar8     *file;          /* original file name */
226     FcChar8     *new;           /* temp file name -- write data here */
227     FcChar8     *lck;           /* lockfile name (used for locking) */
228     FcChar8     *tmp;           /* tmpfile name (used for locking) */
229 };
230
231 struct _FcBlanks {
232     int         nblank;
233     int         sblank;
234     FcChar32    *blanks;
235 };
236
237 struct _FcConfig {
238     /*
239      * File names loaded from the configuration -- saved here as the
240      * cache file must be consulted before the directories are scanned,
241      * and those directives may occur in any order
242      */
243     FcStrSet    *configDirs;        /* directories to scan for fonts */
244     FcChar8     *cache;             /* name of per-user cache file */
245     /*
246      * Set of allowed blank chars -- used to
247      * trim fonts of bogus glyphs
248      */
249     FcBlanks    *blanks;
250     /*
251      * List of directories containing fonts,
252      * built by recursively scanning the set 
253      * of configured directories
254      */
255     FcStrSet    *fontDirs;
256     /*
257      * Names of all of the configuration files used
258      * to create this configuration
259      */
260     FcStrSet    *configFiles;       /* config files loaded */
261     /*
262      * Substitution instructions for patterns and fonts;
263      * maxObjects is used to allocate appropriate intermediate storage
264      * while performing a whole set of substitutions
265      */
266     FcSubst     *substPattern;      /* substitutions for patterns */
267     FcSubst     *substFont;         /* substitutions for fonts */
268     int         maxObjects;         /* maximum number of tests in all substs */
269     /*
270      * The set of fonts loaded from the listed directories; the
271      * order within the set does not determine the font selection,
272      * except in the case of identical matches in which case earlier fonts
273      * match preferrentially
274      */
275     FcFontSet   *fonts[FcSetApplication + 1];
276     /*
277      * Fontconfig can periodically rescan the system configuration
278      * and font directories.  This rescanning occurs when font
279      * listing requests are made, but no more often than rescanInterval
280      * seconds apart.
281      */
282     time_t      rescanTime;         /* last time information was scanned */
283     int         rescanInterval;     /* interval between scans */
284 };
285  
286 extern FcConfig *_fcConfig;
287
288 /* fcblanks.c */
289
290 /* fccache.c */
291
292 FcFileCache *
293 FcFileCacheCreate (void);
294
295 FcChar8 *
296 FcFileCacheFind (FcFileCache    *cache,
297                  const FcChar8  *file,
298                  int            id,
299                  int            *count);
300
301 void
302 FcFileCacheDestroy (FcFileCache *cache);
303
304 FcBool
305 FcFileCacheValid (const FcChar8 *cache_file);
306
307 void
308 FcFileCacheLoad (FcFileCache    *cache,
309                  const FcChar8  *cache_file);
310
311 FcBool
312 FcFileCacheUpdate (FcFileCache      *cache,
313                    const FcChar8    *file,
314                    int              id,
315                    const FcChar8    *name);
316
317 FcBool
318 FcFileCacheSave (FcFileCache    *cache,
319                  const FcChar8  *cache_file);
320
321 FcBool
322 FcFileCacheReadDir (FcFontSet *set, FcStrSet *dirs, const FcChar8 *cache_file);
323
324 FcBool
325 FcFileCacheWriteDir (FcFontSet *set, FcStrSet *dirs, const FcChar8 *cache_file);
326     
327 /* fccfg.c */
328
329 FcBool
330 FcConfigAddConfigDir (FcConfig      *config,
331                       const FcChar8 *d);
332
333 FcBool
334 FcConfigAddFontDir (FcConfig        *config,
335                     const FcChar8   *d);
336
337 FcBool
338 FcConfigAddDir (FcConfig        *config,
339                 const FcChar8   *d);
340
341 FcBool
342 FcConfigAddConfigFile (FcConfig         *config,
343                        const FcChar8    *f);
344
345 FcBool
346 FcConfigSetCache (FcConfig      *config,
347                   const FcChar8 *c);
348
349 FcBool
350 FcConfigAddBlank (FcConfig      *config,
351                   FcChar32      blank);
352
353 FcBool
354 FcConfigAddEdit (FcConfig       *config,
355                  FcTest         *test,
356                  FcEdit         *edit,
357                  FcMatchKind    kind);
358
359 void
360 FcConfigSetFonts (FcConfig      *config,
361                   FcFontSet     *fonts,
362                   FcSetName     set);
363
364 FcBool
365 FcConfigCompareValue (const FcValue m,
366                       FcOp          op,
367                       const FcValue v);
368
369 /* fccharset.c */
370 FcBool
371 FcNameUnparseCharSet (FcStrBuf *buf, const FcCharSet *c);
372
373 FcCharSet *
374 FcNameParseCharSet (FcChar8 *string);
375
376 /* fcdbg.c */
377 void
378 FcValueListPrint (FcValueList *l);
379
380 void
381 FcOpPrint (FcOp op);
382
383 void
384 FcTestPrint (FcTest *test);
385
386 void
387 FcExprPrint (FcExpr *expr);
388
389 void
390 FcEditPrint (FcEdit *edit);
391
392 void
393 FcSubstPrint (FcSubst *subst);
394
395 int
396 FcDebug (void);
397
398 /* fcdir.c */
399
400 /* fcfont.c */
401 int
402 FcFontDebug (void);
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 /* fclist.c */
472
473 /* fcmatch.c */
474
475 /* fcname.c */
476
477 FcBool
478 FcNameBool (FcChar8 *v, FcBool *result);
479
480 /* fcpat.c */
481 void
482 FcValueListDestroy (FcValueList *l);
483     
484 FcPatternElt *
485 FcPatternFind (FcPattern *p, const char *object, FcBool insert);
486
487 /* fcrender.c */
488
489 /* fcmatrix.c */
490 void
491 FcMatrixFree (FcMatrix *mat);
492
493 /* fcstr.c */
494 FcChar8 *
495 FcStrPlus (const FcChar8 *s1, const FcChar8 *s2);
496     
497 void
498 FcStrFree (FcChar8 *s);
499
500 void
501 FcStrBufInit (FcStrBuf *buf, FcChar8 *init, int size);
502
503 void
504 FcStrBufDestroy (FcStrBuf *buf);
505
506 FcChar8 *
507 FcStrBufDone (FcStrBuf *buf);
508
509 FcBool
510 FcStrBufChar (FcStrBuf *buf, FcChar8 c);
511
512 FcBool
513 FcStrBufString (FcStrBuf *buf, const FcChar8 *s);
514
515 FcBool
516 FcStrBufData (FcStrBuf *buf, const FcChar8 *s, int len);
517
518 #endif /* _FC_INT_H_ */