2
//========================================================================
6
// Copyright 1996-2002 Glyph & Cog, LLC
8
//========================================================================
15
#ifdef USE_GCC_PRAGMAS
22
#include "chartypes.h"
26
class CharCodeToUnicode;
27
struct GfxFontCIDWidths;
29
//------------------------------------------------------------------------
31
//------------------------------------------------------------------------
46
//------------------------------------------------------------------------
48
//------------------------------------------------------------------------
50
struct GfxFontCIDWidthExcep {
51
CID first; // this record applies to
52
CID last; // CIDs <first>..<last>
53
double width; // char width
56
struct GfxFontCIDWidthExcepV {
57
CID first; // this record applies to
58
CID last; // CIDs <first>..<last>
59
double height; // char height
60
double vx, vy; // origin position
63
struct GfxFontCIDWidths {
64
double defWidth; // default char width
65
double defHeight; // default char height
66
double defVY; // default origin position
67
GfxFontCIDWidthExcep *exceps; // exceptions
68
int nExceps; // number of valid entries in exceps
69
GfxFontCIDWidthExcepV * // exceptions for vertical font
71
int nExcepsV; // number of valid entries in excepsV
74
//------------------------------------------------------------------------
76
//------------------------------------------------------------------------
78
#define fontFixedWidth (1 << 0)
79
#define fontSerif (1 << 1)
80
#define fontSymbolic (1 << 2)
81
#define fontItalic (1 << 6)
82
#define fontBold (1 << 18)
87
// Build a GfxFont object.
88
static GfxFont *makeFont(XRef *xref, char *tagA, Ref idA, Dict *fontDict);
90
GfxFont(char *tagA, Ref idA, GString *nameA);
94
GBool isOk() { return ok; }
97
GString *getTag() { return tag; }
99
// Get font dictionary ID.
100
Ref *getID() { return &id; }
102
// Does this font match the tag?
103
GBool matches(char *tagA) { return !tag->cmp(tagA); }
105
// Get base font name.
106
GString *getName() { return name; }
109
GfxFontType getType() { return type; }
110
virtual GBool isCIDFont() { return gFalse; }
112
// Get embedded font ID, i.e., a ref for the font file stream.
113
// Returns false if there is no embedded font.
114
GBool getEmbeddedFontID(Ref *embID)
115
{ *embID = embFontID; return embFontID.num >= 0; }
117
// Get the PostScript font name for the embedded font. Returns
118
// NULL if there is no embedded font.
119
GString *getEmbeddedFontName() { return embFontName; }
121
// Get the name of the external font file. Returns NULL if there
122
// is no external font file.
123
GString *getExtFontFile() { return extFontFile; }
125
// Get font descriptor flags.
126
GBool isFixedWidth() { return flags & fontFixedWidth; }
127
GBool isSerif() { return flags & fontSerif; }
128
GBool isSymbolic() { return flags & fontSymbolic; }
129
GBool isItalic() { return flags & fontItalic; }
130
GBool isBold() { return flags & fontBold; }
132
// Return the font matrix.
133
double *getFontMatrix() { return fontMat; }
135
// Return the font bounding box.
136
double *getFontBBox() { return fontBBox; }
138
// Return the ascent and descent values.
139
double getAscent() { return ascent; }
140
double getDescent() { return descent; }
142
// Return the writing mode (0=horizontal, 1=vertical).
143
virtual int getWMode() { return 0; }
145
// Read an external or embedded font file into a buffer.
146
char *readExtFontFile(int *len);
147
char *readEmbFontFile(XRef *xref, int *len);
149
// Get the next char from a string <s> of <len> bytes, returning the
150
// char <code>, its Unicode mapping <u>, its displacement vector
151
// (<dx>, <dy>), and its origin offset vector (<ox>, <oy>). <uSize>
152
// is the number of entries available in <u>, and <uLen> is set to
153
// the number actually used. Returns the number of bytes used by
155
virtual int getNextChar(char *s, int len, CharCode *code,
156
Unicode *u, int uSize, int *uLen,
157
double *dx, double *dy, double *ox, double *oy) = 0;
161
void readFontDescriptor(XRef *xref, Dict *fontDict);
162
CharCodeToUnicode *readToUnicodeCMap(Dict *fontDict, int nBits);
163
void findExtFontFile();
165
GString *tag; // PDF font tag
166
Ref id; // reference (used as unique ID)
167
GString *name; // font name
168
GfxFontType type; // type of font
169
int flags; // font descriptor flags
170
GString *embFontName; // name of embedded font
171
Ref embFontID; // ref to embedded font file stream
172
GString *extFontFile; // external font file name
173
double fontMat[6]; // font matrix (Type 3 only)
174
double fontBBox[4]; // font bounding box (Type 3 only)
175
double missingWidth; // "default" width
176
double ascent; // max height above baseline
177
double descent; // max depth below baseline
181
//------------------------------------------------------------------------
183
//------------------------------------------------------------------------
185
class Gfx8BitFont: public GfxFont {
188
Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GString *nameA,
189
GfxFontType typeA, Dict *fontDict);
191
virtual ~Gfx8BitFont();
193
virtual int getNextChar(char *s, int len, CharCode *code,
194
Unicode *u, int uSize, int *uLen,
195
double *dx, double *dy, double *ox, double *oy);
197
// Return the encoding.
198
char **getEncoding() { return enc; }
200
// Return the Unicode map.
201
CharCodeToUnicode *getToUnicode();
203
// Return the character name associated with <code>.
204
char *getCharName(int code) { return enc[code]; }
206
// Returns true if the PDF font specified an encoding.
207
GBool getHasEncoding() { return hasEncoding; }
209
// Get width of a character or string.
210
double getWidth(Guchar c) { return widths[c]; }
212
// Return the Type 3 CharProc dictionary, or NULL if none.
213
Dict *getCharProcs();
215
// Return the Type 3 CharProc for the character associated with <code>.
216
Object *getCharProc(int code, Object *proc);
218
// Return the Type 3 Resources dictionary, or NULL if none.
219
Dict *getResources();
223
char *enc[256]; // char code --> char name
224
char encFree[256]; // boolean for each char name: if set,
225
// the string is malloc'ed
226
CharCodeToUnicode *ctu; // char code --> Unicode
228
double widths[256]; // character widths
229
Object charProcs; // Type 3 CharProcs dictionary
230
Object resources; // Type 3 Resources dictionary
233
//------------------------------------------------------------------------
235
//------------------------------------------------------------------------
237
class GfxCIDFont: public GfxFont {
240
GfxCIDFont(XRef *xref, char *tagA, Ref idA, GString *nameA,
243
virtual ~GfxCIDFont();
245
virtual GBool isCIDFont() { return gTrue; }
247
virtual int getNextChar(char *s, int len, CharCode *code,
248
Unicode *u, int uSize, int *uLen,
249
double *dx, double *dy, double *ox, double *oy);
251
// Return the writing mode (0=horizontal, 1=vertical).
252
virtual int getWMode();
254
// Return the Unicode map.
255
CharCodeToUnicode *getToUnicode();
257
// Get the collection name (<registry>-<ordering>).
258
GString *getCollection();
260
// Return the CID-to-GID mapping table. These should only be called
261
// if type is fontCIDType2.
262
Gushort *getCIDToGID() { return cidToGID; }
263
int getCIDToGIDLen() { return cidToGIDLen; }
267
CMap *cMap; // char code --> CID
268
CharCodeToUnicode *ctu; // CID --> Unicode
269
GfxFontCIDWidths widths; // character widths
270
Gushort *cidToGID; // CID --> GID mapping (for embedded
275
//------------------------------------------------------------------------
277
//------------------------------------------------------------------------
282
// Build the font dictionary, given the PDF font dictionary.
283
GfxFontDict(XRef *xref, Dict *fontDict);
288
// Get the specified font.
289
GfxFont *lookup(char *tag);
292
int getNumFonts() { return numFonts; }
293
GfxFont *getFont(int i) { return fonts[i]; }
297
GfxFont **fonts; // list of fonts
298
int numFonts; // number of fonts