00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef FONTFILE_H
00010 #define FONTFILE_H
00011
00012 #include <aconf.h>
00013
00014 #ifdef USE_GCC_PRAGMAS
00015 #pragma interface
00016 #endif
00017
00018 #include <stdio.h>
00019 #include "gtypes.h"
00020 #include "GString.h"
00021 #include "CharTypes.h"
00022
00023 class CharCodeToUnicode;
00024
00025
00026
00027 typedef void (*FontFileOutputFunc)(void *stream, const char *data, int len);
00028
00029
00030
00031
00032
00033 class FontFile {
00034 public:
00035
00036 FontFile();
00037 virtual ~FontFile();
00038
00039
00040
00041 virtual const char *getName() = 0;
00042
00043
00044
00045 virtual char **getEncoding() = 0;
00046 };
00047
00048
00049
00050
00051
00052 class Type1FontFile: public FontFile {
00053 public:
00054
00055 Type1FontFile(const char *file, int len);
00056 virtual ~Type1FontFile();
00057 virtual const char *getName() { return name; }
00058 virtual char **getEncoding() { return encoding; }
00059
00060 private:
00061
00062 char *name;
00063 char **encoding;
00064 };
00065
00066
00067
00068
00069
00070 struct Type1CTopDict;
00071 struct Type1CPrivateDict;
00072
00073 class Type1CFontFile: public FontFile {
00074 public:
00075
00076 Type1CFontFile(const char *fileA, int lenA);
00077 virtual ~Type1CFontFile();
00078
00079 virtual const char *getName();
00080 virtual char **getEncoding();
00081
00082
00083
00084 void convertToType1(FontFileOutputFunc outputFuncA, void *outputStreamA);
00085
00086
00087
00088
00089 void convertToCIDType0(const char *psName,
00090 FontFileOutputFunc outputFuncA, void *outputStreamA);
00091
00092
00093
00094
00095 void convertToType0(const char *psName,
00096 FontFileOutputFunc outputFuncA, void *outputStreamA);
00097
00098 private:
00099
00100 void readNameAndEncoding();
00101 void readTopDict(Type1CTopDict *dict);
00102 void readPrivateDict(Type1CPrivateDict *privateDict,
00103 int offset, int size);
00104 Gushort *readCharset(int charset, int nGlyphs);
00105 void eexecWrite(const char *s);
00106 void eexecCvtGlyph(const char *glyphName, const Guchar *s, int n);
00107 void cvtGlyph(const Guchar *s, int n);
00108 void cvtGlyphWidth(GBool useOp);
00109 void eexecDumpNum(double x, GBool fpA);
00110 void eexecDumpOp1(int opA);
00111 void eexecDumpOp2(int opA);
00112 void eexecWriteCharstring(const Guchar *s, int n);
00113 void getDeltaInt(char *buf, const char *key, const double *opA, int n);
00114 void getDeltaReal(char *buf, const char *key, const double *opA, int n);
00115 int getIndexLen(Guchar *indexPtr);
00116 Guchar *getIndexValPtr(Guchar *indexPtr, int i);
00117 Guchar *getIndexEnd(Guchar *indexPtr);
00118 Guint getWord(Guchar *ptr, int size);
00119 double getNum(Guchar **ptr, GBool *fp);
00120 char *getString(int sid, char *buf);
00121
00122 const char *file;
00123 int len;
00124
00125 GString *name;
00126 char **encoding;
00127
00128 int topOffSize;
00129 Guchar *topDictIdxPtr;
00130 Guchar *stringIdxPtr;
00131 Guchar *gsubrIdxPtr;
00132
00133 FontFileOutputFunc outputFunc;
00134 void *outputStream;
00135 double op[48];
00136 GBool fp[48];
00137 int nOps;
00138 double defaultWidthX;
00139 double nominalWidthX;
00140 GBool defaultWidthXFP;
00141 GBool nominalWidthXFP;
00142 Gushort r1;
00143 GString *charBuf;
00144 int line;
00145 };
00146
00147
00148
00149
00150
00151 struct TTFontTableHdr;
00152
00153 class TrueTypeFontFile: public FontFile {
00154 public:
00155
00156 TrueTypeFontFile(const char *fileA, int lenA);
00157 ~TrueTypeFontFile();
00158
00159
00160
00161
00162 virtual const char *getName();
00163
00164 virtual char **getEncoding();
00165
00166
00167
00168
00169
00170
00171 void convertToType42(const char *name, const char **encodingA,
00172 CharCodeToUnicode *toUnicode,
00173 GBool pdfFontHasEncoding,
00174 FontFileOutputFunc outputFunc, void *outputStream);
00175
00176
00177
00178
00179
00180 void convertToCIDType2(const char *name, const Gushort *cidMap, int nCIDs,
00181 FontFileOutputFunc outputFunc, void *outputStream);
00182
00183
00184
00185
00186
00187 void convertToType0(const char *name, const Gushort *cidMap, int nCIDs,
00188 FontFileOutputFunc outputFunc, void *outputStream);
00189
00190
00191
00192
00193 void writeTTF(FILE *out);
00194
00195 private:
00196
00197 const char *file;
00198 int len;
00199
00200 char **encoding;
00201
00202 TTFontTableHdr *tableHdrs;
00203 int nTables;
00204 int bbox[4];
00205 int locaFmt;
00206 int nGlyphs;
00207 GBool mungedCmapSize;
00208
00209 int getByte(int pos);
00210 int getChar(int pos);
00211 int getUShort(int pos);
00212 int getShort(int pos);
00213 Guint getULong(int pos);
00214 double getFixed(int pos);
00215 int seekTable(const char *tag);
00216 int seekTableIdx(const char *tag);
00217 void cvtEncoding(const char **encodingA, GBool pdfFontHasEncoding,
00218 FontFileOutputFunc outputFunc, void *outputStream);
00219 void cvtCharStrings(const char **encodingA, CharCodeToUnicode *toUnicode,
00220 GBool pdfFontHasEncoding,
00221 FontFileOutputFunc outputFunc, void *outputStream);
00222 int getCmapEntry(int cmapFmt, int pos, int code);
00223 void cvtSfnts(FontFileOutputFunc outputFunc, void *outputStream,
00224 GString *name);
00225 void dumpString(const char *s, int length,
00226 FontFileOutputFunc outputFunc, void *outputStream);
00227 Guint computeTableChecksum(const char *data, int length);
00228 };
00229
00230 #endif