e6f2b64d1524c63cee91f72ef8a3a0c3bab69296
[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   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   int blueValues[type1CMaxBlueValues];
77   int nBlueValues;
78   int otherBlues[type1CMaxOtherBlues];
79   int nOtherBlues;
80   int familyBlues[type1CMaxBlueValues];
81   int nFamilyBlues;
82   int familyOtherBlues[type1CMaxOtherBlues];
83   int nFamilyOtherBlues;
84   double blueScale;
85   int blueShift;
86   int blueFuzz;
87   double stdHW;
88   GBool hasStdHW;
89   double stdVW;
90   GBool hasStdVW;
91   double stemSnapH[type1CMaxStemSnap];
92   int nStemSnapH;
93   double stemSnapV[type1CMaxStemSnap];
94   int nStemSnapV;
95   GBool forceBold;
96   GBool hasForceBold;
97   double forceBoldThreshold;
98   int languageGroup;
99   double expansionFactor;
100   int initialRandomSeed;
101   int subrsOffset;
102   double defaultWidthX;
103   GBool defaultWidthXFP;
104   double nominalWidthX;
105   GBool nominalWidthXFP;
106 };
107
108 struct Type1COp {
109   GBool isNum;                  // true -> number, false -> operator
110   GBool isFP;                   // true -> floating point number, false -> int
111   union {
112     double num;                 // if num is true
113     int op;                     // if num is false
114   };
115 };
116
117 struct Type1CEexecBuf {
118   FoFiOutputFunc outputFunc;
119   void *outputStream;
120   GBool ascii;                  // ASCII encoding?
121   Gushort r1;                   // eexec encryption key
122   int line;                     // number of eexec chars left on current line
123 };
124
125 //------------------------------------------------------------------------
126 // FoFiType1C
127 //------------------------------------------------------------------------
128
129 class FoFiType1C: public FoFiBase {
130 public:
131
132   // Create a FoFiType1C object from a memory buffer.
133   static FoFiType1C *make(char *fileA, int lenA);
134
135   // Create a FoFiType1C object from a file on disk.
136   static FoFiType1C *load(char *fileName);
137
138   virtual ~FoFiType1C();
139
140   // Return the font name.
141   char *getName();
142
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();
146
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);
150
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);
158
159   // Convert to a Type 0 CIDFont, suitable for embedding in a
160   // PostScript file.  <psName> will be used as the PostScript font
161   // name.
162   void convertToCIDType0(char *psName,
163                          FoFiOutputFunc outputFunc, void *outputStream);
164
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);
170
171 private:
172
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,
180                 GBool top);
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);
186   GBool parse();
187   void readTopDict();
188   void readFD(int offset, int length, Type1CPrivateDict *pDict);
189   void readPrivateDict(int offset, int length, Type1CPrivateDict *pDict);
190   void readFDSelect();
191   void buildEncoding();
192   GBool readCharset();
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);
199
200   GString *name;
201   char **encoding;
202
203   Type1CIndex nameIdx;
204   Type1CIndex topDictIdx;
205   Type1CIndex stringIdx;
206   Type1CIndex gsubrIdx;
207   Type1CIndex charStringsIdx;
208
209   Type1CTopDict topDict;
210   Type1CPrivateDict *privateDicts;
211
212   int nGlyphs;
213   int nFDs;
214   Guchar *fdSelect;
215   Gushort *charset;
216   int gsubrBias;
217
218   GBool parsedOk;
219
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
224 };
225
226 #endif