source: trunk/poppler/mypoppler/poppler/GfxFont.h @ 257

Last change on this file since 257 was 257, checked in by Eugene Romanenko, 13 years ago

PDF plugin: Poppler library updated to version 0.10.0

File size: 11.2 KB
Line 
1//========================================================================
2//
3// GfxFont.h
4//
5// Copyright 1996-2003 Glyph & Cog, LLC
6//
7//========================================================================
8
9//========================================================================
10//
11// Modified under the Poppler project - http://poppler.freedesktop.org
12//
13// All changes made under the Poppler project to this file are licensed
14// under GPL version 2 or later
15//
16// Copyright (C) 2005, 2008 Albert Astals Cid <aacid@kde.org>
17// Copyright (C) 2006 Takashi Iwai <tiwai@suse.de>
18// Copyright (C) 2006 Kristian HÞgsberg <krh@redhat.com>
19// Copyright (C) 2007 Julien Rebetez <julienr@svn.gnome.org>
20// Copyright (C) 2007 Jeff Muizelaar <jeff@infidigm.net>
21// Copyright (C) 2007 Koji Otani <sho@bbr.jp>
22//
23// To see a description of the changes please see the Changelog file that
24// came with your tarball or type make ChangeLog if you are building from git
25//
26//========================================================================
27
28#ifndef GFXFONT_H
29#define GFXFONT_H
30
31#ifdef USE_GCC_PRAGMAS
32#pragma interface
33#endif
34
35#include "goo/gtypes.h"
36#include "goo/GooString.h"
37#include "Object.h"
38#include "CharTypes.h"
39
40class Dict;
41class CMap;
42class CharCodeToUnicode;
43class FoFiTrueType;
44class DisplayFontParam;
45struct GfxFontCIDWidths;
46
47//------------------------------------------------------------------------
48// GfxFontType
49//------------------------------------------------------------------------
50
51enum GfxFontType {
52  //----- Gfx8BitFont
53  fontUnknownType,
54  fontType1,
55  fontType1C,
56  fontType1COT,
57  fontType3,
58  fontTrueType,
59  fontTrueTypeOT,
60  //----- GfxCIDFont
61  fontCIDType0,
62  fontCIDType0C,
63  fontCIDType0COT,
64  fontCIDType2,
65  fontCIDType2OT
66};
67
68//------------------------------------------------------------------------
69// GfxFontCIDWidths
70//------------------------------------------------------------------------
71
72struct GfxFontCIDWidthExcep {
73  CID first;                    // this record applies to
74  CID last;                     //   CIDs <first>..<last>
75  double width;                 // char width
76};
77
78struct GfxFontCIDWidthExcepV {
79  CID first;                    // this record applies to
80  CID last;                     //   CIDs <first>..<last>
81  double height;                // char height
82  double vx, vy;                // origin position
83};
84
85struct GfxFontCIDWidths {
86  double defWidth;              // default char width
87  double defHeight;             // default char height
88  double defVY;                 // default origin position
89  GfxFontCIDWidthExcep *exceps; // exceptions
90  int nExceps;                  // number of valid entries in exceps
91  GfxFontCIDWidthExcepV *       // exceptions for vertical font
92    excepsV;
93  int nExcepsV;                 // number of valid entries in excepsV
94};
95
96//------------------------------------------------------------------------
97// GfxFont
98//------------------------------------------------------------------------
99
100#define fontFixedWidth (1 << 0)
101#define fontSerif      (1 << 1)
102#define fontSymbolic   (1 << 2)
103#define fontItalic     (1 << 6)
104#define fontBold       (1 << 18)
105
106class GfxFont {
107public:
108
109  enum Stretch { 
110        StretchNotDefined, 
111        UltraCondensed, 
112        ExtraCondensed, 
113        Condensed, 
114        SemiCondensed, 
115        Normal, 
116        SemiExpanded, 
117        Expanded, 
118        ExtraExpanded, 
119        UltraExpanded };
120
121  enum Weight { 
122        WeightNotDefined, 
123        W100, 
124        W200, 
125        W300, 
126        W400, // Normal
127        W500, 
128        W600, 
129        W700, // Bold
130        W800, 
131        W900 };
132
133  // Build a GfxFont object.
134  static GfxFont *makeFont(XRef *xref, char *tagA, Ref idA, Dict *fontDict);
135
136  GfxFont(char *tagA, Ref idA, GooString *nameA);
137
138  virtual ~GfxFont();
139
140  GBool isOk() { return ok; }
141
142  void incRefCnt();
143  void decRefCnt();
144
145  // Get font tag.
146  GooString *getTag() { return tag; }
147
148  // Get font dictionary ID.
149  Ref *getID() { return &id; }
150
151  // Does this font match the tag?
152  GBool matches(char *tagA) { return !tag->cmp(tagA); }
153
154  // Get base font name.
155  GooString *getName() { return name; }
156 
157  // Get font family name.
158  GooString *getFamily() { return family; }
159 
160  // Get font stretch.
161  Stretch getStretch() { return stretch; }
162 
163  // Get font weight.
164  Weight getWeight() { return weight; }
165
166  // Get the original font name (ignornig any munging that might have
167  // been done to map to a canonical Base-14 font name).
168  GooString *getOrigName() { return origName; }
169
170  // Get font type.
171  GfxFontType getType() { return type; }
172  virtual GBool isCIDFont() { return gFalse; }
173
174  // Get embedded font ID, i.e., a ref for the font file stream.
175  // Returns false if there is no embedded font.
176  GBool getEmbeddedFontID(Ref *embID)
177    { *embID = embFontID; return embFontID.num >= 0; }
178
179  // Get the PostScript font name for the embedded font.  Returns
180  // NULL if there is no embedded font.
181  GooString *getEmbeddedFontName() { return embFontName; }
182
183  // Get the name of the external font file.  Returns NULL if there
184  // is no external font file.
185  GooString *getExtFontFile() { return extFontFile; }
186
187  // Get font descriptor flags.
188  int getFlags() { return flags; }
189  GBool isFixedWidth() { return flags & fontFixedWidth; }
190  GBool isSerif() { return flags & fontSerif; }
191  GBool isSymbolic() { return flags & fontSymbolic; }
192  GBool isItalic() { return flags & fontItalic; }
193  GBool isBold() { return flags & fontBold; }
194
195  // Return the Unicode map.
196  virtual CharCodeToUnicode *getToUnicode() = 0;
197
198  // Return the font matrix.
199  double *getFontMatrix() { return fontMat; }
200
201  // Return the font bounding box.
202  double *getFontBBox() { return fontBBox; }
203
204  // Return the ascent and descent values.
205  double getAscent() { return ascent; }
206  double getDescent() { return descent; }
207
208  // Return the writing mode (0=horizontal, 1=vertical).
209  virtual int getWMode() { return 0; }
210
211  // Read an external or embedded font file into a buffer.
212  char *readExtFontFile(int *len);
213  char *readEmbFontFile(XRef *xref, int *len);
214
215  // Get the next char from a string <s> of <len> bytes, returning the
216  // char <code>, its Unicode mapping <u>, its displacement vector
217  // (<dx>, <dy>), and its origin offset vector (<ox>, <oy>).  <uSize>
218  // is the number of entries available in <u>, and <uLen> is set to
219  // the number actually used.  Returns the number of bytes used by
220  // the char code.
221  virtual int getNextChar(char *s, int len, CharCode *code,
222                          Unicode **u, int *uLen,
223                          double *dx, double *dy, double *ox, double *oy) = 0;
224
225  /* XXX: dfp shouldn't be public, however the font finding code is currently in
226   * GlobalParams. Instead it should be inside the GfxFont class. However,
227   * getDisplayFont currently uses FCcfg so moving it is not as simple. */
228  /* XXX: related to this is the fact that all of the extFontFile stuff is dead */
229  DisplayFontParam *dfp;
230protected:
231
232  void readFontDescriptor(XRef *xref, Dict *fontDict);
233  CharCodeToUnicode *readToUnicodeCMap(Dict *fontDict, int nBits,
234                                       CharCodeToUnicode *ctu);
235  void findExtFontFile();
236
237  GooString *tag;                       // PDF font tag
238  Ref id;                       // reference (used as unique ID)
239  GooString *name;              // font name
240  GooString *family;            // font family
241  Stretch stretch;                      // font stretch
242  Weight weight;                        // font weight
243  GooString *origName;          // original font name
244  GfxFontType type;             // type of font
245  int flags;                    // font descriptor flags
246  GooString *embFontName;               // name of embedded font
247  Ref embFontID;                // ref to embedded font file stream
248  GooString *extFontFile;               // external font file name
249  double fontMat[6];            // font matrix (Type 3 only)
250  double fontBBox[4];           // font bounding box (Type 3 only)
251  double missingWidth;          // "default" width
252  double ascent;                // max height above baseline
253  double descent;               // max depth below baseline
254  int refCnt;
255  GBool ok;
256};
257
258//------------------------------------------------------------------------
259// Gfx8BitFont
260//------------------------------------------------------------------------
261
262class Gfx8BitFont: public GfxFont {
263public:
264
265  Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GooString *nameA,
266              GfxFontType typeA, Dict *fontDict);
267
268  virtual ~Gfx8BitFont();
269
270  virtual int getNextChar(char *s, int len, CharCode *code,
271                          Unicode **u, int *uLen,
272                          double *dx, double *dy, double *ox, double *oy);
273
274  // Return the encoding.
275  char **getEncoding() { return enc; }
276
277  // Return the Unicode map.
278  CharCodeToUnicode *getToUnicode();
279
280  // Return the character name associated with <code>.
281  char *getCharName(int code) { return enc[code]; }
282
283  // Returns true if the PDF font specified an encoding.
284  GBool getHasEncoding() { return hasEncoding; }
285
286  // Returns true if the PDF font specified MacRomanEncoding.
287  GBool getUsesMacRomanEnc() { return usesMacRomanEnc; }
288
289  // Get width of a character.
290  double getWidth(Guchar c) { return widths[c]; }
291
292  // Return a char code-to-GID mapping for the provided font file.
293  // (This is only useful for TrueType fonts.)
294  Gushort *getCodeToGIDMap(FoFiTrueType *ff);
295
296  // Return the Type 3 CharProc dictionary, or NULL if none.
297  Dict *getCharProcs();
298
299  // Return the Type 3 CharProc for the character associated with <code>.
300  Object *getCharProc(int code, Object *proc);
301
302  // Return the Type 3 Resources dictionary, or NULL if none.
303  Dict *getResources();
304
305private:
306
307  char *enc[256];               // char code --> char name
308  char encFree[256];            // boolean for each char name: if set,
309                                //   the string is malloc'ed
310  CharCodeToUnicode *ctu;       // char code --> Unicode
311  GBool hasEncoding;
312  GBool usesMacRomanEnc;
313  double widths[256];           // character widths
314  Object charProcs;             // Type 3 CharProcs dictionary
315  Object resources;             // Type 3 Resources dictionary
316};
317
318//------------------------------------------------------------------------
319// GfxCIDFont
320//------------------------------------------------------------------------
321
322class GfxCIDFont: public GfxFont {
323public:
324
325  GfxCIDFont(XRef *xref, char *tagA, Ref idA, GooString *nameA,
326             Dict *fontDict);
327
328  virtual ~GfxCIDFont();
329
330  virtual GBool isCIDFont() { return gTrue; }
331
332  virtual int getNextChar(char *s, int len, CharCode *code,
333                          Unicode **u, int *uLen,
334                          double *dx, double *dy, double *ox, double *oy);
335
336  // Return the writing mode (0=horizontal, 1=vertical).
337  virtual int getWMode();
338
339  // Return the Unicode map.
340  CharCodeToUnicode *getToUnicode();
341
342  // Get the collection name (<registry>-<ordering>).
343  GooString *getCollection();
344
345  // Return the CID-to-GID mapping table.  These should only be called
346  // if type is fontCIDType2.
347  Gushort *getCIDToGID() { return cidToGID; }
348  int getCIDToGIDLen() { return cidToGIDLen; }
349
350  Gushort *getCodeToGIDMap(FoFiTrueType *ff, int *length);
351
352  double getWidth(char* s, int len);
353
354private:
355  Gushort mapCodeToGID(FoFiTrueType *ff, int cmapi,
356    Unicode unicode, GBool wmode);
357
358  CMap *cMap;                   // char code --> CID
359  CharCodeToUnicode *ctu;       // CID --> Unicode
360  GfxFontCIDWidths widths;      // character widths
361  Gushort *cidToGID;            // CID --> GID mapping (for embedded
362                                //   TrueType fonts)
363  int cidToGIDLen;
364};
365
366//------------------------------------------------------------------------
367// GfxFontDict
368//------------------------------------------------------------------------
369
370class GfxFontDict {
371public:
372
373  // Build the font dictionary, given the PDF font dictionary.
374  GfxFontDict(XRef *xref, Ref *fontDictRef, Dict *fontDict);
375
376  // Destructor.
377  ~GfxFontDict();
378
379  // Get the specified font.
380  GfxFont *lookup(char *tag);
381
382  // Iterative access.
383  int getNumFonts() { return numFonts; }
384  GfxFont *getFont(int i) { return fonts[i]; }
385
386private:
387
388  GfxFont **fonts;              // list of fonts
389  int numFonts;                 // number of fonts
390};
391
392#endif
Note: See TracBrowser for help on using the repository browser.