upgraded to xpdf-3.01pl1
[swftools.git] / pdf2swf / xpdf / FoFiType1C.h
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 #ifdef USE_GCC_PRAGMAS
15 #pragma interface
16 #endif
17
18 #include "gtypes.h"
19 #include "FoFiBase.h"
20
21 class GString;
22
23 //------------------------------------------------------------------------
24
25 struct Type1CIndex {
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
31 };
32
33 struct Type1CIndexVal {
34   int pos;                      // absolute position in file
35   int len;                      // length, in bytes
36 };
37
38 struct Type1CTopDict {
39   int firstOp;
40
41   int versionSID;
42   int noticeSID;
43   int copyrightSID;
44   int fullNameSID;
45   int familyNameSID;
46   int weightSID;
47   int isFixedPitch;
48   double italicAngle;
49   double underlinePosition;
50   double underlineThickness;
51   int paintType;
52   int charstringType;
53   double fontMatrix[6];
54   GBool hasFontMatrix;          // CID fonts are allowed to put their
55                                 //   FontMatrix in the FD instead of the
56                                 //   top dict
57   int uniqueID;
58   double fontBBox[4];
59   double strokeWidth;
60   int charsetOffset;
61   int encodingOffset;
62   int charStringsOffset;
63   int privateSize;
64   int privateOffset;
65
66   // CIDFont entries
67   int registrySID;
68   int orderingSID;
69   int supplement;
70   int fdArrayOffset;
71   int fdSelectOffset;
72 };
73
74 #define type1CMaxBlueValues 14
75 #define type1CMaxOtherBlues 10
76 #define type1CMaxStemSnap   12
77
78 struct Type1CPrivateDict {
79   double fontMatrix[6];
80   GBool hasFontMatrix;
81   int blueValues[type1CMaxBlueValues];
82   int nBlueValues;
83   int otherBlues[type1CMaxOtherBlues];
84   int nOtherBlues;
85   int familyBlues[type1CMaxBlueValues];
86   int nFamilyBlues;
87   int familyOtherBlues[type1CMaxOtherBlues];
88   int nFamilyOtherBlues;
89   double blueScale;
90   int blueShift;
91   int blueFuzz;
92   double stdHW;
93   GBool hasStdHW;
94   double stdVW;
95   GBool hasStdVW;
96   double stemSnapH[type1CMaxStemSnap];
97   int nStemSnapH;
98   double stemSnapV[type1CMaxStemSnap];
99   int nStemSnapV;
100   GBool forceBold;
101   GBool hasForceBold;
102   double forceBoldThreshold;
103   int languageGroup;
104   double expansionFactor;
105   int initialRandomSeed;
106   int subrsOffset;
107   double defaultWidthX;
108   GBool defaultWidthXFP;
109   double nominalWidthX;
110   GBool nominalWidthXFP;
111 };
112
113 struct Type1COp {
114   GBool isNum;                  // true -> number, false -> operator
115   GBool isFP;                   // true -> floating point number, false -> int
116   union {
117     double num;                 // if num is true
118     int op;                     // if num is false
119   };
120 };
121
122 struct Type1CEexecBuf {
123   FoFiOutputFunc outputFunc;
124   void *outputStream;
125   GBool ascii;                  // ASCII encoding?
126   Gushort r1;                   // eexec encryption key
127   int line;                     // number of eexec chars left on current line
128 };
129
130 //------------------------------------------------------------------------
131 // FoFiType1C
132 //------------------------------------------------------------------------
133
134 class FoFiType1C: public FoFiBase {
135 public:
136
137   // Create a FoFiType1C object from a memory buffer.
138   static FoFiType1C *make(char *fileA, int lenA);
139
140   // Create a FoFiType1C object from a file on disk.
141   static FoFiType1C *load(char *fileName);
142
143   virtual ~FoFiType1C();
144
145   // Return the font name.
146   char *getName();
147
148   // Return the encoding, as an array of 256 names (any of which may
149   // be NULL).  This is only useful with 8-bit fonts.
150   char **getEncoding();
151
152   // Return the mapping from CIDs to GIDs, and return the number of
153   // CIDs in *<nCIDs>.  This is only useful for CID fonts.
154   Gushort *getCIDToGIDMap(int *nCIDs);
155
156   // Convert to a Type 1 font, suitable for embedding in a PostScript
157   // file.  This is only useful with 8-bit fonts.  If <newEncoding> is
158   // not NULL, it will be used in place of the encoding in the Type 1C
159   // font.  If <ascii> is true the eexec section will be hex-encoded,
160   // otherwise it will be left as binary data.
161   void convertToType1(char **newEncoding, GBool ascii,
162                       FoFiOutputFunc outputFunc, void *outputStream);
163
164   // Convert to a Type 0 CIDFont, suitable for embedding in a
165   // PostScript file.  <psName> will be used as the PostScript font
166   // name.
167   void convertToCIDType0(char *psName,
168                          FoFiOutputFunc outputFunc, void *outputStream);
169
170   // Convert to a Type 0 (but non-CID) composite font, suitable for
171   // embedding in a PostScript file.  <psName> will be used as the
172   // PostScript font name.
173   void convertToType0(char *psName,
174                       FoFiOutputFunc outputFunc, void *outputStream);
175
176 private:
177
178   FoFiType1C(char *fileA, int lenA, GBool freeFileDataA);
179   void eexecCvtGlyph(Type1CEexecBuf *eb, char *glyphName,
180                      int offset, int nBytes,
181                      Type1CIndex *subrIdx,
182                      Type1CPrivateDict *pDict);
183   void cvtGlyph(int offset, int nBytes, GString *charBuf,
184                 Type1CIndex *subrIdx, Type1CPrivateDict *pDict,
185                 GBool top);
186   void cvtGlyphWidth(GBool useOp, GString *charBuf,
187                      Type1CPrivateDict *pDict);
188   void cvtNum(double x, GBool isFP, GString *charBuf);
189   void eexecWrite(Type1CEexecBuf *eb, char *s);
190   void eexecWriteCharstring(Type1CEexecBuf *eb, Guchar *s, int n);
191   GBool parse();
192   void readTopDict();
193   void readFD(int offset, int length, Type1CPrivateDict *pDict);
194   void readPrivateDict(int offset, int length, Type1CPrivateDict *pDict);
195   void readFDSelect();
196   void buildEncoding();
197   GBool readCharset();
198   int getOp(int pos, GBool charstring, GBool *ok);
199   int getDeltaIntArray(int *arr, int maxLen);
200   int getDeltaFPArray(double *arr, int maxLen);
201   void getIndex(int pos, Type1CIndex *idx, GBool *ok);
202   void getIndexVal(Type1CIndex *idx, int i, Type1CIndexVal *val, GBool *ok);
203   char *getString(int sid, char *buf, GBool *ok);
204
205   GString *name;
206   char **encoding;
207
208   Type1CIndex nameIdx;
209   Type1CIndex topDictIdx;
210   Type1CIndex stringIdx;
211   Type1CIndex gsubrIdx;
212   Type1CIndex charStringsIdx;
213
214   Type1CTopDict topDict;
215   Type1CPrivateDict *privateDicts;
216
217   int nGlyphs;
218   int nFDs;
219   Guchar *fdSelect;
220   Gushort *charset;
221   int gsubrBias;
222
223   GBool parsedOk;
224
225   Type1COp ops[49];             // operands and operator
226   int nOps;                     // number of operands
227   int nHints;                   // number of hints for the current glyph
228   GBool firstOp;                // true if we haven't hit the first op yet
229   GBool openPath;               // true if there is an unclosed path
230 };
231
232 #endif