summaryrefslogtreecommitdiff
path: root/noncore/unsupported/qpdf/xpdf/GfxFont.h
Unidiff
Diffstat (limited to 'noncore/unsupported/qpdf/xpdf/GfxFont.h') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/qpdf/xpdf/GfxFont.h286
1 files changed, 286 insertions, 0 deletions
diff --git a/noncore/unsupported/qpdf/xpdf/GfxFont.h b/noncore/unsupported/qpdf/xpdf/GfxFont.h
new file mode 100644
index 0000000..b1aa952
--- a/dev/null
+++ b/noncore/unsupported/qpdf/xpdf/GfxFont.h
@@ -0,0 +1,286 @@
1//========================================================================
2//
3// GfxFont.h
4//
5// Copyright 1996-2001 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 "CharTypes.h"
20
21class Dict;
22class CMap;
23class CharCodeToUnicode;
24struct GfxFontCIDWidths;
25
26//------------------------------------------------------------------------
27// GfxFontType
28//------------------------------------------------------------------------
29
30enum GfxFontType {
31 //----- Gfx8BitFont
32 fontUnknownType,
33 fontType1,
34 fontType1C,
35 fontType3,
36 fontTrueType,
37 //----- GfxCIDFont
38 fontCIDType0,
39 fontCIDType0C,
40 fontCIDType2
41};
42
43//------------------------------------------------------------------------
44// GfxFontCIDWidths
45//------------------------------------------------------------------------
46
47struct GfxFontCIDWidthExcep {
48 CID first; // this record applies to
49 CID last; // CIDs <first>..<last>
50 fouble width; // char width
51};
52
53struct GfxFontCIDWidthExcepV {
54 CID first; // this record applies to
55 CID last; // CIDs <first>..<last>
56 fouble height; // char height
57 fouble vx, vy; // origin position
58};
59
60struct GfxFontCIDWidths {
61 fouble defWidth; // default char width
62 fouble defHeight; // default char height
63 fouble defVY; // default origin position
64 GfxFontCIDWidthExcep *exceps;// exceptions
65 int nExceps; // number of valid entries in exceps
66 GfxFontCIDWidthExcepV *// exceptions for vertical font
67 excepsV;
68 int nExcepsV; // number of valid entries in excepsV
69};
70
71//------------------------------------------------------------------------
72// GfxFont
73//------------------------------------------------------------------------
74
75#define fontFixedWidth (1 << 0)
76#define fontSerif (1 << 1)
77#define fontSymbolic (1 << 2)
78#define fontItalic (1 << 6)
79#define fontBold (1 << 18)
80
81class GfxFont {
82public:
83
84 // Build a GfxFont object.
85 static GfxFont *makeFont(XRef *xref, char *tagA, Ref idA, Dict *fontDict);
86
87 GfxFont(char *tagA, Ref idA, GString *nameA);
88
89 virtual ~GfxFont();
90
91 GBool isOk() { return ok; }
92
93 // Get font tag.
94 GString *getTag() { return tag; }
95
96 // Get font dictionary ID.
97 Ref *getID() { return &id; }
98
99 // Does this font match the tag?
100 GBool matches(char *tagA) { return !tag->cmp(tagA); }
101
102 // Get base font name.
103 GString *getName() { return name; }
104
105 // Get font type.
106 GfxFontType getType() { return type; }
107 virtual GBool isCIDFont() { return gFalse; }
108
109 // Get embedded font ID, i.e., a ref for the font file stream.
110 // Returns false if there is no embedded font.
111 GBool getEmbeddedFontID(Ref *embID)
112 { *embID = embFontID; return embFontID.num >= 0; }
113
114 // Get the PostScript font name for the embedded font. Returns
115 // NULL if there is no embedded font.
116 char *getEmbeddedFontName()
117 { return embFontName ? embFontName->getCString() : (char *)NULL; }
118
119 // Get the name of the external font file. Returns NULL if there
120 // is no external font file.
121 GString *getExtFontFile() { return extFontFile; }
122
123 // Get font descriptor flags.
124 GBool isFixedWidth() { return flags & fontFixedWidth; }
125 GBool isSerif() { return flags & fontSerif; }
126 GBool isSymbolic() { return flags & fontSymbolic; }
127 GBool isItalic() { return flags & fontItalic; }
128 GBool isBold() { return flags & fontBold; }
129
130 // Return the font matrix.
131 fouble *getFontMatrix() { return fontMat; }
132
133 // Return the font bounding box.
134 fouble *getFontBBox() { return fontBBox; }
135
136 // Return the ascent and descent values.
137 fouble getAscent() { return ascent; }
138 fouble getDescent() { return descent; }
139
140 // Read an external or embedded font file into a buffer.
141 char *readExtFontFile(int *len);
142 char *readEmbFontFile(XRef *xref, int *len);
143
144 // Get the next char from a string <s> of <len> bytes, returning the
145 // char <code>, its Unicode mapping <u>, its displacement vector
146 // (<dx>, <dy>), and its origin offset vector (<ox>, <oy>). <uSize>
147 // is the number of entries available in <u>, and <uLen> is set to
148 // the number actually used. Returns the number of bytes used by
149 // the char code.
150 virtual int getNextChar(char *s, int len, CharCode *code,
151 Unicode *u, int uSize, int *uLen,
152 fouble *dx, fouble *dy, fouble *ox, fouble *oy) = 0;
153
154protected:
155
156 void readFontDescriptor(XRef *xref, Dict *fontDict);
157 CharCodeToUnicode *readToUnicodeCMap(Dict *fontDict, int nBits);
158 void GfxFont::findExtFontFile();
159
160 GString *tag; // PDF font tag
161 Ref id; // reference (used as unique ID)
162 GString *name; // font name
163 GfxFontType type; // type of font
164 int flags; // font descriptor flags
165 GString *embFontName; // name of embedded font
166 Ref embFontID; // ref to embedded font file stream
167 GString *extFontFile; // external font file name
168 fouble fontMat[6]; // font matrix (Type 3 only)
169 fouble fontBBox[4]; // font bounding box
170 fouble missingWidth; // "default" width
171 fouble ascent; // max height above baseline
172 fouble descent; // max depth below baseline
173 GBool ok;
174};
175
176//------------------------------------------------------------------------
177// Gfx8BitFont
178//------------------------------------------------------------------------
179
180class Gfx8BitFont: public GfxFont {
181public:
182
183 Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GString *nameA,
184 GfxFontType typeA, Dict *fontDict);
185
186 virtual ~Gfx8BitFont();
187
188 virtual int getNextChar(char *s, int len, CharCode *code,
189 Unicode *u, int uSize, int *uLen,
190 fouble *dx, fouble *dy, fouble *ox, fouble *oy);
191
192 // Return the encoding.
193 char **getEncoding() { return enc; }
194
195 // Return the Unicode map.
196 CharCodeToUnicode *getToUnicode();
197
198 // Return the character name associated with <code>.
199 char *getCharName(int code) { return enc[code]; }
200
201 // Returns true if the PDF font specified an encoding.
202 GBool getHasEncoding() { return hasEncoding; }
203
204 // Get width of a character or string.
205 fouble getWidth(Guchar c) { return widths[c]; }
206
207 // Return the Type 3 CharProc for the character associated with <code>.
208 Object *getCharProc(int code, Object *proc);
209
210private:
211
212 char *enc[256]; // char code --> char name
213 char encFree[256]; // boolean for each char name: if set,
214 // the string is malloc'ed
215 CharCodeToUnicode *ctu;// char code --> Unicode
216 GBool hasEncoding;
217 fouble widths[256]; // character widths
218 Object charProcs; // Type3 CharProcs dictionary
219};
220
221//------------------------------------------------------------------------
222// GfxCIDFont
223//------------------------------------------------------------------------
224
225class GfxCIDFont: public GfxFont {
226public:
227
228 GfxCIDFont(XRef *xref, char *tagA, Ref idA, GString *nameA,
229 Dict *fontDict);
230
231 virtual ~GfxCIDFont();
232
233 virtual GBool isCIDFont() { return gTrue; }
234
235 virtual int getNextChar(char *s, int len, CharCode *code,
236 Unicode *u, int uSize, int *uLen,
237 fouble *dx, fouble *dy, fouble *ox, fouble *oy);
238
239 // Return the Unicode map.
240 CharCodeToUnicode *getToUnicode();
241
242 // Get the collection name (<registry>-<ordering>).
243 GString *getCollection();
244
245 // Return the CID-to-GID mapping table. These should only be called
246 // if type is fontCIDType2.
247 Gushort *getCIDToGID() { return cidToGID; }
248 int getCIDToGIDLen() { return cidToGIDLen; }
249
250private:
251
252 CMap *cMap; // char code --> CID
253 CharCodeToUnicode *ctu;// CID --> Unicode
254 GfxFontCIDWidths widths;// character widths
255 Gushort *cidToGID; // CID --> GID mapping (for embedded
256 // TrueType fonts)
257 int cidToGIDLen;
258};
259
260//------------------------------------------------------------------------
261// GfxFontDict
262//------------------------------------------------------------------------
263
264class GfxFontDict {
265public:
266
267 // Build the font dictionary, given the PDF font dictionary.
268 GfxFontDict(XRef *xref, Dict *fontDict);
269
270 // Destructor.
271 ~GfxFontDict();
272
273 // Get the specified font.
274 GfxFont *lookup(char *tag);
275
276 // Iterative access.
277 int getNumFonts() { return numFonts; }
278 GfxFont *getFont(int i) { return fonts[i]; }
279
280private:
281
282 GfxFont **fonts; // list of fonts
283 int numFonts; // number of fonts
284};
285
286#endif