| 1 |
//======================================================================== |
| 2 |
// |
| 3 |
// FoFiType1C.h |
| 4 |
// |
| 5 |
// Copyright 1999-2003 Glyph & Cog, LLC |
| 6 |
// |
| 7 |
//======================================================================== |
| 8 |
|
| 9 |
#ifndef FOFITYPE1C_H |
| 10 |
#define FOFITYPE1C_H |
| 11 |
|
| 12 |
#include <aconf.h> |
| 13 |
|
| 14 |
#include "gtypes.h" |
| 15 |
#include "FoFiBase.h" |
| 16 |
|
| 17 |
class GHash; |
| 18 |
class GString; |
| 19 |
|
| 20 |
//------------------------------------------------------------------------ |
| 21 |
|
| 22 |
struct Type1CIndex { |
| 23 |
int pos; // absolute position in file |
| 24 |
int len; // length (number of entries) |
| 25 |
int offSize; // offset size |
| 26 |
int startPos; // position of start of index data - 1 |
| 27 |
int endPos; // position one byte past end of the index |
| 28 |
}; |
| 29 |
|
| 30 |
struct Type1CIndexVal { |
| 31 |
int pos; // absolute position in file |
| 32 |
int len; // length, in bytes |
| 33 |
}; |
| 34 |
|
| 35 |
struct Type1CTopDict { |
| 36 |
int firstOp; |
| 37 |
|
| 38 |
int versionSID; |
| 39 |
int noticeSID; |
| 40 |
int copyrightSID; |
| 41 |
int fullNameSID; |
| 42 |
int familyNameSID; |
| 43 |
int weightSID; |
| 44 |
int isFixedPitch; |
| 45 |
double italicAngle; |
| 46 |
double underlinePosition; |
| 47 |
double underlineThickness; |
| 48 |
int paintType; |
| 49 |
int charstringType; |
| 50 |
double fontMatrix[6]; |
| 51 |
GBool hasFontMatrix; // CID fonts are allowed to put their |
| 52 |
// FontMatrix in the FD instead of the |
| 53 |
// top dict |
| 54 |
int uniqueID; |
| 55 |
double fontBBox[4]; |
| 56 |
double strokeWidth; |
| 57 |
int charsetOffset; |
| 58 |
int encodingOffset; |
| 59 |
int charStringsOffset; |
| 60 |
int privateSize; |
| 61 |
int privateOffset; |
| 62 |
|
| 63 |
// CIDFont entries |
| 64 |
int registrySID; |
| 65 |
int orderingSID; |
| 66 |
int supplement; |
| 67 |
int fdArrayOffset; |
| 68 |
int fdSelectOffset; |
| 69 |
}; |
| 70 |
|
| 71 |
#define type1CMaxBlueValues 14 |
| 72 |
#define type1CMaxOtherBlues 10 |
| 73 |
#define type1CMaxStemSnap 12 |
| 74 |
|
| 75 |
struct Type1CPrivateDict { |
| 76 |
double fontMatrix[6]; |
| 77 |
GBool hasFontMatrix; |
| 78 |
int blueValues[type1CMaxBlueValues]; |
| 79 |
int nBlueValues; |
| 80 |
int otherBlues[type1CMaxOtherBlues]; |
| 81 |
int nOtherBlues; |
| 82 |
int familyBlues[type1CMaxBlueValues]; |
| 83 |
int nFamilyBlues; |
| 84 |
int familyOtherBlues[type1CMaxOtherBlues]; |
| 85 |
int nFamilyOtherBlues; |
| 86 |
double blueScale; |
| 87 |
int blueShift; |
| 88 |
int blueFuzz; |
| 89 |
double stdHW; |
| 90 |
GBool hasStdHW; |
| 91 |
double stdVW; |
| 92 |
GBool hasStdVW; |
| 93 |
double stemSnapH[type1CMaxStemSnap]; |
| 94 |
int nStemSnapH; |
| 95 |
double stemSnapV[type1CMaxStemSnap]; |
| 96 |
int nStemSnapV; |
| 97 |
GBool forceBold; |
| 98 |
GBool hasForceBold; |
| 99 |
double forceBoldThreshold; |
| 100 |
int languageGroup; |
| 101 |
double expansionFactor; |
| 102 |
int initialRandomSeed; |
| 103 |
int subrsOffset; |
| 104 |
double defaultWidthX; |
| 105 |
GBool defaultWidthXInt; |
| 106 |
double nominalWidthX; |
| 107 |
GBool nominalWidthXInt; |
| 108 |
}; |
| 109 |
|
| 110 |
// operand kind |
| 111 |
enum Type1COpKind { |
| 112 |
type1COpOperator, |
| 113 |
type1COpInteger, |
| 114 |
type1COpFloat, |
| 115 |
type1COpRational |
| 116 |
}; |
| 117 |
|
| 118 |
// operand |
| 119 |
struct Type1COp { |
| 120 |
Type1COpKind kind; |
| 121 |
union { |
| 122 |
int op; // type1COpOperator |
| 123 |
int intgr; // type1COpInteger |
| 124 |
double flt; // type1COpFloat |
| 125 |
struct { |
| 126 |
int num, den; // type1COpRational |
| 127 |
} rat; |
| 128 |
}; |
| 129 |
GBool isZero(); |
| 130 |
GBool isNegative(); |
| 131 |
int toInt(); |
| 132 |
double toFloat(); |
| 133 |
}; |
| 134 |
|
| 135 |
struct Type1CEexecBuf { |
| 136 |
FoFiOutputFunc outputFunc; |
| 137 |
void *outputStream; |
| 138 |
GBool ascii; // ASCII encoding? |
| 139 |
Gushort r1; // eexec encryption key |
| 140 |
int line; // number of eexec chars left on current line |
| 141 |
}; |
| 142 |
|
| 143 |
//------------------------------------------------------------------------ |
| 144 |
// FoFiType1C |
| 145 |
//------------------------------------------------------------------------ |
| 146 |
|
| 147 |
class FoFiType1C: public FoFiBase { |
| 148 |
public: |
| 149 |
|
| 150 |
// Create a FoFiType1C object from a memory buffer. |
| 151 |
static FoFiType1C *make(char *fileA, int lenA); |
| 152 |
|
| 153 |
// Create a FoFiType1C object from a file on disk. |
| 154 |
static FoFiType1C *load(char *fileName); |
| 155 |
|
| 156 |
virtual ~FoFiType1C(); |
| 157 |
|
| 158 |
// Return the font name. |
| 159 |
char *getName(); |
| 160 |
|
| 161 |
// Return the encoding, as an array of 256 names (any of which may |
| 162 |
// be NULL). This is only useful with 8-bit fonts. |
| 163 |
char **getEncoding(); |
| 164 |
|
| 165 |
// Get the glyph names. |
| 166 |
int getNumGlyphs() { return nGlyphs; } |
| 167 |
GString *getGlyphName(int gid); |
| 168 |
|
| 169 |
// Returns a hash mapping glyph names to GIDs. This is only useful |
| 170 |
// with 8-bit fonts. |
| 171 |
GHash *getNameToGIDMap(); |
| 172 |
|
| 173 |
// Return the mapping from CIDs to GIDs, and return the number of |
| 174 |
// CIDs in *<nCIDs>. This is only useful for CID fonts. |
| 175 |
int *getCIDToGIDMap(int *nCIDs); |
| 176 |
|
| 177 |
// Return the font matrix as an array of six numbers. |
| 178 |
void getFontMatrix(double *mat); |
| 179 |
|
| 180 |
// Convert to a Type 1 font, suitable for embedding in a PostScript |
| 181 |
// file. This is only useful with 8-bit fonts. If <newEncoding> is |
| 182 |
// not NULL, it will be used in place of the encoding in the Type 1C |
| 183 |
// font. If <ascii> is true the eexec section will be hex-encoded, |
| 184 |
// otherwise it will be left as binary data. If <psName> is non-NULL, |
| 185 |
// it will be used as the PostScript font name. |
| 186 |
void convertToType1(char *psName, const char **newEncoding, GBool ascii, |
| 187 |
FoFiOutputFunc outputFunc, void *outputStream); |
| 188 |
|
| 189 |
// Convert to a Type 0 CIDFont, suitable for embedding in a |
| 190 |
// PostScript file. <psName> will be used as the PostScript font |
| 191 |
// name. There are three cases for the CID-to-GID mapping: |
| 192 |
// (1) if <codeMap> is non-NULL, then it is the CID-to-GID mapping |
| 193 |
// (2) if <codeMap> is NULL and this is a CID CFF font, then the |
| 194 |
// font's internal CID-to-GID mapping is used |
| 195 |
// (3) is <codeMap> is NULL and this is an 8-bit CFF font, then |
| 196 |
// the identity CID-to-GID mapping is used |
| 197 |
void convertToCIDType0(char *psName, int *codeMap, int nCodes, |
| 198 |
FoFiOutputFunc outputFunc, void *outputStream); |
| 199 |
|
| 200 |
// Convert to a Type 0 (but non-CID) composite font, suitable for |
| 201 |
// embedding in a PostScript file. <psName> will be used as the |
| 202 |
// PostScript font name. There are three cases for the CID-to-GID |
| 203 |
// mapping: |
| 204 |
// (1) if <codeMap> is non-NULL, then it is the CID-to-GID mapping |
| 205 |
// (2) if <codeMap> is NULL and this is a CID CFF font, then the |
| 206 |
// font's internal CID-to-GID mapping is used |
| 207 |
// (3) is <codeMap> is NULL and this is an 8-bit CFF font, then |
| 208 |
// the identity CID-to-GID mapping is used |
| 209 |
void convertToType0(char *psName, int *codeMap, int nCodes, |
| 210 |
FoFiOutputFunc outputFunc, void *outputStream); |
| 211 |
|
| 212 |
// Write an OpenType file, encapsulating the CFF font. <widths> |
| 213 |
// provides the glyph widths (in design units) for <nWidths> glyphs. |
| 214 |
// The cmap table must be supplied by the caller. |
| 215 |
void convertToOpenType(FoFiOutputFunc outputFunc, void *outputStream, |
| 216 |
int nWidths, Gushort *widths, |
| 217 |
Guchar *cmapTable, int cmapTableLen); |
| 218 |
|
| 219 |
private: |
| 220 |
|
| 221 |
FoFiType1C(char *fileA, int lenA, GBool freeFileDataA); |
| 222 |
void eexecCvtGlyph(Type1CEexecBuf *eb, const char *glyphName, |
| 223 |
int offset, int nBytes, |
| 224 |
Type1CIndex *subrIdx, |
| 225 |
Type1CPrivateDict *pDict); |
| 226 |
void cvtGlyph(int offset, int nBytes, GString *charBuf, |
| 227 |
Type1CIndex *subrIdx, Type1CPrivateDict *pDict, |
| 228 |
GBool top, int recursion); |
| 229 |
void cvtGlyphWidth(GBool useOp, GString *charBuf, |
| 230 |
Type1CPrivateDict *pDict); |
| 231 |
void cvtNum(Type1COp op, GString *charBuf); |
| 232 |
void eexecWrite(Type1CEexecBuf *eb, const char *s); |
| 233 |
void eexecWriteCharstring(Type1CEexecBuf *eb, Guchar *s, int n); |
| 234 |
void writePSString(char *s, FoFiOutputFunc outputFunc, void *outputStream); |
| 235 |
Guint computeOpenTypeTableChecksum(Guchar *data, int length); |
| 236 |
GBool parse(); |
| 237 |
void readTopDict(); |
| 238 |
void readFD(int offset, int length, Type1CPrivateDict *pDict); |
| 239 |
void readPrivateDict(int offset, int length, Type1CPrivateDict *pDict); |
| 240 |
void readFDSelect(); |
| 241 |
void buildEncoding(); |
| 242 |
GBool readCharset(); |
| 243 |
int getOp(int pos, GBool charstring, GBool *ok); |
| 244 |
int getDeltaIntArray(int *arr, int maxLen); |
| 245 |
int getDeltaFPArray(double *arr, int maxLen); |
| 246 |
void getIndex(int pos, Type1CIndex *idx, GBool *ok); |
| 247 |
void getIndexVal(Type1CIndex *idx, int i, Type1CIndexVal *val, GBool *ok); |
| 248 |
char *getString(int sid, char *buf, GBool *ok); |
| 249 |
|
| 250 |
GString *name; |
| 251 |
char **encoding; |
| 252 |
|
| 253 |
Type1CIndex nameIdx; |
| 254 |
Type1CIndex topDictIdx; |
| 255 |
Type1CIndex stringIdx; |
| 256 |
Type1CIndex gsubrIdx; |
| 257 |
Type1CIndex charStringsIdx; |
| 258 |
|
| 259 |
Type1CTopDict topDict; |
| 260 |
Type1CPrivateDict *privateDicts; |
| 261 |
|
| 262 |
int nGlyphs; |
| 263 |
int nFDs; |
| 264 |
Guchar *fdSelect; |
| 265 |
Gushort *charset; |
| 266 |
int gsubrBias; |
| 267 |
|
| 268 |
GBool parsedOk; |
| 269 |
|
| 270 |
Type1COp ops[49]; // operands and operator |
| 271 |
int nOps; // number of operands |
| 272 |
int nHints; // number of hints for the current glyph |
| 273 |
GBool firstOp; // true if we haven't hit the first op yet |
| 274 |
GBool openPath; // true if there is an unclosed path |
| 275 |
}; |
| 276 |
|
| 277 |
#endif |