1 //========================================================================
5 // Copyright 1999-2002 Glyph & Cog, LLC
7 //========================================================================
19 #include "CharTypes.h"
21 class CharCodeToUnicode;
23 //------------------------------------------------------------------------
25 //------------------------------------------------------------------------
33 // Returns the font name, as specified internally by the font file.
34 // Returns NULL if no name is available.
35 virtual char *getName() = 0;
37 // Returns the custom font encoding, or NULL if the encoding is not
39 virtual char **getEncoding() = 0;
42 //------------------------------------------------------------------------
44 //------------------------------------------------------------------------
46 class Type1FontFile: public FontFile {
49 Type1FontFile(char *file, int len);
50 virtual ~Type1FontFile();
51 virtual char *getName() { return name; }
52 virtual char **getEncoding() { return encoding; }
60 //------------------------------------------------------------------------
62 //------------------------------------------------------------------------
65 struct Type1CPrivateDict;
67 class Type1CFontFile: public FontFile {
70 Type1CFontFile(char *fileA, int lenA);
71 virtual ~Type1CFontFile();
73 virtual char *getName();
74 virtual char **getEncoding();
76 // Convert to a Type 1 font, suitable for embedding in a PostScript
77 // file. The name will be used as the PostScript font name.
78 void convertToType1(FILE *outA);
80 // Convert to a Type 0 CIDFont, suitable for embedding in a
81 // PostScript file. The name will be used as the PostScript font
83 void convertToCIDType0(char *psName, FILE *outA);
85 // Convert to a Type 0 (but non-CID) composite font, suitable for
86 // embedding in a PostScript file. The name will be used as the
87 // PostScript font name.
88 void convertToType0(char *psName, FILE *outA);
92 void readNameAndEncoding();
93 void readTopDict(Type1CTopDict *dict);
94 void readPrivateDict(Type1CPrivateDict *privateDict,
95 int offset, int size);
96 Gushort *readCharset(int charset, int nGlyphs);
97 void eexecWrite(char *s);
98 void eexecCvtGlyph(char *glyphName, Guchar *s, int n);
99 void cvtGlyph(Guchar *s, int n);
100 void cvtGlyphWidth(GBool useOp);
101 void eexecDumpNum(double x, GBool fpA);
102 void eexecDumpOp1(int opA);
103 void eexecDumpOp2(int opA);
104 void eexecWriteCharstring(Guchar *s, int n);
105 void getDeltaInt(char *buf, char *key, double *opA, int n);
106 void getDeltaReal(char *buf, char *key, double *opA, int n);
107 int getIndexLen(Guchar *indexPtr);
108 Guchar *getIndexValPtr(Guchar *indexPtr, int i);
109 Guchar *getIndexEnd(Guchar *indexPtr);
110 Guint getWord(Guchar *ptr, int size);
111 double getNum(Guchar **ptr, GBool *fp);
112 char *getString(int sid, char *buf);
121 Guchar *topDictIdxPtr;
122 Guchar *stringIdxPtr;
126 double op[48]; // operands
127 GBool fp[48]; // true if operand is fixed point
128 int nOps; // number of operands
129 double defaultWidthX; // default glyph width
130 double nominalWidthX; // nominal glyph width
131 GBool defaultWidthXFP; // true if defaultWidthX is fixed point
132 GBool nominalWidthXFP; // true if nominalWidthX is fixed point
133 Gushort r1; // eexec encryption key
134 GString *charBuf; // charstring output buffer
135 int line; // number of eexec chars on current line
138 //------------------------------------------------------------------------
140 //------------------------------------------------------------------------
142 struct TTFontTableHdr;
144 class TrueTypeFontFile: public FontFile {
147 TrueTypeFontFile(char *fileA, int lenA);
150 // This always returns NULL, since it's probably better to trust the
151 // font name in the PDF file rather than the one in the TrueType
153 virtual char *getName();
155 virtual char **getEncoding();
157 // Convert to a Type 42 font, suitable for embedding in a PostScript
158 // file. The name will be used as the PostScript font name (so we
159 // don't need to depend on the 'name' table in the font). The
160 // encoding is needed because the PDF Font object can modify the
162 void convertToType42(char *name, char **encodingA,
163 CharCodeToUnicode *toUnicode,
164 GBool pdfFontHasEncoding, FILE *out);
166 // Convert to a Type 2 CIDFont, suitable for embedding in a
167 // PostScript file. The name will be used as the PostScript font
168 // name (so we don't need to depend on the 'name' table in the
170 void convertToCIDType2(char *name, Gushort *cidMap,
171 int nCIDs, FILE *out);
173 // Convert to a Type 0 (but non-CID) composite font, suitable for
174 // embedding in a PostScript file. The name will be used as the
175 // PostScript font name (so we don't need to depend on the 'name'
176 // table in the font).
177 void convertToType0(char *name, Gushort *cidMap,
178 int nCIDs, FILE *out);
180 // Write a TTF file, filling in any missing tables that are required
181 // by the TrueType spec. If the font already has all the required
182 // tables, it will be written unmodified.
183 void writeTTF(FILE *out);
192 TTFontTableHdr *tableHdrs;
198 int getByte(int pos);
199 int getChar(int pos);
200 int getUShort(int pos);
201 int getShort(int pos);
202 Guint getULong(int pos);
203 double getFixed(int pos);
204 int seekTable(char *tag);
205 int seekTableIdx(char *tag);
206 void cvtEncoding(char **encodingA, FILE *out);
207 void cvtCharStrings(char **encodingA, CharCodeToUnicode *toUnicode,
208 GBool pdfFontHasEncoding, FILE *out);
209 int getCmapEntry(int cmapFmt, int pos, int code);
210 void cvtSfnts(FILE *out, GString *name);
211 void dumpString(char *s, int length, FILE *out);
212 Guint computeTableChecksum(char *data, int length);