TTFont.h
1//========================================================================
2//
3// TTFont.h
4//
5// An X wrapper for the FreeType TrueType font rasterizer.
6//
7// Copyright 2001-2002 Glyph & Cog, LLC
8//
9//========================================================================
10
11#ifndef TTFONT_H
12#define TTFONT_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#if HAVE_FREETYPE_FREETYPE_H
23#include <freetype/freetype.h>
24#include <freetype/ftxpost.h>
25#else
26#include <freetype.h>
27#include <ftxpost.h>
28#endif
29#include "gtypes.h"
30#include "SFont.h"
31
32//------------------------------------------------------------------------
33
34class TTFontEngine: public SFontEngine {
35public:
36
37 TTFontEngine(Display *displayA, Visual *visualA, int depthA,
38 Colormap colormapA, GBool aaA);
39 GBool isOk() { return ok; }
40 virtual ~TTFontEngine();
41
42private:
43
44 TT_Engine engine;
45 GBool aa;
46 Gulong palette[5];
47 GBool ok;
48
49 friend class TTFontFile;
50 friend class TTFont;
51};
52
53//------------------------------------------------------------------------
54
55enum TTFontIndexMode {
56 ttFontModeUnicode,
57 ttFontModeCharCode,
58 ttFontModeCharCodeOffset,
59 ttFontModeCodeMap,
60 ttFontModeCIDToGIDMap
61};
62
63class TTFontFile: public SFontFile {
64public:
65
66 // 8-bit font, TrueType or Type 1/1C
67 TTFontFile(TTFontEngine *engineA, char *fontFileName,
68 char **fontEnc, GBool pdfFontHasEncoding);
69
70 // CID font, TrueType
71 TTFontFile(TTFontEngine *engineA, char *fontFileName,
72 Gushort *cidToGIDA, int cidToGIDLenA);
73
74 GBool isOk() { return ok; }
75 virtual ~TTFontFile();
76
77private:
78
79 TTFontEngine *engine;
80 TT_Face face;
81 TT_CharMap charMap;
82 TTFontIndexMode mode;
83 int charMapOffset;
84 Guchar *codeMap;
85 Gushort *cidToGID;
86 int cidToGIDLen;
87 GBool ok;
88
89 friend class TTFont;
90};
91
92//------------------------------------------------------------------------
93
94struct TTFontCacheTag {
95 Gushort code;
96 Gushort mru; // valid bit (0x8000) and MRU index
97};
98
99class TTFont: public SFont {
100public:
101
102 TTFont(TTFontFile *fontFileA, double *m);
103 GBool isOk() { return ok; }
104 virtual ~TTFont();
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
109private:
110
111 GBool getGlyphPixmap(CharCode c, Unicode u);
112
113 TTFontFile *fontFile;
114 TT_Instance instance;
115 TT_Glyph glyph;
116 TT_Raster_Map ras;
117 XImage *image;
118 TT_Matrix matrix;
119 TT_F26Dot6 xOffset, yOffset;
120 Guchar *cache; // glyph pixmap cache
121 TTFontCacheTag *cacheTags; // cache tags, i.e., char codes
122 int cacheSets; // number of sets in cache
123 int cacheAssoc; // cache associativity (glyphs per set)
124 GBool ok;
125};
126
127#endif // !FREETYPE2 && (HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H)
128
129#endif