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