filters

FTFont.h
1//========================================================================
2//
3// FTFont.h
4//
5// An X wrapper for the FreeType font rasterizer.
6//
7// Copyright 2001-2002 Glyph & Cog, LLC
8//
9//========================================================================
10
11#ifndef FTFONT_H
12#define FTFONT_H
13
14#include <aconf.h>
15
16#if FREETYPE2 && (HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H)
17
18#ifdef USE_GCC_PRAGMAS
19#pragma interface
20#endif
21
22#include <freetype/freetype.h>
23#include "CharTypes.h"
24#include "SFont.h"
25
26//------------------------------------------------------------------------
27
28class FTFontEngine: public SFontEngine {
29public:
30
31 FTFontEngine(Display *displayA, Visual *visualA, int depthA,
32 Colormap colormapA, GBool aaA);
33 GBool isOk() { return ok; }
34 virtual ~FTFontEngine();
35
36private:
37
38 FT_Library lib;
39 GBool aa;
40 Gulong palette[5];
41 GBool ok;
42
43 friend class FTFontFile;
44 friend class FTFont;
45};
46
47//------------------------------------------------------------------------
48
49enum FTFontIndexMode {
50 ftFontModeUnicode,
51 ftFontModeCharCode,
52 ftFontModeCharCodeOffset,
53 ftFontModeCodeMap,
54 ftFontModeCodeMapDirect,
55 ftFontModeCIDToGIDMap,
56 ftFontModeCFFCharset
57};
58
59class FTFontFile: public SFontFile {
60public:
61
62 // 8-bit font, TrueType or Type 1/1C
63 FTFontFile(FTFontEngine *engineA, char *fontFileName,
64 char **fontEnc, GBool pdfFontHasEncoding);
65
66 // CID font, TrueType
67 FTFontFile(FTFontEngine *engineA, char *fontFileName,
68 Gushort *cidToGIDA, int cidToGIDLenA);
69
70 // CID font, Type 0C (CFF)
71 FTFontFile(FTFontEngine *engineA, char *fontFileName);
72
73 GBool isOk() { return ok; }
74 virtual ~FTFontFile();
75
76private:
77
78 FTFontEngine *engine;
79 FT_Face face;
80 FTFontIndexMode mode;
81 int charMapOffset;
82 Guint *codeMap;
83 Gushort *cidToGID;
84 int cidToGIDLen;
85 GBool ok;
86
87 friend class FTFont;
88};
89
90//------------------------------------------------------------------------
91
92struct FTFontCacheTag {
93 Gushort code;
94 Gushort mru; // valid bit (0x8000) and MRU index
95 int x, y, w, h; // offset and size of glyph
96};
97
98class FTFont: public SFont {
99public:
100
101 FTFont(FTFontFile *fontFileA, double *m);
102 GBool isOk() { return ok; }
103 virtual ~FTFont();
104 virtual GBool drawChar(Drawable d, int w, int h, GC gc,
105 int x, int y, int r, int g, int b,
106 CharCode c, Unicode u);
107 virtual GBool getCharPath(CharCode c, Unicode u, GfxState *state);
108
109private:
110
111 Guchar *getGlyphPixmap(CharCode c, Unicode u,
112 int *x, int *y, int *w, int *h);
113 static int charPathMoveTo(FT_Vector *pt, void *state);
114 static int charPathLineTo(FT_Vector *pt, void *state);
115 static int charPathConicTo(FT_Vector *ctrl, FT_Vector *pt, void *state);
116 static int charPathCubicTo(FT_Vector *ctrl1, FT_Vector *ctrl2,
117 FT_Vector *pt, void *state);
118 FT_UInt getGlyphIndex(CharCode c, Unicode u);
119
120 FTFontFile *fontFile;
121 FT_Size sizeObj;
122 XImage *image;
123 FT_Matrix matrix;
124 int glyphW, glyphH; // size of glyph pixmaps
125 int glyphSize; // size of glyph pixmaps, in bytes
126 Guchar *cache; // glyph pixmap cache
127 FTFontCacheTag *cacheTags; // cache tags, i.e., char codes
128 int cacheSets; // number of sets in cache
129 int cacheAssoc; // cache associativity (glyphs per set)
130 GBool ok;
131};
132
133#endif // FREETYPE2 && (HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H)
134
135#endif