~ubuntu-branches/ubuntu/precise/ipe/precise

« back to all changes in this revision

Viewing changes to src/xpdflib/gfxfont.h

  • Committer: Bazaar Package Importer
  • Author(s): Steve M. Robbins
  • Date: 2004-06-08 00:44:02 UTC
  • Revision ID: james.westby@ubuntu.com-20040608004402-72yu51xlh7vt6p9m
Tags: upstream-6.0pre16
ImportĀ upstreamĀ versionĀ 6.0pre16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- C++ -*-
 
2
//========================================================================
 
3
//
 
4
// GfxFont.h
 
5
//
 
6
// Copyright 1996-2002 Glyph & Cog, LLC
 
7
//
 
8
//========================================================================
 
9
 
 
10
#ifndef GFXFONT_H
 
11
#define GFXFONT_H
 
12
 
 
13
#include "aconf.h"
 
14
 
 
15
#ifdef USE_GCC_PRAGMAS
 
16
#pragma interface
 
17
#endif
 
18
 
 
19
#include "gtypes.h"
 
20
#include "gstring.h"
 
21
#include "object.h"
 
22
#include "chartypes.h"
 
23
 
 
24
class Dict;
 
25
class CMap;
 
26
class CharCodeToUnicode;
 
27
struct GfxFontCIDWidths;
 
28
 
 
29
//------------------------------------------------------------------------
 
30
// GfxFontType
 
31
//------------------------------------------------------------------------
 
32
 
 
33
enum GfxFontType {
 
34
  //----- Gfx8BitFont
 
35
  fontUnknownType,
 
36
  fontType1,
 
37
  fontType1C,
 
38
  fontType3,
 
39
  fontTrueType,
 
40
  //----- GfxCIDFont
 
41
  fontCIDType0,
 
42
  fontCIDType0C,
 
43
  fontCIDType2
 
44
};
 
45
 
 
46
//------------------------------------------------------------------------
 
47
// GfxFontCIDWidths
 
48
//------------------------------------------------------------------------
 
49
 
 
50
struct GfxFontCIDWidthExcep {
 
51
  CID first;                    // this record applies to
 
52
  CID last;                     //   CIDs <first>..<last>
 
53
  double width;                 // char width
 
54
};
 
55
 
 
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
 
61
};
 
62
 
 
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
 
70
    excepsV;
 
71
  int nExcepsV;                 // number of valid entries in excepsV
 
72
};
 
73
 
 
74
//------------------------------------------------------------------------
 
75
// GfxFont
 
76
//------------------------------------------------------------------------
 
77
 
 
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)
 
83
 
 
84
class GfxFont {
 
85
public:
 
86
 
 
87
  // Build a GfxFont object.
 
88
  static GfxFont *makeFont(XRef *xref, char *tagA, Ref idA, Dict *fontDict);
 
89
 
 
90
  GfxFont(char *tagA, Ref idA, GString *nameA);
 
91
 
 
92
  virtual ~GfxFont();
 
93
 
 
94
  GBool isOk() { return ok; }
 
95
 
 
96
  // Get font tag.
 
97
  GString *getTag() { return tag; }
 
98
 
 
99
  // Get font dictionary ID.
 
100
  Ref *getID() { return &id; }
 
101
 
 
102
  // Does this font match the tag?
 
103
  GBool matches(char *tagA) { return !tag->cmp(tagA); }
 
104
 
 
105
  // Get base font name.
 
106
  GString *getName() { return name; }
 
107
 
 
108
  // Get font type.
 
109
  GfxFontType getType() { return type; }
 
110
  virtual GBool isCIDFont() { return gFalse; }
 
111
 
 
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; }
 
116
 
 
117
  // Get the PostScript font name for the embedded font.  Returns
 
118
  // NULL if there is no embedded font.
 
119
  GString *getEmbeddedFontName() { return embFontName; }
 
120
 
 
121
  // Get the name of the external font file.  Returns NULL if there
 
122
  // is no external font file.
 
123
  GString *getExtFontFile() { return extFontFile; }
 
124
 
 
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; }
 
131
 
 
132
  // Return the font matrix.
 
133
  double *getFontMatrix() { return fontMat; }
 
134
 
 
135
  // Return the font bounding box.
 
136
  double *getFontBBox() { return fontBBox; }
 
137
 
 
138
  // Return the ascent and descent values.
 
139
  double getAscent() { return ascent; }
 
140
  double getDescent() { return descent; }
 
141
 
 
142
  // Return the writing mode (0=horizontal, 1=vertical).
 
143
  virtual int getWMode() { return 0; }
 
