~ubuntu-branches/ubuntu/wily/luatex/wily

« back to all changes in this revision

Viewing changes to source/libs/xpdf/xpdf-3.02/xpdf/GfxFont.h

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2010-04-29 00:47:19 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20100429004719-o42etkqe90n97b9e
Tags: 0.60.1-1
* new upstream release, adapt build-script patch
* disable patch: upstream-epstopdf_cc_no_xpdf_patching, included upstream
* disable patch: libpoppler-0.12, not needed anymore

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//========================================================================
 
2
//
 
3
// GfxFont.h
 
4
//
 
5
// Copyright 1996-2003 Glyph & Cog, LLC
 
6
//
 
7
//========================================================================
 
8
 
 
9
#ifndef GFXFONT_H
 
10
#define GFXFONT_H
 
11
 
 
12
#include <aconf.h>
 
13
 
 
14
#ifdef USE_GCC_PRAGMAS
 
15
#pragma interface
 
16
#endif
 
17
 
 
18
#include "gtypes.h"
 
19
#include "GString.h"
 
20
#include "Object.h"
 
21
#include "CharTypes.h"
 
22
 
 
23
class Dict;
 
24
class CMap;
 
25
class CharCodeToUnicode;
 
26
class FoFiTrueType;
 
27
struct GfxFontCIDWidths;
 
28
 
 
29
//------------------------------------------------------------------------
 
30
// GfxFontType
 
31
//------------------------------------------------------------------------
 
32
 
 
33
enum GfxFontType {
 
34
  //----- Gfx8BitFont
 
35
  fontUnknownType,
 
36
  fontType1,
 
37
  fontType1C,
 
38
  fontType1COT,
 
39
  fontType3,
 
40
  fontTrueType,
 
41
  fontTrueTypeOT,
 
42
  //----- GfxCIDFont
 
43
  fontCIDType0,
 
44
  fontCIDType0C,
 
45
  fontCIDType0COT,
 
46
  fontCIDType2,
 
47
  fontCIDType2OT
 
48
};
 
49
 
 
50
//------------------------------------------------------------------------
 
51
// GfxFontCIDWidths
 
52
//------------------------------------------------------------------------
 
53
 
 
54
struct GfxFontCIDWidthExcep {
 
55
  CID first;                    // this record applies to
 
56
  CID last;                     //   CIDs <first>..<last>
 
57
  double width;                 // char width
 
58
};
 
59
 
 
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
 
65
};
 
66
 
 
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
 
74
    excepsV;
 
75
  int nExcepsV;                 // number of valid entries in excepsV
 
76
};
 
77
 
 
78
//------------------------------------------------------------------------
 
79
// GfxFont
 
80
//------------------------------------------------------------------------
 
81
 
 
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)
 
87
 
 
88
class GfxFont {
 
89
public:
 
90
 
 
91
  // Build a GfxFont object.
 
92
  static GfxFont *makeFont(XRef *xref, char *tagA, Ref idA, Dict *fontDict);
 
93
 
 
94
  GfxFont(char *tagA, Ref idA, GString *nameA);
 
95
 
 
96
  virtual ~GfxFont();
 
97
 
 
98
  GBool isOk() { return ok; }
 
99
 
 
100
  // Get font tag.
 
101
  GString *getTag() { return tag; }
 
102
 
 
103
  // Get font dictionary ID.
 
104
  Ref *getID() { return &id; }
 
105
 
 
106
  // Does this font match the tag?
 
107
  GBool matches(char *tagA) { return !tag->cmp(tagA); }
 
108
 
 
109
  // Get base font name.
 
110
  GString *getName() { return name; }
 
111
 
 
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; }
 
115
 
 
116
  // Get font type.
 
117
  GfxFontType getType() { return type; }
 
118
  virtual GBool isCIDFont() { return gFalse; }
 
119
 
 
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; }
 
124
 
 
125
  // Get the PostScript font name for the embedded font.  Returns
 
126
  // NULL if there is no embedded font.
 
127
  GString *getEmbeddedFontName() { return embFontName; }
 
128
 
 
129
  // Get the name of the external font file.  Returns NULL if there
 
130
  // is no external font file.
 
131
  GString *getExtFontFile() { return extFontFile; }
 
132
 
 
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; }
 
140
 
 
141
  // Return the font matrix.
 
142
  double *getFontMatrix() { return fontMat; }
 
143
 
 
144
  // Return the font bounding box.
 
145
  double *getFontBBox() { return fontBBox; }
 
146
 
 
147
  // Return the ascent and descent values.
 
148
  double getAscent() { return ascent; }
 
149
  double getDescent() { return descent; }
 
150
 
 
151
  // Return the writing mode (0=horizontal, 1=vertical).
 
152
  virtual int getWMode() { return 0; }
 
153
 
 
154
  // Read an external or embedded font file into a buffer.
 
155
  char *readExtFontFile(int *len);
 
