]> git.wh0rd.org - fontconfig.git/blob - src/fcint.h
b861dc1cc63b4e7a4c31a3a48997a35f380c108b
[fontconfig.git] / src / fcint.h
1 /*
2 * $XFree86: xc/lib/fontconfig/src/fcint.h,v 1.21 2002/07/31 01:36:37 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 FcValue value;
92 FcValueBinding binding;
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 FcPatternElt *elts;
104 int ref;
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 #define FcMatchDefault ((FcMatchKind) -1)
142
143 typedef struct _FcTest {
144 struct _FcTest *next;
145 FcMatchKind kind;
146 FcQual qual;
147 const char *field;
148 FcOp op;
149 FcExpr *expr;
150 } FcTest;
151
152 typedef struct _FcEdit {
153 struct _FcEdit *next;
154 const char *field;
155 FcOp op;
156 FcExpr *expr;
157 FcValueBinding binding;
158 } FcEdit;
159
160 typedef struct _FcSubst {
161 struct _FcSubst *next;
162 FcTest *test;
163 FcEdit *edit;
164 } FcSubst;
165
166 typedef struct _FcCharLeaf {
167 FcChar32 map[256/32];
168 } FcCharLeaf;
169
170 typedef enum _FcLangResult {
171 FcLangEqual, FcLangDifferentCountry, FcLangDifferentLang
172 } FcLangResult;
173
174 struct _FcCharSet {
175 int ref; /* reference count */
176 FcBool constant; /* in hash table constant */
177 int num; /* size of leaves and numbers arrays */
178 FcCharLeaf **leaves;
179 FcChar16 *numbers;
180 };
181
182 struct _FcStrSet {
183 int ref; /* reference count */
184 int num;
185 int size;
186 FcChar8 **strs;
187 };
188
189 struct _FcStrList {
190 FcStrSet *set;
191 int n;
192 };
193
194 typedef struct _FcStrBuf {
195 FcChar8 *buf;
196 FcBool allocated;
197 FcBool failed;
198 int len;
199 int size;
200 } FcStrBuf;
201
202 /*
203 * The per-user ~/.fonts.cache file is loaded into
204 * this data structure. Each directory gets a substructure
205 * which is validated by comparing the directory timestamp with
206 * that saved in the cache. When valid, the entire directory cache
207 * can be immediately loaded without reading the directory. Otherwise,
208 * the files are checked individually; updated files are loaded into the
209 * cache which is then rewritten to the users home directory
210 */
211
212 #define FC_GLOBAL_CACHE_DIR_HASH_SIZE 37
213 #define FC_GLOBAL_CACHE_FILE_HASH_SIZE 67
214
215 typedef struct _FcGlobalCacheInfo {
216 unsigned int hash;
217 FcChar8 *file;
218 time_t time;
219 FcBool referenced;
220 } FcGlobalCacheInfo;
221
222 typedef struct _FcGlobalCacheFile {
223 struct _FcGlobalCacheFile *next;
224 FcGlobalCacheInfo info;
225 int id;
226 FcChar8 *name;
227 } FcGlobalCacheFile;
228
229 typedef struct _FcGlobalCacheSubdir {
230 struct _FcGlobalCacheSubdir *next;
231 FcChar8 *file;
232 } FcGlobalCacheSubdir;
233
234 typedef struct _FcGlobalCacheDir {
235 struct _FcGlobalCacheDir *next;
236 FcGlobalCacheInfo info;
237 int len;
238 FcGlobalCacheFile *ents[FC_GLOBAL_CACHE_FILE_HASH_SIZE];
239 FcGlobalCacheSubdir *subdirs;
240 } FcGlobalCacheDir;
241
242 typedef struct _FcGlobalCache {
243 FcGlobalCacheDir *ents[FC_GLOBAL_CACHE_DIR_HASH_SIZE];
244 FcBool updated;
245 FcBool broken;
246 int entries;
247 int referenced;
248 } FcGlobalCache;
249
250 struct _FcAtomic {
251 FcChar8 *file; /* original file name */
252 FcChar8 *new; /* temp file name -- write data here */
253 FcChar8 *lck; /* lockfile name (used for locking) */
254 FcChar8 *tmp; /* tmpfile name (used for locking) */
255 };
256
257 struct _FcBlanks {
258 int nblank;
259 int sblank;
260 FcChar32 *blanks;
261 };
262
263 struct _FcConfig {
264 /*
265 * File names loaded from the configuration -- saved here as the
266 * cache file must be consulted before the directories are scanned,
267 * and those directives may occur in any order
268 */
269 FcStrSet *configDirs; /* directories to scan for fonts */
270 FcChar8 *cache; /* name of per-user cache file */
271 /*
272 * Set of allowed blank chars -- used to
273 * trim fonts of bogus glyphs
274 */
275 FcBlanks *blanks;
276 /*
277 * List of directories containing fonts,
278 * built by recursively scanning the set
279 * of configured directories
280 */
281 FcStrSet *fontDirs;
282 /*
283 * Names of all of the configuration files used
284 * to create this configuration
285 */
286 FcStrSet *configFiles; /* config files loaded */
287 /*
288 * Substitution instructions for patterns and fonts;
289 * maxObjects is used to allocate appropriate intermediate storage
290 * while performing a whole set of substitutions
291 */
292 FcSubst *substPattern; /* substitutions for patterns */
293 FcSubst *substFont; /* substitutions for fonts */
294 int maxObjects; /* maximum number of tests in all substs */
295 /*
296 * The set of fonts loaded from the listed directories; the
297 * order within the set does not determine the font selection,
298 * except in the case of identical matches in which case earlier fonts
299 * match preferrentially
300 */
301 FcFontSet *fonts[FcSetApplication + 1];
302 /*
303 * Fontconfig can periodically rescan the system configuration
304 * and font directories. This rescanning occurs when font
305 * listing requests are made, but no more often than rescanInterval
306 * seconds apart.
307 */
308 time_t rescanTime; /* last time information was scanned */
309 int rescanInterval; /* interval between scans */
310 };
311
312 extern FcConfig *_fcConfig;
313
314 typedef struct _FcCharMap FcCharMap;
315
316 /* fcblanks.c */
317
318 /* fccache.c */
319
320 FcGlobalCache *
321 FcGlobalCacheCreate (void);
322
323 void
324 FcGlobalCacheDestroy (FcGlobalCache *cache);
325
326 FcBool
327 FcGlobalCacheCheckTime (FcGlobalCacheInfo *info);
328
329 void
330 FcGlobalCacheReferenced (FcGlobalCache *cache,
331 FcGlobalCacheInfo *info);
332
333 FcGlobalCacheDir *
334 FcGlobalCacheDirGet (FcGlobalCache *cache,
335 const FcChar8 *dir,
336 int len,
337 FcBool create_missing);
338
339 FcBool
340 FcGlobalCacheScanDir (FcFontSet *set,
341 FcStrSet *dirs,
342 FcGlobalCache *cache,
343 const FcChar8 *dir);
344
345 FcGlobalCacheFile *
346 FcGlobalCacheFileGet (FcGlobalCache *cache,
347 const FcChar8 *file,
348 int id,
349 int *count);
350
351
352 void
353 FcGlobalCacheLoad (FcGlobalCache *cache,
354 const FcChar8 *cache_file);
355
356 FcBool
357 FcGlobalCacheUpdate (FcGlobalCache *cache,
358 const FcChar8 *file,
359 int id,
360 const FcChar8 *name);
361
362 FcBool
363 FcGlobalCacheSave (FcGlobalCache *cache,
364 const FcChar8 *cache_file);
365
366 FcBool
367 FcDirCacheReadDir (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir);
368
369 FcBool
370 FcDirCacheWriteDir (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir);
371
372 /* fccfg.c */
373
374 FcBool
375 FcConfigAddConfigDir (FcConfig *config,
376 const FcChar8 *d);
377
378 FcBool
379 FcConfigAddFontDir (FcConfig *config,
380 const FcChar8 *d);
381
382 FcBool
383 FcConfigAddDir (FcConfig *config,
384 const FcChar8 *d);
385
386 FcBool
387 FcConfigAddConfigFile (FcConfig *config,
388 const FcChar8 *f);
389
390 FcBool
391 FcConfigSetCache (FcConfig *config,
392 const FcChar8 *c);
393
394 FcBool
395 FcConfigAddBlank (FcConfig *config,
396 FcChar32 blank);
397
398 FcBool
399 FcConfigAddEdit (FcConfig *config,
400 FcTest *test,
401 FcEdit *edit,
402 FcMatchKind kind);
403
404 void
405 FcConfigSetFonts (FcConfig *config,
406 FcFontSet *fonts,
407 FcSetName set);
408
409 FcBool
410 FcConfigCompareValue (const FcValue m,
411 FcOp op,
412 const FcValue v);
413
414 /* fccharset.c */
415 FcCharSet *
416 FcCharSetFreeze (FcCharSet *cs);
417
418 FcBool
419 FcNameUnparseCharSet (FcStrBuf *buf, const FcCharSet *c);
420
421 FcCharSet *
422 FcNameParseCharSet (FcChar8 *string);
423
424 FcChar32
425 FcFreeTypeUcs4ToPrivate (FcChar32 ucs4, const FcCharMap *map);
426
427 FcChar32
428 FcFreeTypePrivateToUcs4 (FcChar32 private, const FcCharMap *map);
429
430 const FcCharMap *
431 FcFreeTypeGetPrivateMap (FT_Encoding encoding);
432
433 /* fcdbg.c */
434 void
435 FcValueListPrint (const FcValueList *l);
436
437 void
438 FcOpPrint (FcOp op);
439
440 void
441 FcTestPrint (const FcTest *test);
442
443 void
444 FcExprPrint (const FcExpr *expr);
445
446 void
447 FcEditPrint (const FcEdit *edit);
448
449 void
450 FcSubstPrint (const FcSubst *subst);
451
452 int
453 FcDebug (void);
454
455 /* fcdir.c */
456
457 /* fcfont.c */
458 int
459 FcFontDebug (void);
460
461 /* fcfreetype.c */
462 FcBool
463 FcFreeTypeIsExclusiveLang (const FcChar8 *lang);
464
465 FcBool
466 FcFreeTypeHasLang (FcPattern *pattern, const FcChar8 *lang);
467
468 /* fcfs.c */
469 /* fcgram.y */
470 int
471 FcConfigparse (void);
472
473 int
474 FcConfigwrap (void);
475
476 void
477 FcConfigerror (char *fmt, ...);
478
479 char *
480 FcConfigSaveField (const char *field);
481
482 FcTest *
483 FcTestCreate (FcMatchKind kind,
484 FcQual qual,
485 const FcChar8 *field,
486 FcOp compare,
487 FcExpr *expr);
488
489 void
490 FcTestDestroy (FcTest *test);
491
492 FcExpr *
493 FcExprCreateInteger (int i);
494
495 FcExpr *
496 FcExprCreateDouble (double d);
497
498 FcExpr *
499 FcExprCreateString (const FcChar8 *s);
500
501 FcExpr *
502 FcExprCreateMatrix (const FcMatrix *m);
503
504 FcExpr *
505 FcExprCreateBool (FcBool b);
506
507 FcExpr *
508 FcExprCreateNil (void);
509
510 FcExpr *
511 FcExprCreateField (const char *field);
512
513 FcExpr *
514 FcExprCreateConst (const FcChar8 *constant);
515
516 FcExpr *
517 FcExprCreateOp (FcExpr *left, FcOp op, FcExpr *right);
518
519 void
520 FcExprDestroy (FcExpr *e);
521
522 FcEdit *
523 FcEditCreate (const char *field, FcOp op, FcExpr *expr, FcValueBinding binding);
524
525 void
526 FcEditDestroy (FcEdit *e);
527
528 /* fcinit.c */
529
530 void
531 FcMemReport (void);
532
533 void
534 FcMemAlloc (int kind, int size);
535
536 void
537 FcMemFree (int kind, int size);
538
539 /* fclang.c */
540 FcBool
541 FcFreeTypeSetLang (FcPattern *pattern,
542 FcCharSet *charset,
543 const FcChar8 *exclusiveLang);
544
545 FcLangResult
546 FcLangCompare (const FcChar8 *s1, const FcChar8 *s2);
547
548 const FcCharSet *
549 FcCharSetForLang (const FcChar8 *lang);
550
551 /* fclist.c */
552
553 /* fcmatch.c */
554
555 /* fcname.c */
556
557 FcBool
558 FcNameBool (FcChar8 *v, FcBool *result);
559
560 /* fcpat.c */
561 void
562 FcValueListDestroy (FcValueList *l);
563
564 FcPatternElt *
565 FcPatternFindElt (const FcPattern *p, const char *object);
566
567 FcPatternElt *
568 FcPatternInsertElt (FcPattern *p, const char *object);
569
570 FcBool
571 FcPatternAddWithBinding (FcPattern *p,
572 const char *object,
573 FcValue value,
574 FcValueBinding binding,
575 FcBool append);
576
577 /* fcrender.c */
578
579 /* fcmatrix.c */
580
581 extern const FcMatrix FcIdentityMatrix;
582
583 void
584 FcMatrixFree (FcMatrix *mat);
585
586 /* fcstr.c */
587 FcChar8 *
588 FcStrPlus (const FcChar8 *s1, const FcChar8 *s2);
589
590 void
591 FcStrFree (FcChar8 *s);
592
593 void
594 FcStrBufInit (FcStrBuf *buf, FcChar8 *init, int size);
595
596 void
597 FcStrBufDestroy (FcStrBuf *buf);
598
599 FcChar8 *
600 FcStrBufDone (FcStrBuf *buf);
601
602 FcBool
603 FcStrBufChar (FcStrBuf *buf, FcChar8 c);
604
605 FcBool
606 FcStrBufString (FcStrBuf *buf, const FcChar8 *s);
607
608 FcBool
609 FcStrBufData (FcStrBuf *buf, const FcChar8 *s, int len);
610
611 int
612 FcStrCmpIgnoreBlanksAndCase (const FcChar8 *s1, const FcChar8 *s2);
613
614 #endif /* _FC_INT_H_ */