1 //========================================================================
5 // Copyright 1999-2002 Glyph & Cog, LLC
7 //========================================================================
14 #ifdef USE_GCC_PRAGMAS
21 #include "CharTypes.h"
23 class CharCodeToUnicode;
25 //------------------------------------------------------------------------
27 typedef void (*FontFileOutputFunc)(void *stream, char *data, int len);
29 //------------------------------------------------------------------------
31 //------------------------------------------------------------------------
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;
43 // Returns the custom font encoding, or NULL if the encoding is not
45 virtual char **getEncoding() = 0;
48 //------------------------------------------------------------------------
50 //------------------------------------------------------------------------
52 class Type1FontFile: public FontFile {
55 Type1FontFile(char *file, int len);
56 virtual ~Type1FontFile();
57 virtual char *getName() { return name; }
58 virtual char **getEncoding() { return encoding; }
66 //------------------------------------------------------------------------
68 //------------------------------------------------------------------------
71 struct Type1CPrivateDict;
73 class Type1CFontFile: public FontFile {
76 Type1CFontFile(char *fileA, int lenA);
77 virtual ~Type1CFontFile();
79 virtual char *getName();
80 virtual char **getEncoding();
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);
86 // Convert to a Type 0 CIDFont, suitable for embedding in a
87 // PostScript file. The name will be used as the PostScript font
89 void convertToCIDType0(char *psName,
90 FontFileOutputFunc outputFuncA, void *outputStreamA);
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);
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);
129 Guchar *topDictIdxPtr;
130 Guchar *stringIdxPtr;
133 FontFileOutputFunc outputFunc;
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
147 //------------------------------------------------------------------------
149 //------------------------------------------------------------------------
151 struct TTFontTableHdr;
153 class TrueTypeFontFile: public FontFile {
156 TrueTypeFontFile(char *fileA, int lenA);
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
162 virtual char *getName();
164 virtual char **getEncoding();
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
171 void convertToType42(char *name, char **encodingA,
172 CharCodeToUnicode *toUnicode,
173 GBool pdfFontHasEncoding,
174 FontFileOutputFunc outputFunc, void *outputStream);
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
180 void convertToCIDType2(char *name, Gushort *cidMap, int nCIDs,
181 FontFileOutputFunc outputFunc, void *outputStream);
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);
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);
202 TTFontTableHdr *tableHdrs;
207 GBool mungedCmapSize;
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,
225 void dumpString(char *s, int length,
226 FontFileOutputFunc outputFunc, void *outputStream);
227 Guint computeTableChecksum(char *data, int length);