156
  char *readEmbFontFile(XRef *xref, int *len);
 
157
 
 
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
 
163
  // the char code.
 
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;
 
167
 
 
168
protected:
 
169
 
 
170
  void readFontDescriptor(XRef *xref, Dict *fontDict);
 
171
  CharCodeToUnicode *readToUnicodeCMap(Dict *fontDict, int nBits,
 
172
                                       CharCodeToUnicode *ctu);
 
173
  void findExtFontFile();
 
174
 
 
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
 
189
  GBool ok;
 
190
};
 
191
 
 
192
//------------------------------------------------------------------------
 
193
// Gfx8BitFont
 
194
//------------------------------------------------------------------------
 
195
 
 
196
class Gfx8BitFont: public GfxFont {
 
197
public:
 
198
 
 
199
  Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GString *nameA,
 
200
              GfxFontType typeA, Dict *fontDict);
 
201
 
 
202
  virtual ~Gfx8BitFont();
 
203
 
 
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);
 
207
 
 
208
  // Return the encoding.
 
209
  char **getEncoding() { return enc; }
 
210
 
 
211
  // Return the Unicode map.
 
212
  CharCodeToUnicode *getToUnicode();
 
213
 
 
214
  // Return the character name associated with <code>.
 
215
  char *getCharName(int code) { return enc[code]; }
 
216
 
 
217
  // Returns true if the PDF font specified an encoding.
 
218
  GBool getHasEncoding() { return hasEncoding; }
 
219
 
 
220
  // Returns true if the PDF font specified MacRomanEncoding.
 
221
  GBool getUsesMacRomanEnc() { return usesMacRomanEnc; }
 
222
 
 
223
  // Get width of a character.
 
224
  double getWidth(Guchar c) { return widths[c]; }
 
225
 
 
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);
 
229
 
 
230
  // Return the Type 3 CharProc dictionary, or NULL if none.
 
231
  Dict *getCharProcs();
 
232
 
 
233
  // Return the Type 3 CharProc for the character associated with <code>.
 
234
  Object *getCharProc(int code, Object *proc);
 
235
 
 
236
  // Return the Type 3 Resources dictionary, or NULL if none.
 
237
  Dict *getResources();
 
238
 
 
239
private:
 
240
 
 
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
 
245
  GBool hasEncoding;
 
246
  GBool usesMacRomanEnc;
 
247
  double widths[256];           // character widths
 
248
  Object charProcs;             // Type 3 CharProcs dictionary
 
249
  Object resources;             // Type 3 Resources dictionary
 
250
};
 
251
 
 
252
//------------------------------------------------------------------------
 
253
// GfxCIDFont
 
254
//------------------------------------------------------------------------
 
255
 
 
256
class GfxCIDFont: public GfxFont {
 
257
public:
 
258
 
 
259
  GfxCIDFont(XRef *xref, char *tagA, Ref idA, GString *nameA,
 
260
             Dict *fontDict);
 
261
 
 
262
  virtual ~GfxCIDFont();
 
263
 
 
264
  virtual GBool isCIDFont() { return gTrue; }
 
265
 
 
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);
 
269
 
 
270
  // Return the writing mode (0=horizontal, 1=vertical).
 
271
  virtual int getWMode();
 
272
 
 
273
  // Return the Unicode map.
 
274
  CharCodeToUnicode *getToUnicode();
 
275
 
 
276
  // Get the collection name (<registry>-<ordering>).
 
277
  GString *getCollection();
 
278
 
 
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; }
 
283
 
 
284
private:
 
285
 
 
286
  CMap *cMap;                   // char code --> CID
 
287
  CharCodeToUnicode *ctu;       // CID --> Unicode
 
288
  GfxFontCIDWidths widths;      // character widths
 
289
  Gushort *cidToGID;            // CID --> GID mapping (for embedded
 
290
                                //   TrueType fonts)
 
291
  int cidToGIDLen;
 
292
};
 
293
 
 
294
//------------------------------------------------------------------------
 
295
// GfxFontDict
 
296
//------------------------------------------------------------------------
 
297
 
 
298
class GfxFontDict {
 
299
public:
 
300
 
 
301
  // Build the font dictionary, given the PDF font dictionary.
 
302
  GfxFontDict(XRef *xref, Ref *fontDictRef, Dict *fontDict);
 
303
 
 
304
  // Destructor.
 
305
  ~GfxFontDict();
 
306
 
 
307
  // Get the specified font.
 
308
  GfxFont *lookup(char *tag);
 
309
 
 
310
  // Iterative access.
 
311
  int getNumFonts() { return numFonts; }
 
312
  GfxFont *getFont(int i) { return fonts[i]; }
 
313
 
 
314
private:
 
315
 
 
316
  GfxFont **fonts;              // list of fonts
 
317
  int numFonts;                 // number of fonts
 
318
};
 
319
 
 
320
#endif