144
 
 
145
  // Read an external or embedded font file into a buffer.
 
146
  char *readExtFontFile(int *len);
 
147
  char *readEmbFontFile(XRef *xref, int *len);
 
148
 
 
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
 
154
  // the char code.
 
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;
 
158
 
 
159
protected:
 
160
 
 
161
  void readFontDescriptor(XRef *xref, Dict *fontDict);
 
162
  CharCodeToUnicode *readToUnicodeCMap(Dict *fontDict, int nBits);
 
163
  void findExtFontFile();
 
164
 
 
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
 
178
  GBool ok;
 
179
};
 
180
 
 
181
//------------------------------------------------------------------------
 
182
// Gfx8BitFont
 
183
//------------------------------------------------------------------------
 
184
 
 
185
class Gfx8BitFont: public GfxFont {
 
186
public:
 
187
 
 
188
  Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GString *nameA,
 
189
              GfxFontType typeA, Dict *fontDict);
 
190
 
 
191
  virtual ~Gfx8BitFont();
 
192
 
 
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);
 
196
 
 
197
  // Return the encoding.
 
198
  char **getEncoding() { return enc; }
 
199
 
 
200
  // Return the Unicode map.
 
201
  CharCodeToUnicode *getToUnicode();
 
202
 
 
203
  // Return the character name associated with <code>.
 
204
  char *getCharName(int code) { return enc[code]; }
 
205
 
 
206
  // Returns true if the PDF font specified an encoding.
 
207
  GBool getHasEncoding() { return hasEncoding; }
 
208
 
 
209
  // Get width of a character or string.
 
210
  double getWidth(Guchar c) { return widths[c]; }
 
211
 
 
212
  // Return the Type 3 CharProc dictionary, or NULL if none.
 
213
  Dict *getCharProcs();
 
214
 
 
215
  // Return the Type 3 CharProc for the character associated with <code>.
 
216
  Object *getCharProc(int code, Object *proc);
 
217
 
 
218
  // Return the Type 3 Resources dictionary, or NULL if none.
 
219
  Dict *getResources();
 
220
 
 
221
private:
 
222
 
 
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
 
227
  GBool hasEncoding;
 
228
  double widths[256];           // character widths
 
229
  Object charProcs;             // Type 3 CharProcs dictionary
 
230
  Object resources;             // Type 3 Resources dictionary
 
231
};
 
232
 
 
233
//------------------------------------------------------------------------
 
234
// GfxCIDFont
 
235
//------------------------------------------------------------------------
 
236
 
 
237
class GfxCIDFont: public GfxFont {
 
238
public:
 
239
 
 
240
  GfxCIDFont(XRef *xref, char *tagA, Ref idA, GString *nameA,
 
241
             Dict *fontDict);
 
242
 
 
243
  virtual ~GfxCIDFont();
 
244
 
 
245
  virtual GBool isCIDFont() { return gTrue; }
 
246
 
 
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);
 
250
 
 
251
  // Return the writing mode (0=horizontal, 1=vertical).
 
252
  virtual int getWMode();
 
253
 
 
254
  // Return the Unicode map.
 
255
  CharCodeToUnicode *getToUnicode();
 
256
 
 
257
  // Get the collection name (<registry>-<ordering>).
 
258
  GString *getCollection();
 
259
 
 
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; }
 
264
 
 
265
private:
 
266
 
 
267
  CMap *cMap;                   // char code --> CID
 
268
  CharCodeToUnicode *ctu;       // CID --> Unicode
 
269
  GfxFontCIDWidths widths;      // character widths
 
270
  Gushort *cidToGID;            // CID --> GID mapping (for embedded
 
271
                                //   TrueType fonts)
 
272
  int cidToGIDLen;
 
273
};
 
274
 
 
275
//------------------------------------------------------------------------
 
276
// GfxFontDict
 
277
//------------------------------------------------------------------------
 
278
 
 
279
class GfxFontDict {
 
280
public:
 
281
 
 
282
  // Build the font dictionary, given the PDF font dictionary.
 
283
  GfxFontDict(XRef *xref, Dict *fontDict);
 
284
 
 
285
  // Destructor.
 
286
  ~GfxFontDict();
 
287
 
 
288
  // Get the specified font.
 
289
  GfxFont *lookup(char *tag);
 
290
 
 
291
  // Iterative access.
 
292
  int getNumFonts() { return numFonts; }
 
293
  GfxFont *getFont(int i) { return fonts[i]; }
 
294
 
 
295
private:
 
296
 
 
297
  GfxFont **fonts;              // list of fonts
 
298
  int numFonts;                 // number of fonts
 
299
};
 
300
 
 
301
#endif