]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/GfxFont.h
Painful merge.
[evince.git] / pdf / xpdf / GfxFont.h
1 //========================================================================
2 //
3 // GfxFont.h
4 //
5 // Copyright 1996 Derek B. Noonburg
6 //
7 //========================================================================
8
9 #ifndef GFXFONT_H
10 #define GFXFONT_H
11
12 #ifdef __GNUC__
13 #pragma interface
14 #endif
15
16 #include "gtypes.h"
17 #include "GString.h"
18 #include "Object.h"
19 #include "FontEncoding.h"
20
21 class Dict;
22 struct BuiltinFont;
23
24 //------------------------------------------------------------------------
25 // GfxFontCharSet16
26 //------------------------------------------------------------------------
27
28 enum GfxFontCharSet16 {
29   font16AdobeJapan12                    // Adobe-Japan1-2
30 };
31
32 //------------------------------------------------------------------------
33 // GfxFontEncoding16
34 //------------------------------------------------------------------------
35
36 struct GfxFontEncoding16 {
37   int wMode;                    // writing mode (0=horizontal, 1=vertical)
38   Guchar codeLen[256];          // length of codes, in bytes, indexed by
39                                 //   first byte of code
40   Gushort map1[256];            // one-byte code mapping:
41                                 //   map1[code] --> 16-bit char selector
42   Gushort *map2;                // two-byte code mapping
43                                 //   map2[2*i]   --> first code in range
44                                 //   map2[2*i+1] --> 16-bit char selector
45                                 //                   for map2[2*i]
46   int map2Len;                  // length of map2 array (divided by 2)
47 };
48
49 //------------------------------------------------------------------------
50 // GfxFontWidths16
51 //------------------------------------------------------------------------
52
53 struct GfxFontWidthExcep {
54   int first;                    // this record applies to
55   int last;                     //   chars <first>..<last>
56   double width;                 // char width
57 };
58
59 struct GfxFontWidthExcepV {
60   int first;                    // this record applies to
61   int last;                     //   chars <first>..<last>
62   double height;                // char height
63   double vx, vy;                // origin position
64 };
65
66 struct GfxFontWidths16 {
67   double defWidth;              // default char width
68   double defHeight;             // default char height
69   double defVY;                 // default origin position
70   GfxFontWidthExcep *exceps;    // exceptions
71   int numExceps;                // number of valid entries in exceps
72   GfxFontWidthExcepV *excepsV;  // exceptions for vertical font
73   int numExcepsV;               // number of valid entries in excepsV
74 };
75
76 //------------------------------------------------------------------------
77 // GfxFont
78 //------------------------------------------------------------------------
79
80 #define fontFixedWidth (1 << 0)
81 #define fontSerif      (1 << 1)
82 #define fontSymbolic   (1 << 2)
83 #define fontItalic     (1 << 6)
84 #define fontBold       (1 << 18)
85
86 enum GfxFontType {
87   fontUnknownType,
88   fontType1,
89   fontType1C,
90   fontType3,
91   fontTrueType,
92   fontType0
93 };
94
95 class GfxFont {
96 public:
97
98   // Constructor.
99   GfxFont(char *tag1, Ref id1, Dict *fontDict);
100
101   // Destructor.
102   ~GfxFont();
103
104   // Get font tag.
105   GString *getTag() { return tag; }
106
107   // Get font dictionary ID.
108   Ref getID() { return id; }
109
110   // Does this font match the tag?
111   GBool matches(char *tag1) { return !tag->cmp(tag1); }
112
113   // Get base font name.
114   GString *getName() { return name; }
115
116   // Get font type.
117   GfxFontType getType() { return type; }
118
119   // Does this font use 16-bit characters?
120   GBool is16Bit() { return is16; }
121
122   // Get embedded font ID, i.e., a ref for the font file stream.
123   // Returns false if there is no embedded font.
124   GBool getEmbeddedFontID(Ref *embID)
125     { *embID = embFontID; return embFontID.num >= 0; }
126
127   // Get the PostScript font name for the embedded font.  Returns
128   // NULL if there is no embedded font.
129   char *getEmbeddedFontName()
130     { return embFontName ? embFontName->getCString() : (char *)NULL; }
131
132   // Get the name of the external font file.  Returns NULL if there
133   // is no external font file.
134   char *getExtFontFile()
135     { return extFontFile ? extFontFile->getCString() : (char *)NULL; }
136
137   // Get font descriptor flags.
138   GBool isFixedWidth() { return flags & fontFixedWidth; }
139   GBool isSerif() { return flags & fontSerif; }
140   GBool isSymbolic() { return flags & fontSymbolic; }
141   GBool isItalic() { return flags & fontItalic; }
142   GBool isBold() { return flags & fontBold; }
143
144   // Get width of a character or string.
145   double getWidth(Guchar c) { return widths[c]; }
146   double getWidth(GString *s);
147
148   // Get character metrics for 16-bit font.
149   double getWidth16(int c);
150   double getHeight16(int c);
151   double getOriginX16(int c);
152   double getOriginY16(int c);
153
154   // Return the encoding.
155   FontEncoding *getEncoding() { return encoding; }
156
157   // Return the character name associated with <code>.
158   char *getCharName(int code) { return encoding->getCharName(code); }
159
160   // Return the code associated with <name>.
161   int getCharCode(char *charName) { return encoding->getCharCode(charName); }
162
163   // Return the 16-bit character set and encoding.
164   GfxFontCharSet16 getCharSet16() { return enc16.charSet; }
165   GfxFontEncoding16 *getEncoding16() { return enc16.enc; }
166
167   // Get the writing mode (0=horizontal, 1=vertical).
168   int getWMode16() { return enc16.enc->wMode; }
169
170   // Return the font matrix.
171   double *getFontMatrix() { return fontMat; }
172
173   // Read an external or embedded font file into a buffer.
174   char *readExtFontFile(int *len);
175   char *readEmbFontFile(int *len);
176
177 private:
178
179   void getEncAndWidths(Dict *fontDict, BuiltinFont *builtinFont);
180   void findExtFontFile();
181   void makeWidths(Dict *fontDict, FontEncoding *builtinEncoding,
182                   Gushort *builtinWidths);
183   void getType0EncAndWidths(Dict *fontDict);
184
185   GString *tag;                 // PDF font tag
186   Ref id;                       // reference (used as unique ID)
187   GString *name;                // font name
188   int flags;                    // font descriptor flags
189   GfxFontType type;             // type of font
190   GBool is16;                   // set if font uses 16-bit chars
191   GString *embFontName;         // name of embedded font
192   Ref embFontID;                // ref to embedded font file stream
193   GString *extFontFile;         // external font file name
194   double fontMat[6];            // font matrix
195   union {
196     FontEncoding *encoding;     // 8-bit font encoding
197     struct {
198       GfxFontCharSet16 charSet; // 16-bit character set
199       GfxFontEncoding16 *enc;   // 16-bit encoding (CMap)
200     } enc16;
201   };
202   union {
203     double widths[256];         // width of each char for 8-bit font
204     GfxFontWidths16 widths16;   // char widths for 16-bit font
205   };
206 };
207
208 //------------------------------------------------------------------------
209 // GfxFontDict
210 //------------------------------------------------------------------------
211
212 class GfxFontDict {
213 public:
214
215   // Build the font dictionary, given the PDF font dictionary.
216   GfxFontDict(Dict *fontDict);
217
218   // Destructor.
219   ~GfxFontDict();
220
221   // Get the specified font.
222   GfxFont *lookup(char *tag);
223
224   // Iterative access.
225   int getNumFonts() { return numFonts; }
226   GfxFont *getFont(int i) { return fonts[i]; }
227
228 private:
229
230   GfxFont **fonts;              // list of fonts
231   int numFonts;                 // number of fonts
232 };
233
234 #endif