]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/FontFile.h
Import of Xpdf 2.00 for merge
[evince.git] / pdf / xpdf / FontFile.h
1 //========================================================================
2 //
3 // FontFile.h
4 //
5 // Copyright 1999-2002 Glyph & Cog, LLC
6 //
7 //========================================================================
8
9 #ifndef FONTFILE_H
10 #define FONTFILE_H
11
12 #include <aconf.h>
13
14 #ifdef USE_GCC_PRAGMAS
15 #pragma interface
16 #endif
17
18 #include <stdio.h>
19 #include "gtypes.h"
20 #include "GString.h"
21 #include "CharTypes.h"
22
23 class CharCodeToUnicode;
24
25 //------------------------------------------------------------------------
26
27 typedef void (*FontFileOutputFunc)(void *stream, char *data, int len);
28
29 //------------------------------------------------------------------------
30 // FontFile
31 //------------------------------------------------------------------------
32
33 class FontFile {
34 public:
35
36   FontFile();
37   virtual ~FontFile();
38
39   // Returns the font name, as specified internally by the font file.
40   // Returns NULL if no name is available.
41   virtual char *getName() = 0;
42
43   // Returns the custom font encoding, or NULL if the encoding is not
44   // available.
45   virtual char **getEncoding() = 0;
46 };
47
48 //------------------------------------------------------------------------
49 // Type1FontFile
50 //------------------------------------------------------------------------
51
52 class Type1FontFile: public FontFile {
53 public:
54
55   Type1FontFile(char *file, int len);
56   virtual ~Type1FontFile();
57   virtual char *getName() { return name; }
58   virtual char **getEncoding() { return encoding; }
59
60 private:
61
62   char *name;
63   char **encoding;
64 };
65
66 //------------------------------------------------------------------------
67 // Type1CFontFile
68 //------------------------------------------------------------------------
69
70 struct Type1CTopDict;
71 struct Type1CPrivateDict;
72
73 class Type1CFontFile: public FontFile {
74 public:
75
76   Type1CFontFile(char *fileA, int lenA);
77   virtual ~Type1CFontFile();
78
79   virtual char *getName();
80   virtual char **getEncoding();
81
82   // Convert to a Type 1 font, suitable for embedding in a PostScript
83   // file.  The name will be used as the PostScript font name.
84   void convertToType1(FontFileOutputFunc outputFuncA, void *outputStreamA);
85
86   // Convert to a Type 0 CIDFont, suitable for embedding in a
87   // PostScript file.  The name will be used as the PostScript font
88   // name.
89   void convertToCIDType0(char *psName,
90                          FontFileOutputFunc outputFuncA, void *outputStreamA);
91
92   // Convert to a Type 0 (but non-CID) composite font, suitable for
93   // embedding in a PostScript file.  The name will be used as the
94   // PostScript font name.
95   void convertToType0(char *psName,
96                       FontFileOutputFunc outputFuncA, void *outputStreamA);
97
98 private:
99
100   void readNameAndEncoding();
101   void readTopDict(Type1CTopDict *dict);
102   void readPrivateDict(Type1CPrivateDict *privateDict,
103                        int offset, int size);
104   Gushort *readCharset(int charset, int nGlyphs);
105   void eexecWrite(char *s);
106   void eexecCvtGlyph(char *glyphName, Guchar *s, int n);
107   void cvtGlyph(Guchar *s, int n);
108   void cvtGlyphWidth(GBool useOp);
109   void eexecDumpNum(double x, GBool fpA);
110   void eexecDumpOp1(int opA);
111   void eexecDumpOp2(int opA);
112   void eexecWriteCharstring(Guchar *s, int n);
113   void getDeltaInt(char *buf, char *key, double *opA, int n);
114   void getDeltaReal(char *buf, char *key, double *opA, int n);
115   int getIndexLen(Guchar *indexPtr);
116   Guchar *getIndexValPtr(Guchar *indexPtr, int i);
117   Guchar *getIndexEnd(Guchar *indexPtr);
118   Guint getWord(Guchar *ptr, int size);
119   double getNum(Guchar **ptr, GBool *fp);
120   char *getString(int sid, char *buf);
121
122   char *file;
123   int len;
124
125   GString *name;
126   char **encoding;
127
128   int topOffSize;
129   Guchar *topDictIdxPtr;
130   Guchar *stringIdxPtr;
131   Guchar *gsubrIdxPtr;
132
133   FontFileOutputFunc outputFunc;
134   void *outputStream;
135   double op[48];                // operands
136   GBool fp[48];                 // true if operand is fixed point
137   int nOps;                     // number of operands
138   double defaultWidthX;         // default glyph width
139   double nominalWidthX;         // nominal glyph width
140   GBool defaultWidthXFP;        // true if defaultWidthX is fixed point
141   GBool nominalWidthXFP;        // true if nominalWidthX is fixed point
142   Gushort r1;                   // eexec encryption key
143   GString *charBuf;             // charstring output buffer
144   int line;                     // number of eexec chars on current line
145 };
146
147 //------------------------------------------------------------------------
148 // TrueTypeFontFile
149 //------------------------------------------------------------------------
150
151 struct TTFontTableHdr;
152
153 class TrueTypeFontFile: public FontFile {
154 public:
155
156   TrueTypeFontFile(char *fileA, int lenA);
157   ~TrueTypeFontFile();
158
159   // This always returns NULL, since it's probably better to trust the
160   // font name in the PDF file rather than the one in the TrueType
161   // font file.
162   virtual char *getName();
163
164   virtual char **getEncoding();
165
166   // Convert to a Type 42 font, suitable for embedding in a PostScript
167   // file.  The name will be used as the PostScript font name (so we
168   // don't need to depend on the 'name' table in the font).  The
169   // encoding is needed because the PDF Font object can modify the
170   // encoding.
171   void convertToType42(char *name, char **encodingA,
172                        CharCodeToUnicode *toUnicode,
173                        GBool pdfFontHasEncoding,
174                        FontFileOutputFunc outputFunc, void *outputStream);
175
176   // Convert to a Type 2 CIDFont, suitable for embedding in a
177   // PostScript file.  The name will be used as the PostScript font
178   // name (so we don't need to depend on the 'name' table in the
179   // font).
180   void convertToCIDType2(char *name, Gushort *cidMap, int nCIDs,
181                          FontFileOutputFunc outputFunc, void *outputStream);
182
183   // Convert to a Type 0 (but non-CID) composite font, suitable for
184   // embedding in a PostScript file.  The name will be used as the
185   // PostScript font name (so we don't need to depend on the 'name'
186   // table in the font).
187   void convertToType0(char *name, Gushort *cidMap, int nCIDs,
188                       FontFileOutputFunc outputFunc, void *outputStream);
189
190   // Write a TTF file, filling in any missing tables that are required
191   // by the TrueType spec.  If the font already has all the required
192   // tables, it will be written unmodified.
193   void writeTTF(FILE *out);
194
195 private:
196
197   char *file;
198   int len;
199
200   char **encoding;
201
202   TTFontTableHdr *tableHdrs;
203   int nTables;
204   int bbox[4];
205   int locaFmt;
206   int nGlyphs;
207   GBool mungedCmapSize;
208
209   int getByte(int pos);
210   int getChar(int pos);
211   int getUShort(int pos);
212   int getShort(int pos);
213   Guint getULong(int pos);
214   double getFixed(int pos);
215   int seekTable(char *tag);
216   int seekTableIdx(char *tag);
217   void cvtEncoding(char **encodingA, GBool pdfFontHasEncoding,
218                    FontFileOutputFunc outputFunc, void *outputStream);
219   void cvtCharStrings(char **encodingA, CharCodeToUnicode *toUnicode,
220                       GBool pdfFontHasEncoding,
221                       FontFileOutputFunc outputFunc, void *outputStream);
222   int getCmapEntry(int cmapFmt, int pos, int code);
223   void cvtSfnts(FontFileOutputFunc outputFunc, void *outputStream,
224                 GString *name);
225   void dumpString(char *s, int length,
226                   FontFileOutputFunc outputFunc, void *outputStream);
227   Guint computeTableChecksum(char *data, int length);
228 };
229
230 #endif