file(s) added by xpdf 1.01.
[swftools.git] / pdf2swf / xpdf / GlobalParams.h
1 //========================================================================
2 //
3 // GlobalParams.h
4 //
5 // Copyright 2001-2002 Glyph & Cog, LLC
6 //
7 //========================================================================
8
9 #ifndef GLOBALPARAMS_H
10 #define GLOBALPARAMS_H
11
12 #ifdef __GNUC__
13 #pragma interface
14 #endif
15
16 #include <stdio.h>
17 #include "gtypes.h"
18 #include "CharTypes.h"
19
20 class GString;
21 class GList;
22 class GHash;
23 class NameToCharCode;
24 class CharCodeToUnicode;
25 class CIDToUnicodeCache;
26 class UnicodeMap;
27 class UnicodeMapCache;
28 class CMap;
29 class CMapCache;
30 class GlobalParams;
31
32 //------------------------------------------------------------------------
33
34 // The global parameters object.
35 extern GlobalParams *globalParams;
36
37 //------------------------------------------------------------------------
38
39 enum DisplayFontParamKind {
40   displayFontX,
41   displayFontT1,
42   displayFontTT
43 };
44
45 class DisplayFontParam {
46 public:
47
48   GString *name;                // font name for 8-bit fonts and named
49                                 //   CID fonts; collection name for
50                                 //   generic CID fonts
51   DisplayFontParamKind kind;
52   union {
53     struct {
54       GString *xlfd;
55       GString *encoding;
56     } x;
57     struct {
58       GString *fileName;
59     } t1;
60     struct {
61       GString *fileName;
62     } tt;
63   };
64
65   DisplayFontParam(GString *nameA, DisplayFontParamKind kindA);
66   DisplayFontParam(char *nameA, char *xlfdA, char *encodingA);
67   ~DisplayFontParam();
68 };
69
70 // Font rasterizer control.
71 enum FontRastControl {
72   fontRastNone,                 // don't use this rasterizer
73   fontRastPlain,                // use it, without anti-aliasing
74   fontRastAALow,                // use it, with low-level anti-aliasing
75   fontRastAAHigh                // use it, with high-level anti-aliasing
76 };
77
78 //------------------------------------------------------------------------
79
80 class PSFontParam {
81 public:
82
83   GString *pdfFontName;         // PDF font name for 8-bit fonts and
84                                 //   named 16-bit fonts; char collection
85                                 //   name for generic 16-bit fonts
86   int wMode;                    // writing mode (0=horiz, 1=vert) for
87                                 //   16-bit fonts
88   GString *psFontName;          // PostScript font name
89   GString *encoding;            // encoding, for 16-bit fonts only
90
91   PSFontParam(GString *pdfFontNameA, int wModeA,
92               GString *psFontNameA, GString *encodingA);
93   ~PSFontParam();
94 };
95
96 //------------------------------------------------------------------------
97
98 enum PSLevel {
99   psLevel1,
100   psLevel1Sep,
101   psLevel2,
102   psLevel2Sep,
103   psLevel3,
104   psLevel3Sep
105 };
106
107 //------------------------------------------------------------------------
108
109 enum EndOfLineKind {
110   eolUnix,                      // LF
111   eolDOS,                       // CR+LF
112   eolMac                        // CR
113 };
114
115 //------------------------------------------------------------------------
116
117 class GlobalParams {
118 public:
119
120   // Initialize the global parameters by attempting to read a config
121   // file.
122   GlobalParams(char *cfgFileName);
123
124   ~GlobalParams();
125
126   //----- accessors
127
128   CharCode getMacRomanCharCode(char *charName);
129
130   Unicode mapNameToUnicode(char *charName);
131   FILE *getCIDToUnicodeFile(GString *collection);
132   UnicodeMap *getResidentUnicodeMap(GString *encodingName);
133   FILE *getUnicodeMapFile(GString *encodingName);
134   FILE *findCMapFile(GString *collection, GString *cMapName);
135   FILE *findToUnicodeFile(GString *name);
136   DisplayFontParam *getDisplayFont(GString *fontName);
137   DisplayFontParam *getDisplayCIDFont(GString *fontName, GString *collection);
138   GString *getPSFile() { return psFile; }
139   int getPSPaperWidth() { return psPaperWidth; }
140   int getPSPaperHeight() { return psPaperHeight; }
141   GBool getPSDuplex() { return psDuplex; }
142   PSLevel getPSLevel() { return psLevel; }
143   PSFontParam *getPSFont(GString *fontName);
144   PSFontParam *getPSFont16(GString *fontName, GString *collection, int wMode);
145   GBool getPSEmbedType1() { return psEmbedType1; }
146   GBool getPSEmbedTrueType() { return psEmbedTrueType; }
147   GBool getPSEmbedCIDPostScript() { return psEmbedCIDPostScript; }
148   GBool getPSEmbedCIDTrueType() { return psEmbedCIDTrueType; }
149   GBool getPSOPI() { return psOPI; }
150   GBool getPSASCIIHex() { return psASCIIHex; }
151   GString *getTextEncodingName() { return textEncoding; }
152   EndOfLineKind getTextEOL() { return textEOL; }
153   GString *findFontFile(GString *fontName, char *ext1, char *ext2);
154   GString *getInitialZoom() { return initialZoom; }
155   FontRastControl getT1libControl() { return t1libControl; }
156   FontRastControl getFreeTypeControl() { return freetypeControl; }
157   GString *getURLCommand() { return urlCommand; }
158   GBool getMapNumericCharNames() { return mapNumericCharNames; }
159   GBool getErrQuiet() { return errQuiet; }
160
161   CharCodeToUnicode *getCIDToUnicode(GString *collection);
162   UnicodeMap *getUnicodeMap(GString *encodingName);
163   CMap *getCMap(GString *collection, GString *cMapName);
164   UnicodeMap *getTextEncoding();
165
166   //----- functions to set parameters
167
168   void setPSFile(char *file);
169   GBool setPSPaperSize(char *size);
170   void setPSPaperWidth(int width);
171   void setPSPaperHeight(int height);
172   void setPSDuplex(GBool duplex);
173   void setPSLevel(PSLevel level);
174   void setPSEmbedType1(GBool embed);
175   void setPSEmbedTrueType(GBool embed);
176   void setPSEmbedCIDPostScript(GBool embed);
177   void setPSEmbedCIDTrueType(GBool embed);
178   void setPSOPI(GBool opi);
179   void setPSASCIIHex(GBool hex);
180   void setTextEncoding(char *encodingName);
181   GBool setTextEOL(char *s);
182   void setInitialZoom(char *s);
183   GBool setT1libControl(char *s);
184   GBool setFreeTypeControl(char *s);
185   void setErrQuiet(GBool errQuietA);
186
187 private:
188
189   void parseFile(GString *fileName, FILE *f);
190   void parseNameToUnicode(GList *tokens, GString *fileName, int line);
191   void parseCIDToUnicode(GList *tokens, GString *fileName, int line);
192   void parseUnicodeMap(GList *tokens, GString *fileName, int line);
193   void parseCMapDir(GList *tokens, GString *fileName, int line);
194   void parseToUnicodeDir(GList *tokens, GString *fileName, int line);
195   void parseDisplayFont(GList *tokens, GHash *fontHash,
196                         DisplayFontParamKind kind,
197                         GString *fileName, int line);
198   void parsePSFile(GList *tokens, GString *fileName, int line);
199   void parsePSPaperSize(GList *tokens, GString *fileName, int line);
200   void parsePSLevel(GList *tokens, GString *fileName, int line);
201   void parsePSFont(GList *tokens, GString *fileName, int line);
202   void parsePSFont16(char *cmdName, GList *fontList,
203                      GList *tokens, GString *fileName, int line);
204   void parseTextEncoding(GList *tokens, GString *fileName, int line);
205   void parseTextEOL(GList *tokens, GString *fileName, int line);
206   void parseFontDir(GList *tokens, GString *fileName, int line);
207   void parseInitialZoom(GList *tokens, GString *fileName, int line);
208   void parseFontRastControl(char *cmdName, FontRastControl *val,
209                             GList *tokens, GString *fileName, int line);
210   void parseURLCommand(GList *tokens, GString *fileName, int line);
211   void parseYesNo(char *cmdName, GBool *flag,
212                   GList *tokens, GString *fileName, int line);
213   GBool setFontRastControl(FontRastControl *val, char *s);
214
215   //----- static tables
216
217   NameToCharCode *              // mapping from char name to
218     macRomanReverseMap;         //   MacRomanEncoding index
219
220   //----- user-modifiable settings
221
222   NameToCharCode *              // mapping from char name to Unicode
223     nameToUnicode;
224   GHash *cidToUnicodes;         // files for mappings from char collections
225                                 //   to Unicode, indexed by collection name
226                                 //   [GString]
227   GHash *residentUnicodeMaps;   // mappings from Unicode to char codes,
228                                 //   indexed by encoding name [UnicodeMap]
229   GHash *unicodeMaps;           // files for mappings from Unicode to char
230                                 //   codes, indexed by encoding name [GString]
231   GHash *cMapDirs;              // list of CMap dirs, indexed by collection
232                                 //   name [GList[GString]]
233   GList *toUnicodeDirs;         // list of ToUnicode CMap dirs [GString]
234   GHash *displayFonts;          // display font info, indexed by font name
235                                 //   [DisplayFontParam]
236   GHash *displayCIDFonts;       // display CID font info, indexed by
237                                 //   collection [DisplayFontParam]
238   GHash *displayNamedCIDFonts;  // display CID font info, indexed by
239                                 //   font name [DisplayFontParam]
240   GString *psFile;              // PostScript file or command (for xpdf)
241   int psPaperWidth;             // paper size, in PostScript points, for
242   int psPaperHeight;            //   PostScript output
243   GBool psDuplex;               // enable duplexing in PostScript?
244   PSLevel psLevel;              // PostScript level to generate
245   GHash *psFonts;               // PostScript font info, indexed by PDF
246                                 //   font name [PSFontParam]
247   GList *psNamedFonts16;        // named 16-bit fonts [PSFontParam]
248   GList *psFonts16;             // generic 16-bit fonts [PSFontParam]
249   GBool psEmbedType1;           // embed Type 1 fonts?
250   GBool psEmbedTrueType;        // embed TrueType fonts?
251   GBool psEmbedCIDPostScript;   // embed CID PostScript fonts?
252   GBool psEmbedCIDTrueType;     // embed CID TrueType fonts?
253   GBool psOPI;                  // generate PostScript OPI comments?
254   GBool psASCIIHex;             // use ASCIIHex instead of ASCII85?
255   GString *textEncoding;        // encoding (unicodeMap) to use for text
256                                 //   output
257   EndOfLineKind textEOL;        // type of EOL marker to use for text
258                                 //   output
259   GList *fontDirs;              // list of font dirs [GString]
260   GString *initialZoom;         // initial zoom level
261   FontRastControl t1libControl; // t1lib rasterization mode
262   FontRastControl               // FreeType rasterization mode
263     freetypeControl;
264   GString *urlCommand;          // command executed for URL links
265   GBool mapNumericCharNames;    // map numeric char names (from font subsets)?
266   GBool errQuiet;               // suppress error messages?
267
268   CIDToUnicodeCache *cidToUnicodeCache;
269   UnicodeMapCache *unicodeMapCache;
270   CMapCache *cMapCache;
271 };
272
273 #endif