1 //========================================================================
5 // Copyright 1999-2003 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();
78 GBool isOk() { return ok; }
80 virtual char *getName();
81 virtual char **getEncoding();
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);
87 // Convert to a Type 0 CIDFont, suitable for embedding in a
88 // PostScript file. The name will be used as the PostScript font
90 void convertToCIDType0(char *psName,
91 FontFileOutputFunc outputFuncA, void *outputStreamA);
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);
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);
136 FontFileOutputFunc outputFunc;
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
154 //------------------------------------------------------------------------
156 //------------------------------------------------------------------------
158 struct TTFontTableHdr;
160 class TrueTypeFontFile: public FontFile {
163 TrueTypeFontFile(char *fileA, int lenA);
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
169 virtual char *getName();
171 virtual char **getEncoding();
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
178 void convertToType42(char *name, char **encodingA,
179 CharCodeToUnicode *toUnicode,
180 GBool pdfFontHasEncoding,
181 GBool pdfFontIsSymbolic,
182 FontFileOutputFunc outputFunc, void *outputStream);
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
188 void convertToCIDType2(char *name, Gushort *cidMap, int nCIDs,
189 FontFileOutputFunc outputFunc, void *outputStream);
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);
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);
210 TTFontTableHdr *tableHdrs;
215 GBool mungedCmapSize;
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,
233 void dumpString(char *s, int length,
234 FontFileOutputFunc outputFunc, void *outputStream);
235 Guint computeTableChecksum(char *data, int length);