]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/FTFont.h
8da5558219e30bcf1a1cca2e627150646f7b7a46
[evince.git] / pdf / xpdf / FTFont.h
1 //========================================================================
2 //
3 // FTFont.h
4 //
5 // An X wrapper for the FreeType font rasterizer.
6 //
7 // Copyright 2001-2003 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
28 class FTFontEngine: public SFontEngine {
29 public:
30
31   FTFontEngine(Display *displayA, Visual *visualA, int depthA,
32                Colormap colormapA, GBool aaA);
33   GBool isOk() { return ok; }
34   virtual ~FTFontEngine();
35
36 private:
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
49 enum FTFontIndexMode {
50   ftFontModeUnicode,
51   ftFontModeCodeMapDirect,
52   ftFontModeCIDToGIDMap,
53   ftFontModeCFFCharset,
54   ftFontModeCID
55 };
56
57 class FTFontFile: public SFontFile {
58 public:
59
60   // 8-bit font, TrueType or Type 1/1C
61   FTFontFile(FTFontEngine *engineA, char *fontFileName,
62              char **fontEnc, Gushort *codeToGID);
63
64   // CID font, TrueType
65   FTFontFile(FTFontEngine *engineA, char *fontFileName,
66              Gushort *cidToGIDA, int cidToGIDLenA, GBool embedded);
67
68   // CID font, Type 0C (CFF)
69   FTFontFile(FTFontEngine *engineA, char *fontFileName,
70              GBool embedded);
71
72   GBool isOk() { return ok; }
73   virtual ~FTFontFile();
74
75 private:
76
77   FTFontEngine *engine;
78   FT_Face face;
79   FTFontIndexMode mode;
80   Guint *codeMap;
81   Gushort *cidToGID;
82   int cidToGIDLen;
83   GBool ok;
84
85   friend class FTFont;
86 };
87
88 //------------------------------------------------------------------------
89
90 struct FTFontCacheTag {
91   Gushort code;
92   Gushort mru;                  // valid bit (0x8000) and MRU index
93   int x, y, w, h;               // offset and size of glyph
94 };
95
96 class FTFont: public SFont {
97 public:
98
99   FTFont(FTFontFile *fontFileA, double *m);
100   GBool isOk() { return ok; }
101   virtual ~FTFont();
102   virtual GBool drawChar(Drawable d, int w, int h, GC gc,
103                          int x, int y, int r, int g, int b,
104                          CharCode c, Unicode u);
105   virtual GBool getCharPath(CharCode c, Unicode u, GfxState *state);
106
107 private:
108
109   Guchar *getGlyphPixmap(CharCode c, Unicode u,
110                          int *x, int *y, int *w, int *h,
111                          GBool *tempBitmap);
112   static int charPathMoveTo(FT_Vector *pt, void *state);
113   static int charPathLineTo(FT_Vector *pt, void *state);
114   static int charPathConicTo(FT_Vector *ctrl, FT_Vector *pt, void *state);
115   static int charPathCubicTo(FT_Vector *ctrl1, FT_Vector *ctrl2,
116                              FT_Vector *pt, void *state);
117   FT_UInt getGlyphIndex(CharCode c, Unicode u);
118
119   FTFontFile *fontFile;
120   FT_Size sizeObj;
121   XImage *image;
122   FT_Matrix matrix;
123   int glyphW, glyphH;           // size of glyph pixmaps
124   int glyphSize;                // size of glyph pixmaps, in bytes
125   Guchar *cache;                // glyph pixmap cache
126   FTFontCacheTag *cacheTags;    // cache tags, i.e., char codes
127   int cacheSets;                // number of sets in cache
128   int cacheAssoc;               // cache associativity (glyphs per set)
129   GBool ok;
130 };
131
132 #endif // FREETYPE2 && (HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H)
133
134 #endif