1
//========================================================================
5
// Copyright 1996-2003 Glyph & Cog, LLC
7
//========================================================================
14
#ifdef USE_GCC_PRAGMAS
21
#include "CharTypes.h"
25
class CharCodeToUnicode;
27
struct GfxFontCIDWidths;
29
//------------------------------------------------------------------------
31
//------------------------------------------------------------------------
50
//------------------------------------------------------------------------
52
//------------------------------------------------------------------------
54
struct GfxFontCIDWidthExcep {
55
CID first; // this record applies to
56
CID last; // CIDs <first>..<last>
57
double width; // char width
60
struct GfxFontCIDWidthExcepV {
61
CID first; // this record applies to
62
CID last; // CIDs <first>..<last>
63
double height; // char height
64
double vx, vy; // origin position
67
struct GfxFontCIDWidths {
68
double defWidth; // default char width
69
double defHeight; // default char height
70
double defVY; // default origin position
71
GfxFontCIDWidthExcep *exceps; // exceptions
72
int nExceps; // number of valid entries in exceps
73
GfxFontCIDWidthExcepV * // exceptions for vertical font
75
int nExcepsV; // number of valid entries in excepsV
78
//------------------------------------------------------------------------
80
//------------------------------------------------------------------------
82
#define fontFixedWidth (1 << 0)
83
#define fontSerif (1 << 1)
84
#define fontSymbolic (1 << 2)
85
#define fontItalic (1 << 6)
86
#define fontBold (1 << 18)
91
// Build a GfxFont object.
92
static GfxFont *makeFont(XRef *xref, char *tagA, Ref idA, Dict *fontDict);
94
GfxFont(char *tagA, Ref idA, GString *nameA);
98
GBool isOk() { return ok; }
101
GString *getTag() { return tag; }
103
// Get font dictionary ID.
104
Ref *getID() { return &id; }
106
// Does this font match the tag?
107
GBool matches(char *tagA) { return !tag->cmp(tagA); }
109
// Get base font name.
110
GString *getName() { return name; }
112
// Get the original font name (ignornig any munging that might have
113
// been done to map to a canonical Base-14 font name).
114
GString *getOrigName() { return origName; }
117
GfxFontType getType() { return type; }
118
virtual GBool isCIDFont() { return gFalse; }
120
// Get embedded font ID, i.e., a ref for the font file stream.
121
// Returns false if there is no embedded font.
122
GBool getEmbeddedFontID(Ref *embID)
123
{ *embID = embFontID; return embFontID.num >= 0; }
125
// Get the PostScript font name for the embedded font. Returns
126
// NULL if there is no embedded font.
127
GString *getEmbeddedFontName() { return embFontName; }
129
// Get the name of the external font file. Returns NULL if there
130
// is no external font file.
131
GString *getExtFontFile() { return extFontFile; }
133
// Get font descriptor flags.
134
int getFlags() { return flags; }
135
GBool isFixedWidth() { return flags & fontFixedWidth; }
136
GBool isSerif() { return flags & fontSerif; }
137
GBool isSymbolic() { return flags & fontSymbolic; }
138
GBool isItalic() { return flags & fontItalic; }
139
GBool isBold() { return flags & fontBold; }
141
// Return the font matrix.
142
double *getFontMatrix() { return fontMat; }
144
// Return the font bounding box.
145
double *getFontBBox() { return fontBBox; }
147
// Return the ascent and descent values.
148
double getAscent() { return ascent; }
149
double getDescent() { return descent; }
151
// Return the writing mode (0=horizontal, 1=vertical).
152
virtual int getWMode() { return 0; }
154
// Read an external or embedded font file into a buffer.
155
char *readExtFontFile(int *len);
156
char *readEmbFontFile(XRef *xref, int *len);
158
// Get the next char from a string <s> of <len> bytes, returning the
159
// char <code>, its Unicode mapping <u>, its displacement vector
160
// (<dx>, <dy>), and its origin offset vector (<ox>, <oy>). <uSize>
161
// is the number of entries available in <u>, and <uLen> is set to
162
// the number actually used. Returns the number of bytes used by
164
virtual int getNextChar(char *s, int len, CharCode *code,
165
Unicode *u, int uSize, int *uLen,
166
double *dx, double *dy, double *ox, double *oy) = 0;
170
void readFontDescriptor(XRef *xref, Dict *fontDict);
171
CharCodeToUnicode *readToUnicodeCMap(Dict *fontDict, int nBits,
172
CharCodeToUnicode *ctu);
173
void findExtFontFile();
175
GString *tag; // PDF font tag
176
Ref id; // reference (used as unique ID)
177
GString *name; // font name
178
GString *origName; // original font name
179
GfxFontType type; // type of font
180
int flags; // font descriptor flags
181
GString *embFontName; // name of embedded font
182
Ref embFontID; // ref to embedded font file stream
183
GString *extFontFile; // external font file name
184
double fontMat[6]; // font matrix (Type 3 only)
185
double fontBBox[4]; // font bounding box (Type 3 only)
186
double missingWidth; // "default" width
187
double ascent; // max height above baseline
188
double descent; // max depth below baseline
192
//------------------------------------------------------------------------
194
//------------------------------------------------------------------------
196
class Gfx8BitFont: public GfxFont {
199
Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GString *nameA,
200
GfxFontType typeA, Dict *fontDict);
202
virtual ~Gfx8BitFont();
204
virtual int getNextChar(char *s, int len, CharCode *code,
205
Unicode *u, int uSize, int *uLen,
206
double *dx, double *dy, double *ox, double *oy);
208
// Return the encoding.
209
char **getEncoding() { return enc; }
211
// Return the Unicode map.
212
CharCodeToUnicode *getToUnicode();
214
// Return the character name associated with <code>.
215
char *getCharName(int code) { return enc[code]; }
217
// Returns true if the PDF font specified an encoding.
218
GBool getHasEncoding() { return hasEncoding; }
220
// Returns true if the PDF font specified MacRomanEncoding.
221
GBool getUsesMacRomanEnc() { return usesMacRomanEnc; }
223
// Get width of a character.
224
double getWidth(Guchar c) { return widths[c]; }
226
// Return a char code-to-GID mapping for the provided font file.
227
// (This is only useful for TrueType fonts.)
228
Gushort *getCodeToGIDMap(FoFiTrueType *ff);
230
// Return the Type 3 CharProc dictionary, or NULL if none.
231
Dict *getCharProcs();
233
// Return the Type 3 CharProc for the character associated with <code>.
234
Object *getCharProc(int code, Object *proc);
236
// Return the Type 3 Resources dictionary, or NULL if none.
237
Dict *getResources();
241
char *enc[256]; // char code --> char name
242
char encFree[256]; // boolean for each char name: if set,
243
// the string is malloc'ed
244
CharCodeToUnicode *ctu; // char code --> Unicode
246
GBool usesMacRomanEnc;
247
double widths[256]; // character widths
248
Object charProcs; // Type 3 CharProcs dictionary
249
Object resources; // Type 3 Resources dictionary
252
//------------------------------------------------------------------------
254
//------------------------------------------------------------------------
256
class GfxCIDFont: public GfxFont {
259
GfxCIDFont(XRef *xref, char *tagA, Ref idA, GString *nameA,
262
virtual ~GfxCIDFont();
264
virtual GBool isCIDFont() { return gTrue; }
266
virtual int getNextChar(char *s, int len, CharCode *code,
267
Unicode *u, int uSize, int *uLen,
268
double *dx, double *dy, double *ox, double *oy);
270
// Return the writing mode (0=horizontal, 1=vertical).
271
virtual int getWMode();
273
// Return the Unicode map.
274
CharCodeToUnicode *getToUnicode();
276
// Get the collection name (<registry>-<ordering>).
277
GString *getCollection();
279
// Return the CID-to-GID mapping table. These should only be called
280
// if type is fontCIDType2.
281
Gushort *getCIDToGID() { return cidToGID; }
282
int getCIDToGIDLen() { return cidToGIDLen; }
286
CMap *cMap; // char code --> CID
287
CharCodeToUnicode *ctu; // CID --> Unicode
288
GfxFontCIDWidths widths; // character widths
289
Gushort *cidToGID; // CID --> GID mapping (for embedded
294
//------------------------------------------------------------------------
296
//------------------------------------------------------------------------
301
// Build the font dictionary, given the PDF font dictionary.
302
GfxFontDict(XRef *xref, Ref *fontDictRef, Dict *fontDict);
307
// Get the specified font.
308
GfxFont *lookup(char *tag);
311
int getNumFonts() { return numFonts; }
312
GfxFont *getFont(int i) { return fonts[i]; }
316
GfxFont **fonts; // list of fonts
317
int numFonts; // number of fonts