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