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