1 //========================================================================
5 // Copyright 1999-2003 Glyph & Cog, LLC
7 //========================================================================
14 #ifdef USE_GCC_PRAGMAS
21 #include "CharTypes.h"
24 class CharCodeToUnicode;
26 //------------------------------------------------------------------------
28 typedef void (*FontFileOutputFunc)(void *stream, char *data, int len);
30 //------------------------------------------------------------------------
32 //------------------------------------------------------------------------
40 // Returns the font name, as specified internally by the font file.
41 // Returns NULL if no name is available.
42 virtual char *getName() = 0;
44 // Returns the custom font encoding, or NULL if the encoding is not
46 virtual char **getEncoding() = 0;
49 //------------------------------------------------------------------------
51 //------------------------------------------------------------------------
53 class Type1FontFile: public FontFile {
56 Type1FontFile(char *file, int len);
57 virtual ~Type1FontFile();
58 virtual char *getName() { return name; }
59 virtual char **getEncoding() { return encoding; }
67 //------------------------------------------------------------------------
69 //------------------------------------------------------------------------
72 struct Type1CPrivateDict;
74 class Type1CFontFile: public FontFile {
77 Type1CFontFile(char *fileA, int lenA);
78 virtual ~Type1CFontFile();
79 GBool isOk() { return ok; }
81 virtual char *getName();
82 virtual char **getEncoding();
84 // Convert to a Type 1 font, suitable for embedding in a PostScript
85 // file. The name will be used as the PostScript font name.
86 void convertToType1(FontFileOutputFunc outputFuncA, void *outputStreamA);
88 // Convert to a Type 0 CIDFont, suitable for embedding in a
89 // PostScript file. The name will be used as the PostScript font
91 void convertToCIDType0(char *psName,
92 FontFileOutputFunc outputFuncA, void *outputStreamA);
94 // Convert to a Type 0 (but non-CID) composite font, suitable for
95 // embedding in a PostScript file. The name will be used as the
96 // PostScript font name.
97 void convertToType0(char *psName,
98 FontFileOutputFunc outputFuncA, void *outputStreamA);
103 void readTopDict(Type1CTopDict *dict);
104 void readPrivateDict(Type1CPrivateDict *privateDict,
105 int offset, int size);
106 Gushort *readCharset(int charset, int nGlyphs);
107 void eexecWrite(char *s);
108 void eexecCvtGlyph(char *glyphName, int pos, int n);
109 void cvtGlyph(int pos, int n, GBool top);
110 void cvtGlyphWidth(GBool useOp);
111 void eexecDumpNum(double x, GBool fpA);
112 void eexecDumpOp1(int opA);
113 void eexecDumpOp2(int opA);
114 void eexecWriteCharstring(Guchar *s, int n);
115 void getDeltaInt(char *buf, char *key, double *opA, int n);
116 void getDeltaReal(char *buf, char *key, double *opA, int n);
117 int getIndexLen(int indexPos);
118 int getIndexValPos(int indexPos, int i, int *valLen);
119 int getIndexEnd(int indexPos);
120 Guint getWord(int pos, int size);
121 double getNum(int *pos, GBool *fp);
122 char *getString(int sid, char *buf);
137 FontFileOutputFunc outputFunc;
139 double op[48]; // operands
140 GBool fp[48]; // true if operand is fixed point
141 int nOps; // number of operands
142 int nHints; // number of hints for the current glyph
143 GBool firstOp; // true if we haven't hit the first op yet
144 double defaultWidthX; // default glyph width
145 double nominalWidthX; // nominal glyph width
146 GBool defaultWidthXFP; // true if defaultWidthX is fixed point
147 GBool nominalWidthXFP; // true if nominalWidthX is fixed point
148 Gushort r1; // eexec encryption key
149 GString *charBuf; // charstring output buffer
150 int line; // number of eexec chars on current line
155 //------------------------------------------------------------------------
157 //------------------------------------------------------------------------
159 struct TTFontTableHdr;
162 class TrueTypeFontFile: public FontFile {
165 TrueTypeFontFile(char *fileA, int lenA);
168 // This always returns NULL, since it's probably better to trust the
169 // font name in the PDF file rather than the one in the TrueType
171 virtual char *getName();
173 virtual char **getEncoding();
175 // Return the number of cmaps defined by this font.
178 // Return the platform ID of the <i>th cmap.
179 int getCmapPlatform(int i);
181 // Return the encoding ID of the <i>th cmap.
182 int getCmapEncoding(int i);
184 // Return the index of the cmap for <platform>, <encoding>. Returns
185 // -1 if there is no corresponding cmap.
186 int findCmap(int platform, int enc);
188 // Return the GID corresponding to <c> according to the <i>th cmap.
189 Gushort mapCodeToGID(int i, int c);
191 // Return a name-to-GID mapping, constructed from the font's post
192 // table. Returns NULL if there is no post table.
193 GHash *getNameToGID();
195 // Convert to a Type 42 font, suitable for embedding in a PostScript
196 // file. The name will be used as the PostScript font name (so we
197 // don't need to depend on the 'name' table in the font). The
198 // encoding is needed because the PDF Font object can modify the
200 void convertToType42(char *name, char **encodingA,
201 GBool pdfFontHasEncoding,
203 FontFileOutputFunc outputFunc, void *outputStream);
205 // Convert to a Type 2 CIDFont, suitable for embedding in a
206 // PostScript file. The name will be used as the PostScript font
207 // name (so we don't need to depend on the 'name' table in the
209 void convertToCIDType2(char *name, Gushort *cidMap, int nCIDs,
210 FontFileOutputFunc outputFunc, void *outputStream);
212 // Convert to a Type 0 (but non-CID) composite font, suitable for
213 // embedding in a PostScript file. The name will be used as the
214 // PostScript font name (so we don't need to depend on the 'name'
215 // table in the font).
216 void convertToType0(char *name, Gushort *cidMap, int nCIDs,
217 FontFileOutputFunc outputFunc, void *outputStream);
219 // Write a TTF file, filling in any missing tables that are required
220 // by the TrueType spec. If the font already has all the required
221 // tables, it will be written unmodified.
222 void writeTTF(FILE *out);
231 TTFontTableHdr *tableHdrs;
236 GBool mungedCmapSize;
240 int getByte(int pos);
241 int getChar(int pos);
242 int getUShort(int pos);
243 int getShort(int pos);
244 Guint getULong(int pos);
245 double getFixed(int pos);
246 int seekTable(char *tag);
247 int seekTableIdx(char *tag);
248 void cvtEncoding(char **encodingA, GBool pdfFontHasEncoding,
249 FontFileOutputFunc outputFunc, void *outputStream);
250 void cvtCharStrings(char **encodingA, GBool pdfFontHasEncoding,
252 FontFileOutputFunc outputFunc, void *outputStream);
253 int getCmapEntry(int cmapFmt, int pos, int code);
254 void cvtSfnts(FontFileOutputFunc outputFunc, void *outputStream,
256 void dumpString(char *s, int length,
257 FontFileOutputFunc outputFunc, void *outputStream);
258 Guint computeTableChecksum(char *data, int length);