Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/pdf/xpdf/FTFont.h
blob: 52bc149b180a3d8f74fc7763ae7f6441b3bc1173 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//========================================================================
//
// FTFont.h
//
// An X wrapper for the FreeType font rasterizer.
//
// Copyright 2001-2003 Glyph & Cog, LLC
//
//========================================================================

#ifndef FTFONT_H
#define FTFONT_H

#include <aconf.h>

#if FREETYPE2 && (HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H)

#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif

#include <freetype/freetype.h>
#include "CharTypes.h"
#include "SFont.h"

//------------------------------------------------------------------------

class FTFontEngine: public SFontEngine {
public:

  FTFontEngine(Display *displayA, Visual *visualA, int depthA,
	       Colormap colormapA, GBool aaA);
  GBool isOk() { return ok; }
  virtual ~FTFontEngine();

private:

  FT_Library lib;
  GBool aa;
  Gulong palette[5];
  GBool ok;

  friend class FTFontFile;
  friend class FTFont;
};

//------------------------------------------------------------------------

enum FTFontIndexMode {
  ftFontModeUnicode,
  ftFontModeCharCode,
  ftFontModeCharCodeOffset,
  ftFontModeCodeMap,
  ftFontModeCodeMapDirect,
  ftFontModeCIDToGIDMap,
  ftFontModeCFFCharset,
  ftFontModeCID
};

class FTFontFile: public SFontFile {
public:

  // 8-bit font, TrueType or Type 1/1C
  FTFontFile(FTFontEngine *engineA, char *fontFileName,
	     char **fontEnc, GBool pdfFontHasEncoding,
	     GBool pdfFontIsSymbolic);

  // CID font, TrueType
  FTFontFile(FTFontEngine *engineA, char *fontFileName,
	     Gushort *cidToGIDA, int cidToGIDLenA, GBool embedded);

  // CID font, Type 0C (CFF)
  FTFontFile(FTFontEngine *engineA, char *fontFileName,
	     GBool embedded);

  GBool isOk() { return ok; }
  virtual ~FTFontFile();

private:

  FTFontEngine *engine;
  FT_Face face;
  FTFontIndexMode mode;
  int charMapOffset;
  Guint *codeMap;
  Gushort *cidToGID;
  int cidToGIDLen;
  GBool ok;

  friend class FTFont;
};

//------------------------------------------------------------------------

struct FTFontCacheTag {
  Gushort code;
  Gushort mru;			// valid bit (0x8000) and MRU index
  int x, y, w, h;		// offset and size of glyph
};

class FTFont: public SFont {
public:

  FTFont(FTFontFile *fontFileA, double *m);
  GBool isOk() { return ok; }
  virtual ~FTFont();
  virtual GBool drawChar(Drawable d, int w, int h, GC gc,
			 int x, int y, int r, int g, int b,
			 CharCode c, Unicode u);
  virtual GBool getCharPath(CharCode c, Unicode u, GfxState *state);

private:

  Guchar *getGlyphPixmap(CharCode c, Unicode u,
			 int *x, int *y, int *w, int *h,
			 GBool *tempBitmap);
  static int charPathMoveTo(FT_Vector *pt, void *state);
  static int charPathLineTo(FT_Vector *pt, void *state);
  static int charPathConicTo(FT_Vector *ctrl, FT_Vector *pt, void *state);
  static int charPathCubicTo(FT_Vector *ctrl1, FT_Vector *ctrl2,
			     FT_Vector *pt, void *state);
  FT_UInt getGlyphIndex(CharCode c, Unicode u);

  FTFontFile *fontFile;
  FT_Size sizeObj;
  XImage *image;
  FT_Matrix matrix;
  int glyphW, glyphH;		// size of glyph pixmaps
  int glyphSize;		// size of glyph pixmaps, in bytes
  Guchar *cache;		// glyph pixmap cache
  FTFontCacheTag *cacheTags;	// cache tags, i.e., char codes
  int cacheSets;		// number of sets in cache
  int cacheAssoc;		// cache associativity (glyphs per set)
  GBool ok;
};

#endif // FREETYPE2 && (HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H)

#endif