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