]> git.wh0rd.org - fontconfig.git/blame_incremental - src/fcint.h
Change files from ISO-Latin-1 to UTF-8
[fontconfig.git] / src / fcint.h
... / ...
CommitLineData
1/*
2 * $RCSId: xc/lib/fontconfig/src/fcint.h,v 1.27 2002/08/31 22:17:32 keithp Exp $
3 *
4 * Copyright © 2000 Keith Packard
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
44typedef 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#ifdef _WIN32
57#define FC_SEARCH_PATH_SEPARATOR ';'
58#else
59#define FC_SEARCH_PATH_SEPARATOR ':'
60#endif
61
62#define FC_DBG_MATCH 1
63#define FC_DBG_MATCHV 2
64#define FC_DBG_EDIT 4
65#define FC_DBG_FONTSET 8
66#define FC_DBG_CACHE 16
67#define FC_DBG_CACHEV 32
68#define FC_DBG_PARSE 64
69#define FC_DBG_SCAN 128
70#define FC_DBG_SCANV 256
71#define FC_DBG_MEMORY 512
72#define FC_DBG_CONFIG 1024
73
74#define FC_MEM_CHARSET 0
75#define FC_MEM_CHARLEAF 1
76#define FC_MEM_FONTSET 2
77#define FC_MEM_FONTPTR 3
78#define FC_MEM_OBJECTSET 4
79#define FC_MEM_OBJECTPTR 5
80#define FC_MEM_MATRIX 6
81#define FC_MEM_PATTERN 7
82#define FC_MEM_PATELT 8
83#define FC_MEM_VALLIST 9
84#define FC_MEM_SUBSTATE 10
85#define FC_MEM_STRING 11
86#define FC_MEM_LISTBUCK 12
87#define FC_MEM_STRSET 13
88#define FC_MEM_STRLIST 14
89#define FC_MEM_CONFIG 15
90#define FC_MEM_LANGSET 16
91#define FC_MEM_ATOMIC 17
92#define FC_MEM_BLANKS 18
93#define FC_MEM_CACHE 19
94#define FC_MEM_STRBUF 20
95#define FC_MEM_SUBST 21
96#define FC_MEM_OBJECTTYPE 22
97#define FC_MEM_CONSTANT 23
98#define FC_MEM_TEST 24
99#define FC_MEM_EXPR 25
100#define FC_MEM_VSTACK 26
101#define FC_MEM_ATTR 27
102#define FC_MEM_PSTACK 28
103
104#define FC_MEM_NUM 29
105
106typedef enum _FcValueBinding {
107 FcValueBindingWeak, FcValueBindingStrong, FcValueBindingSame
108} FcValueBinding;
109
110typedef struct _FcValueList {
111 struct _FcValueList *next;
112 FcValue value;
113 FcValueBinding binding;
114} FcValueList;
115
116typedef struct _FcPatternElt {
117 const char *object;
118 FcValueList *values;
119} FcPatternElt;
120
121
122struct _FcPattern {
123 int num;
124 int size;
125 FcPatternElt *elts;
126 int ref;
127};
128
129typedef enum _FcOp {
130 FcOpInteger, FcOpDouble, FcOpString, FcOpMatrix, FcOpBool, FcOpCharSet,
131 FcOpNil,
132 FcOpField, FcOpConst,
133 FcOpAssign, FcOpAssignReplace,
134 FcOpPrependFirst, FcOpPrepend, FcOpAppend, FcOpAppendLast,
135 FcOpQuest,
136 FcOpOr, FcOpAnd, FcOpEqual, FcOpNotEqual,
137 FcOpContains, FcOpListing, FcOpNotContains,
138 FcOpLess, FcOpLessEqual, FcOpMore, FcOpMoreEqual,
139 FcOpPlus, FcOpMinus, FcOpTimes, FcOpDivide,
140 FcOpNot, FcOpComma, FcOpFloor, FcOpCeil, FcOpRound, FcOpTrunc,
141 FcOpInvalid
142} FcOp;
143
144typedef struct _FcExpr {
145 FcOp op;
146 union {
147 int ival;
148 double dval;
149 FcChar8 *sval;
150 FcMatrix *mval;
151 FcBool bval;
152 FcCharSet *cval;
153 char *field;
154 FcChar8 *constant;
155 struct {
156 struct _FcExpr *left, *right;
157 } tree;
158 } u;
159} FcExpr;
160
161typedef enum _FcQual {
162 FcQualAny, FcQualAll, FcQualFirst, FcQualNotFirst
163} FcQual;
164
165#define FcMatchDefault ((FcMatchKind) -1)
166
167typedef struct _FcTest {
168 struct _FcTest *next;
169 FcMatchKind kind;
170 FcQual qual;
171 const char *field;
172 FcOp op;
173 FcExpr *expr;
174} FcTest;
175
176typedef struct _FcEdit {
177 struct _FcEdit *next;
178 const char *field;
179 FcOp op;
180 FcExpr *expr;
181 FcValueBinding binding;
182} FcEdit;
183
184typedef struct _FcSubst {
185 struct _FcSubst *next;
186 FcTest *test;
187 FcEdit *edit;
188} FcSubst;
189
190typedef struct _FcCharLeaf {
191 FcChar32 map[256/32];
192} FcCharLeaf;
193
194#define FC_REF_CONSTANT -1
195
196struct _FcCharSet {
197 int ref; /* reference count */
198 int num; /* size of leaves and numbers arrays */
199 FcCharLeaf **leaves;
200 FcChar16 *numbers;
201};
202
203struct _FcStrSet {
204 int ref; /* reference count */
205 int num;
206 int size;
207 FcChar8 **strs;
208};
209
210struct _FcStrList {
211 FcStrSet *set;
212 int n;
213};
214
215typedef struct _FcStrBuf {
216 FcChar8 *buf;
217 FcBool allocated;
218 FcBool failed;
219 int len;
220 int size;
221} FcStrBuf;
222
223/*
224 * To map adobe glyph names to unicode values, a precomputed hash
225 * table is used
226 */
227
228typedef struct _FcGlyphName {
229 FcChar32 ucs; /* unicode value */
230 FcChar8 name[1]; /* name extends beyond struct */
231} FcGlyphName;
232
233#define FC_MAX_FILE_LEN 4096
234
235/*
236 * The per-user ~/.fonts.cache-<version> file is loaded into
237 * this data structure. Each directory gets a substructure
238 * which is validated by comparing the directory timestamp with
239 * that saved in the cache. When valid, the entire directory cache
240 * can be immediately loaded without reading the directory. Otherwise,
241 * the files are checked individually; updated files are loaded into the
242 * cache which is then rewritten to the users home directory
243 */
244
245#define FC_GLOBAL_CACHE_DIR_HASH_SIZE 37
246#define FC_GLOBAL_CACHE_FILE_HASH_SIZE 67
247
248typedef struct _FcGlobalCacheInfo {
249 unsigned int hash;
250 FcChar8 *file;
251 time_t time;
252 FcBool referenced;
253} FcGlobalCacheInfo;
254
255typedef struct _FcGlobalCacheFile {
256 struct _FcGlobalCacheFile *next;
257 FcGlobalCacheInfo info;
258 int id;
259 FcChar8 *name;
260} FcGlobalCacheFile;
261
262typedef struct _FcGlobalCacheDir FcGlobalCacheDir;
263
264typedef struct _FcGlobalCacheSubdir {
265 struct _FcGlobalCacheSubdir *next;
266 FcGlobalCacheDir *ent;
267} FcGlobalCacheSubdir;
268
269struct _FcGlobalCacheDir {
270 struct _FcGlobalCacheDir *next;
271 FcGlobalCacheInfo info;
272 int len;
273 FcGlobalCacheFile *ents[FC_GLOBAL_CACHE_FILE_HASH_SIZE];
274 FcGlobalCacheSubdir *subdirs;
275};
276
277typedef struct _FcGlobalCache {
278 FcGlobalCacheDir *ents[FC_GLOBAL_CACHE_DIR_HASH_SIZE];
279 FcBool updated;
280 FcBool broken;
281 int entries;
282 int referenced;
283} FcGlobalCache;
284
285struct _FcAtomic {
286 FcChar8 *file; /* original file name */
287 FcChar8 *new; /* temp file name -- write data here */
288 FcChar8 *lck; /* lockfile name (used for locking) */
289 FcChar8 *tmp; /* tmpfile name (used for locking) */
290};
291
292struct _FcBlanks {
293 int nblank;
294 int sblank;
295 FcChar32 *blanks;
296};
297
298struct _FcConfig {
299 /*
300 * File names loaded from the configuration -- saved here as the
301 * cache file must be consulted before the directories are scanned,
302 * and those directives may occur in any order
303 */
304 FcStrSet *configDirs; /* directories to scan for fonts */
305 FcChar8 *cache; /* name of per-user cache file */
306 /*
307 * Set of allowed blank chars -- used to
308 * trim fonts of bogus glyphs
309 */
310 FcBlanks *blanks;
311 /*
312 * List of directories containing fonts,
313 * built by recursively scanning the set
314 * of configured directories
315 */
316 FcStrSet *fontDirs;
317 /*
318 * Names of all of the configuration files used
319 * to create this configuration
320 */
321 FcStrSet *configFiles; /* config files loaded */
322 /*
323 * Substitution instructions for patterns and fonts;
324 * maxObjects is used to allocate appropriate intermediate storage
325 * while performing a whole set of substitutions
326 */
327 FcSubst *substPattern; /* substitutions for patterns */
328 FcSubst *substFont; /* substitutions for fonts */
329 int maxObjects; /* maximum number of tests in all substs */
330 /*
331 * List of patterns used to control font file selection
332 */
333 FcStrSet *acceptGlobs;
334 FcStrSet *rejectGlobs;
335 FcFontSet *acceptPatterns;
336 FcFontSet *rejectPatterns;
337 /*
338 * The set of fonts loaded from the listed directories; the
339 * order within the set does not determine the font selection,
340 * except in the case of identical matches in which case earlier fonts
341 * match preferrentially
342 */
343 FcFontSet *fonts[FcSetApplication + 1];
344 /*
345 * Fontconfig can periodically rescan the system configuration
346 * and font directories. This rescanning occurs when font
347 * listing requests are made, but no more often than rescanInterval
348 * seconds apart.
349 */
350 time_t rescanTime; /* last time information was scanned */
351 int rescanInterval; /* interval between scans */
352};
353
354extern FcConfig *_fcConfig;
355
356typedef struct _FcCharMap FcCharMap;
357
358/* fcblanks.c */
359
360/* fccache.c */
361
362FcGlobalCache *
363FcGlobalCacheCreate (void);
364
365void
366FcGlobalCacheDestroy (FcGlobalCache *cache);
367
368FcBool
369FcGlobalCacheCheckTime (const FcChar8*file, FcGlobalCacheInfo *info);
370
371void
372FcGlobalCacheReferenced (FcGlobalCache *cache,
373 FcGlobalCacheInfo *info);
374
375void
376FcGlobalCacheReferenceSubdir (FcGlobalCache *cache,
377 const FcChar8 *dir);
378
379FcGlobalCacheDir *
380FcGlobalCacheDirGet (FcGlobalCache *cache,
381 const FcChar8 *dir,
382 int len,
383 FcBool create_missing);
384
385FcBool
386FcGlobalCacheScanDir (FcFontSet *set,
387 FcStrSet *dirs,
388 FcGlobalCache *cache,
389 const FcChar8 *dir,
390 FcConfig *config);
391
392FcGlobalCacheFile *
393FcGlobalCacheFileGet (FcGlobalCache *cache,
394 const FcChar8 *file,
395 int id,
396 int *count);
397
398
399void
400FcGlobalCacheLoad (FcGlobalCache *cache,
401 const FcChar8 *cache_file);
402
403FcBool
404FcGlobalCacheUpdate (FcGlobalCache *cache,
405 const FcChar8 *file,
406 int id,
407 const FcChar8 *name);
408
409FcBool
410FcGlobalCacheSave (FcGlobalCache *cache,
411 const FcChar8 *cache_file);
412
413FcBool
414FcDirCacheReadDir (FcFontSet *set,
415 FcStrSet *dirs,
416 const FcChar8 *dir,
417 FcConfig *config);
418
419FcBool
420FcDirCacheWriteDir (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir);
421
422/* fccfg.c */
423
424FcBool
425FcConfigAddConfigDir (FcConfig *config,
426 const FcChar8 *d);
427
428FcBool
429FcConfigAddFontDir (FcConfig *config,
430 const FcChar8 *d);
431
432FcBool
433FcConfigAddDir (FcConfig *config,
434 const FcChar8 *d);
435
436FcBool
437FcConfigAddConfigFile (FcConfig *config,
438 const FcChar8 *f);
439
440FcBool
441FcConfigSetCache (FcConfig *config,
442 const FcChar8 *c);
443
444FcBool
445FcConfigAddBlank (FcConfig *config,
446 FcChar32 blank);
447
448FcBool
449FcConfigAddEdit (FcConfig *config,
450 FcTest *test,
451 FcEdit *edit,
452 FcMatchKind kind);
453
454void
455FcConfigSetFonts (FcConfig *config,
456 FcFontSet *fonts,
457 FcSetName set);
458
459FcBool
460FcConfigCompareValue (const FcValue m,
461 FcOp op,
462 const FcValue v);
463
464FcBool
465FcConfigGlobAdd (FcConfig *config,
466 const FcChar8 *glob,
467 FcBool accept);
468
469FcBool
470FcConfigAcceptFilename (FcConfig *config,
471 const FcChar8 *filename);
472
473FcBool
474FcConfigPatternsAdd (FcConfig *config,
475 FcPattern *pattern,
476 FcBool accept);
477
478FcBool
479FcConfigAcceptFont (FcConfig *config,
480 const FcPattern *font);
481
482/* fccharset.c */
483FcCharSet *
484FcCharSetFreeze (FcCharSet *cs);
485
486void
487FcCharSetThawAll (void);
488
489FcBool
490FcNameUnparseCharSet (FcStrBuf *buf, const FcCharSet *c);
491
492FcCharSet *
493FcNameParseCharSet (FcChar8 *string);
494
495FcCharLeaf *
496FcCharSetFindLeafCreate (FcCharSet *fcs, FcChar32 ucs4);
497
498/* fcdbg.c */
499void
500FcValueListPrint (const FcValueList *l);
501
502void
503FcLangSetPrint (const FcLangSet *ls);
504
505void
506FcOpPrint (FcOp op);
507
508void
509FcTestPrint (const FcTest *test);
510
511void
512FcExprPrint (const FcExpr *expr);
513
514void
515FcEditPrint (const FcEdit *edit);
516
517void
518FcSubstPrint (const FcSubst *subst);
519
520int
521FcDebug (void);
522
523/* fcdir.c */
524
525FcBool
526FcFileIsDir (const FcChar8 *file);
527
528FcBool
529FcFileScanConfig (FcFontSet *set,
530 FcStrSet *dirs,
531 FcFileCache *cache,
532 FcBlanks *blanks,
533 const FcChar8 *file,
534 FcBool force,
535 FcConfig *config);
536
537FcBool
538FcDirScanConfig (FcFontSet *set,
539 FcStrSet *dirs,
540 FcFileCache *cache,
541 FcBlanks *blanks,
542 const FcChar8 *dir,
543 FcBool force,
544 FcConfig *config);
545
546/* fcfont.c */
547int
548FcFontDebug (void);
549
550/* fcfreetype.c */
551FcBool
552FcFreeTypeIsExclusiveLang (const FcChar8 *lang);
553
554FcBool
555FcFreeTypeHasLang (FcPattern *pattern, const FcChar8 *lang);
556
557FcChar32
558FcFreeTypeUcs4ToPrivate (FcChar32 ucs4, const FcCharMap *map);
559
560FcChar32
561FcFreeTypePrivateToUcs4 (FcChar32 private, const FcCharMap *map);
562
563const FcCharMap *
564FcFreeTypeGetPrivateMap (FT_Encoding encoding);
565
566/* fcfs.c */
567/* fcgram.y */
568int
569FcConfigparse (void);
570
571int
572FcConfigwrap (void);
573
574void
575FcConfigerror (char *fmt, ...);
576
577char *
578FcConfigSaveField (const char *field);
579
580FcTest *
581FcTestCreate (FcMatchKind kind,
582 FcQual qual,
583 const FcChar8 *field,
584 FcOp compare,
585 FcExpr *expr);
586
587void
588FcTestDestroy (FcTest *test);
589
590FcExpr *
591FcExprCreateInteger (int i);
592
593FcExpr *
594FcExprCreateDouble (double d);
595
596FcExpr *
597FcExprCreateString (const FcChar8 *s);
598
599FcExpr *
600FcExprCreateMatrix (const FcMatrix *m);
601
602FcExpr *
603FcExprCreateBool (FcBool b);
604
605FcExpr *
606FcExprCreateNil (void);
607
608FcExpr *
609FcExprCreateField (const char *field);
610
611FcExpr *
612FcExprCreateConst (const FcChar8 *constant);
613
614FcExpr *
615FcExprCreateOp (FcExpr *left, FcOp op, FcExpr *right);
616
617void
618FcExprDestroy (FcExpr *e);
619
620FcEdit *
621FcEditCreate (const char *field, FcOp op, FcExpr *expr, FcValueBinding binding);
622
623void
624FcEditDestroy (FcEdit *e);
625
626/* fcinit.c */
627
628void
629FcMemReport (void);
630
631void
632FcMemAlloc (int kind, int size);
633
634void
635FcMemFree (int kind, int size);
636
637/* fclang.c */
638FcLangSet *
639FcFreeTypeLangSet (const FcCharSet *charset,
640 const FcChar8 *exclusiveLang);
641
642FcLangResult
643FcLangCompare (const FcChar8 *s1, const FcChar8 *s2);
644
645const FcCharSet *
646FcCharSetForLang (const FcChar8 *lang);
647
648FcLangSet *
649FcLangSetPromote (const FcChar8 *lang);
650
651FcLangSet *
652FcNameParseLangSet (const FcChar8 *string);
653
654FcBool
655FcNameUnparseLangSet (FcStrBuf *buf, const FcLangSet *ls);
656
657/* fclist.c */
658
659FcBool
660FcListPatternMatchAny (const FcPattern *p,
661 const FcPattern *font);
662
663/* fcmatch.c */
664
665/* fcname.c */
666
667FcBool
668FcNameBool (FcChar8 *v, FcBool *result);
669
670/* fcpat.c */
671void
672FcValueListDestroy (FcValueList *l);
673
674FcPatternElt *
675FcPatternFindElt (const FcPattern *p, const char *object);
676
677FcPatternElt *
678FcPatternInsertElt (FcPattern *p, const char *object);
679
680FcBool
681FcPatternAddWithBinding (FcPattern *p,
682 const char *object,
683 FcValue value,
684 FcValueBinding binding,
685 FcBool append);
686
687FcPattern *
688FcPatternFreeze (FcPattern *p);
689
690void
691FcPatternThawAll (void);
692
693FcBool
694FcPatternAppend (FcPattern *p, FcPattern *s);
695
696const char *
697FcObjectStaticName (const char *name);
698
699/* fcrender.c */
700
701/* fcmatrix.c */
702
703extern const FcMatrix FcIdentityMatrix;
704
705void
706FcMatrixFree (FcMatrix *mat);
707
708/* fcstr.c */
709FcChar8 *
710FcStrPlus (const FcChar8 *s1, const FcChar8 *s2);
711
712void
713FcStrFree (FcChar8 *s);
714
715void
716FcStrBufInit (FcStrBuf *buf, FcChar8 *init, int size);
717
718void
719FcStrBufDestroy (FcStrBuf *buf);
720
721FcChar8 *
722FcStrBufDone (FcStrBuf *buf);
723
724FcBool
725FcStrBufChar (FcStrBuf *buf, FcChar8 c);
726
727FcBool
728FcStrBufString (FcStrBuf *buf, const FcChar8 *s);
729
730FcBool
731FcStrBufData (FcStrBuf *buf, const FcChar8 *s, int len);
732
733int
734FcStrCmpIgnoreBlanksAndCase (const FcChar8 *s1, const FcChar8 *s2);
735
736const FcChar8 *
737FcStrContainsIgnoreBlanksAndCase (const FcChar8 *s1, const FcChar8 *s2);
738
739const FcChar8 *
740FcStrContainsIgnoreCase (const FcChar8 *s1, const FcChar8 *s2);
741
742FcBool
743FcStrUsesHome (const FcChar8 *s);
744
745FcChar8 *
746FcStrLastSlash (const FcChar8 *path);
747
748#endif /* _FC_INT_H_ */