]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/FontFile.h
Reused eog HIG dialog in GPdf.
[evince.git] / pdf / xpdf / FontFile.h
1 //========================================================================
2 //
3 // FontFile.h
4 //
5 // Copyright 1999-2003 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   GBool isOk() { return ok; }
79
80   virtual char *getName();
81   virtual char **getEncoding();
82
83   // Convert to a Type 1 font, suitable for embedding in a PostScript
84   // file.  The name will be used as the PostScript font name.
85   void convertToType1(FontFileOutputFunc outputFuncA, void *outputStreamA);
86
87   // Convert to a Type 0 CIDFont, suitable for embedding in a
88   // PostScript file.  The name will be used as the PostScript font
89   // name.
90   void convertToCIDType0(char *psName,
91                          FontFileOutputFunc outputFuncA, void *outputStreamA);
92
93   // Convert to a Type 0 (but non-CID) composite font, suitable for
94   // embedding in a PostScript file.  The name will be used as the
95   // PostScript font name.
96   void convertToType0(char *psName,
97                       FontFileOutputFunc outputFuncA, void *outputStreamA);
98
99 private:
100
101   void readEncoding();
102   void readTopDict(Type1CTopDict *dict);
103   void readPrivateDict(Type1CPrivateDict *privateDict,
104                        int offset, int size);
105   Gushort *readCharset(int charset, int nGlyphs);
106   void eexecWrite(char *s);
107   void eexecCvtGlyph(char *glyphName, int pos, int n);
108   void cvtGlyph(int pos, int n, GBool top);
109   void cvtGlyphWidth(GBool useOp);
110   void eexecDumpNum(double x, GBool fpA);
111   void eexecDumpOp1(int opA);
112   void eexecDumpOp2(int opA);
113   void eexecWriteCharstring(Guchar *s, int n);
114   void getDeltaInt(char *buf, char *key, double *opA, int n);
115   void getDeltaReal(char *buf, char *key, double *opA, int n);
116   int getIndexLen(int indexPos);
117   int getIndexValPos(int indexPos, int i, int *valLen);
118   int getIndexEnd(int indexPos);
119   Guint getWord(int pos, int size);
120   double getNum(int *pos, GBool *fp);
121   char *getString(int sid, char *buf);
122
123   Guchar *file;
124   int len;
125
126   GString *name;
127   char **encoding;
128
129   int topDictIdxPos;
130   int stringIdxPos;
131   int gsubrIdxPos;
132   int subrIdxPos;
133   int gsubrBias;
134   int subrBias;
135
136   FontFileOutputFunc outputFunc;
137   void *outputStream;
138   double op[48];                // operands
139   GBool fp[48];                 // true if operand is fixed point
140   int nOps;                     // number of operands
141   int nHints;                   // number of hints for the current glyph
142   GBool firstOp;                // true if we haven't hit the first op yet
143   double defaultWidthX;         // default glyph width
144   double nominalWidthX;         // nominal glyph width
145   GBool defaultWidthXFP;        // true if defaultWidthX is fixed point
146   GBool nominalWidthXFP;        // true if nominalWidthX is fixed point
147   Gushort r1;                   // eexec encryption key
148   GString *charBuf;             // charstring output buffer
149   int line;                     // number of eexec chars on current line
150
151   GBool ok;
152 };
153
154 //------------------------------------------------------------------------
155 // TrueTypeFontFile
156 //------------------------------------------------------------------------
157
158 struct TTFontTableHdr;
159
160 class TrueTypeFontFile: public FontFile {
161 public:
162
163   TrueTypeFontFile(char *fileA, int lenA);
164   ~TrueTypeFontFile();
165
166   // This always returns NULL, since it's probably better to trust the
167   // font name in the PDF file rather than the one in the TrueType
168   // font file.
169   virtual char *getName();
170
171   virtual char **getEncoding();
172
173   // Convert to a Type 42 font, suitable for embedding in a PostScript
174   // file.  The name will be used as the PostScript font name (so we
175   // don't need to depend on the 'name' table in the font).  The
176   // encoding is needed because the PDF Font object can modify the
177   // encoding.
178   void convertToType42(char *name, char **encodingA,
179                        CharCodeToUnicode *toUnicode,
180                        GBool pdfFontHasEncoding,
181                        GBool pdfFontIsSymbolic,
182                        FontFileOutputFunc outputFunc, void *outputStream);
183
184   // Convert to a Type 2 CIDFont, suitable for embedding in a
185   // PostScript file.  The name will be used as the PostScript font
186   // name (so we don't need to depend on the 'name' table in the
187   // font).
188   void convertToCIDType2(char *name, Gushort *cidMap, int nCIDs,
189                          FontFileOutputFunc outputFunc, void *outputStream);
190
191   // Convert to a Type 0 (but non-CID) composite font, suitable for
192   // embedding in a PostScript file.  The name will be used as the
193   // PostScript font name (so we don't need to depend on the 'name'
194   // table in the font).
195   void convertToType0(char *name, Gushort *cidMap, int nCIDs,
196                       FontFileOutputFunc outputFunc, void *outputStream);
197
198   // Write a TTF file, filling in any missing tables that are required
199   // by the TrueType spec.  If the font already has all the required
200   // tables, it will be written unmodified.
201   void writeTTF(FILE *out);
202
203 private:
204
205   char *file;
206   int len;
207
208   char **encoding;
209
210   TTFontTableHdr *tableHdrs;
211   int nTables;
212   int bbox[4];
213   int locaFmt;
214   int nGlyphs;
215   GBool mungedCmapSize;
216
217   int getByte(int pos);
218   int getChar(int pos);
219   int getUShort(int pos);
220   int getShort(int pos);
221   Guint getULong(int pos);
222   double getFixed(int pos);
223   int seekTable(char *tag);
224   int seekTableIdx(char *tag);
225   void cvtEncoding(char **encodingA, GBool pdfFontHasEncoding,
226                    FontFileOutputFunc outputFunc, void *outputStream);
227   void cvtCharStrings(char **encodingA, CharCodeToUnicode *toUnicode,
228                       GBool pdfFontHasEncoding, GBool pdfFontIsSymbolic,
229                       FontFileOutputFunc outputFunc, void *outputStream);
230   int getCmapEntry(int cmapFmt, int pos, int code);
231   void cvtSfnts(FontFileOutputFunc outputFunc, void *outputStream,
232                 GString *name);
233   void dumpString(char *s, int length,
234                   FontFileOutputFunc outputFunc, void *outputStream);
235   Guint computeTableChecksum(char *data, int length);
236 };
237
238 #endif