1 //========================================================================
5 // Copyright 1999-2003 Glyph & Cog, LLC
7 //========================================================================
14 #ifdef USE_GCC_PRAGMAS
23 //------------------------------------------------------------------------
26 int pos; // absolute position in file
27 int len; // length (number of entries)
28 int offSize; // offset size
29 int startPos; // position of start of index data - 1
30 int endPos; // position one byte past end of the index
33 struct Type1CIndexVal {
34 int pos; // absolute position in file
35 int len; // length, in bytes
38 struct Type1CTopDict {
49 double underlinePosition;
50 double underlineThickness;
59 int charStringsOffset;
71 #define type1CMaxBlueValues 14
72 #define type1CMaxOtherBlues 10
73 #define type1CMaxStemSnap 12
75 struct Type1CPrivateDict {
76 int blueValues[type1CMaxBlueValues];
78 int otherBlues[type1CMaxOtherBlues];
80 int familyBlues[type1CMaxBlueValues];
82 int familyOtherBlues[type1CMaxOtherBlues];
83 int nFamilyOtherBlues;
91 double stemSnapH[type1CMaxStemSnap];
93 double stemSnapV[type1CMaxStemSnap];
97 double forceBoldThreshold;
99 double expansionFactor;
100 int initialRandomSeed;
102 double defaultWidthX;
103 GBool defaultWidthXFP;
104 double nominalWidthX;
105 GBool nominalWidthXFP;
109 GBool isNum; // true -> number, false -> operator
110 GBool isFP; // true -> floating point number, false -> int
112 double num; // if num is true
113 int op; // if num is false
117 struct Type1CEexecBuf {
118 FoFiOutputFunc outputFunc;
120 GBool ascii; // ASCII encoding?
121 Gushort r1; // eexec encryption key
122 int line; // number of eexec chars left on current line
125 //------------------------------------------------------------------------
127 //------------------------------------------------------------------------
129 class FoFiType1C: public FoFiBase {
132 // Create a FoFiType1C object from a memory buffer.
133 static FoFiType1C *make(char *fileA, int lenA);
135 // Create a FoFiType1C object from a file on disk.
136 static FoFiType1C *load(char *fileName);
138 virtual ~FoFiType1C();
140 // Return the font name.
143 // Return the encoding, as an array of 256 names (any of which may
144 // be NULL). This is only useful with 8-bit fonts.
145 char **getEncoding();
147 // Return the mapping from CIDs to GIDs, and return the number of
148 // CIDs in *<nCIDs>. This is only useful for CID fonts.
149 Gushort *getCIDToGIDMap(int *nCIDs);
151 // Convert to a Type 1 font, suitable for embedding in a PostScript
152 // file. This is only useful with 8-bit fonts. If <newEncoding> is
153 // not NULL, it will be used in place of the encoding in the Type 1C
154 // font. If <ascii> is true the eexec section will be hex-encoded,
155 // otherwise it will be left as binary data.
156 void convertToType1(char **newEncoding, GBool ascii,
157 FoFiOutputFunc outputFunc, void *outputStream);
159 // Convert to a Type 0 CIDFont, suitable for embedding in a
160 // PostScript file. <psName> will be used as the PostScript font
162 void convertToCIDType0(char *psName,
163 FoFiOutputFunc outputFunc, void *outputStream);
165 // Convert to a Type 0 (but non-CID) composite font, suitable for
166 // embedding in a PostScript file. <psName> will be used as the
167 // PostScript font name.
168 void convertToType0(char *psName,
169 FoFiOutputFunc outputFunc, void *outputStream);
173 FoFiType1C(char *fileA, int lenA, GBool freeFileDataA);
174 void eexecCvtGlyph(Type1CEexecBuf *eb, char *glyphName,
175 int offset, int nBytes,
176 Type1CIndex *subrIdx,
177 Type1CPrivateDict *pDict);
178 void cvtGlyph(int offset, int nBytes, GString *charBuf,
179 Type1CIndex *subrIdx, Type1CPrivateDict *pDict,
181 void cvtGlyphWidth(GBool useOp, GString *charBuf,
182 Type1CPrivateDict *pDict);
183 void cvtNum(double x, GBool isFP, GString *charBuf);
184 void eexecWrite(Type1CEexecBuf *eb, char *s);
185 void eexecWriteCharstring(Type1CEexecBuf *eb, Guchar *s, int n);
188 void readFD(int offset, int length, Type1CPrivateDict *pDict);
189 void readPrivateDict(int offset, int length, Type1CPrivateDict *pDict);
191 void buildEncoding();
193 int getOp(int pos, GBool charstring, GBool *ok);
194 int getDeltaIntArray(int *arr, int maxLen);
195 int getDeltaFPArray(double *arr, int maxLen);
196 void getIndex(int pos, Type1CIndex *idx, GBool *ok);
197 void getIndexVal(Type1CIndex *idx, int i, Type1CIndexVal *val, GBool *ok);
198 char *getString(int sid, char *buf, GBool *ok);
204 Type1CIndex topDictIdx;
205 Type1CIndex stringIdx;
206 Type1CIndex gsubrIdx;
207 Type1CIndex charStringsIdx;
209 Type1CTopDict topDict;
210 Type1CPrivateDict *privateDicts;
220 Type1COp ops[49]; // operands and operator
221 int nOps; // number of operands
222 int nHints; // number of hints for the current glyph
223 GBool firstOp; // true if we haven't hit the first op yet