09820365fb90a211321b3366d26f1f6af2e01993
[swftools.git] / pdf2swf / xpdf / GlobalParams.h
1 //========================================================================
2 //
3 // GlobalParams.h
4 //
5 // Copyright 2001-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
8
9 #ifndef GLOBALPARAMS_H
10 #define GLOBALPARAMS_H
11
12 #include <aconf.h>
13
14 #ifdef USE_GCC_PRAGMAS
15 #pragma interface
16 #endif
17
18 #include <stdio.h>
19 #include "gtypes.h"
20 #include "CharTypes.h"
21
22 #if MULTITHREADED
23 #include "GMutex.h"
24 #endif
25
26 class GString;
27 class GList;
28 class GHash;
29 class NameToCharCode;
30 class CharCodeToUnicode;
31 class CharCodeToUnicodeCache;
32 class UnicodeMap;
33 class UnicodeMapCache;
34 class CMap;
35 class CMapCache;
36 class GlobalParams;
37
38 //------------------------------------------------------------------------
39
40 // The global parameters object.
41 extern GlobalParams *globalParams;
42
43 //------------------------------------------------------------------------
44
45 enum DisplayFontParamKind {
46   displayFontT1,
47   displayFontTT
48 };
49
50 class DisplayFontParam {
51 public:
52
53   GString *name;                // font name for 8-bit fonts and named
54                                 //   CID fonts; collection name for
55                                 //   generic CID fonts
56   DisplayFontParamKind kind;
57   union {
58     struct {
59       GString *fileName;
60     } t1;
61     struct {
62       GString *fileName;
63     } tt;
64   };
65
66   DisplayFontParam(GString *nameA, DisplayFontParamKind kindA);
67   ~DisplayFontParam();
68 };
69
70 //------------------------------------------------------------------------
71
72 class PSFontParam {
73 public:
74
75   GString *pdfFontName;         // PDF font name for 8-bit fonts and
76                                 //   named 16-bit fonts; char collection
77                                 //   name for generic 16-bit fonts
78   int wMode;                    // writing mode (0=horiz, 1=vert) for
79                                 //   16-bit fonts
80   GString *psFontName;          // PostScript font name
81   GString *encoding;            // encoding, for 16-bit fonts only
82
83   PSFontParam(GString *pdfFontNameA, int wModeA,
84               GString *psFontNameA, GString *encodingA);
85   ~PSFontParam();
86 };
87
88 //------------------------------------------------------------------------
89
90 enum PSLevel {
91   psLevel1,
92   psLevel1Sep,
93   psLevel2,
94   psLevel2Sep,
95   psLevel3,
96   psLevel3Sep
97 };
98
99 //------------------------------------------------------------------------
100
101 enum EndOfLineKind {
102   eolUnix,                      // LF
103   eolDOS,                       // CR+LF
104   eolMac                        // CR
105 };
106
107 //------------------------------------------------------------------------
108
109 class GlobalParams {
110 public:
111
112   // Initialize the global parameters by attempting to read a config
113   // file.
114   GlobalParams(char *cfgFileName);
115
116   ~GlobalParams();
117
118   void setupBaseFonts(char *dir);
119
120   //----- accessors
121
122   CharCode getMacRomanCharCode(char *charName);
123
124   Unicode mapNameToUnicode(char *charName);
125   UnicodeMap *getResidentUnicodeMap(GString *encodingName);
126   FILE *getUnicodeMapFile(GString *encodingName);
127   FILE *findCMapFile(GString *collection, GString *cMapName);
128   FILE *findToUnicodeFile(GString *name);
129   DisplayFontParam *getDisplayFont(GString *fontName);
130   DisplayFontParam *getDisplayCIDFont(GString *fontName, GString *collection);
131   GString *getPSFile();
132   int getPSPaperWidth();
133   int getPSPaperHeight();
134   void getPSImageableArea(int *llx, int *lly, int *urx, int *ury);
135   GBool getPSDuplex();
136   GBool getPSCrop();
137   GBool getPSExpandSmaller();
138   GBool getPSShrinkLarger();
139   GBool getPSCenter();
140   PSLevel getPSLevel();
141   PSFontParam *getPSFont(GString *fontName);
142   PSFontParam *getPSFont16(GString *fontName, GString *collection, int wMode);
143   GBool getPSEmbedType1();
144   GBool getPSEmbedTrueType();
145   GBool getPSEmbedCIDPostScript();
146   GBool getPSEmbedCIDTrueType();
147   GBool getPSOPI();
148   GBool getPSASCIIHex();
149   GString *getTextEncodingName();
150   EndOfLineKind getTextEOL();
151   GBool getTextPageBreaks();
152   GBool getTextKeepTinyChars();
153   GString *findFontFile(GString *fontName, char **exts);
154   GString *getInitialZoom();
155   GBool getEnableT1lib();
156   GBool getEnableFreeType();
157   GBool getAntialias();
158   GString *getURLCommand() { return urlCommand; }
159   GString *getMovieCommand() { return movieCommand; }
160   GBool getMapNumericCharNames();
161   GBool getPrintCommands();
162   GBool getErrQuiet();
163
164   CharCodeToUnicode *getCIDToUnicode(GString *collection);
165   CharCodeToUnicode *getUnicodeToUnicode(GString *fontName);
166   UnicodeMap *getUnicodeMap(GString *encodingName);
167   CMap *getCMap(GString *collection, GString *cMapName);
168   UnicodeMap *getTextEncoding();
169
170   //----- functions to set parameters
171
172   void addDisplayFont(DisplayFontParam *param);
173   void setPSFile(char *file);
174   GBool setPSPaperSize(char *size);
175   void setPSPaperWidth(int width);
176   void setPSPaperHeight(int height);
177   void setPSImageableArea(int llx, int lly, int urx, int ury);
178   void setPSDuplex(GBool duplex);
179   void setPSCrop(GBool crop);
180   void setPSExpandSmaller(GBool expand);
181   void setPSShrinkLarger(GBool shrink);
182   void setPSCenter(GBool center);
183   void setPSLevel(PSLevel level);
184   void setPSEmbedType1(GBool embed);
185   void setPSEmbedTrueType(GBool embed);
186   void setPSEmbedCIDPostScript(GBool embed);
187   void setPSEmbedCIDTrueType(GBool embed);
188   void setPSOPI(GBool opi);
189   void setPSASCIIHex(GBool hex);
190   void setTextEncoding(char *encodingName);
191   GBool setTextEOL(char *s);
192   void setTextPageBreaks(GBool pageBreaks);
193   void setTextKeepTinyChars(GBool keep);
194   void setInitialZoom(char *s);
195   GBool setEnableT1lib(char *s);
196   GBool setEnableFreeType(char *s);
197   GBool setAntialias(char *s);
198   void setMapNumericCharNames(GBool map);
199   void setPrintCommands(GBool printCommandsA);
200   void setErrQuiet(GBool errQuietA);
201   void parseFile(GString *fileName, FILE *f);
202
203 private:
204
205   void parseNameToUnicode(GList *tokens, GString *fileName, int line);
206   void parseCIDToUnicode(GList *tokens, GString *fileName, int line);
207   void parseUnicodeToUnicode(GList *tokens, GString *fileName, int line);
208   void parseUnicodeMap(GList *tokens, GString *fileName, int line);
209   void parseCMapDir(GList *tokens, GString *fileName, int line);
210   void parseToUnicodeDir(GList *tokens, GString *fileName, int line);
211   void parseDisplayFont(GList *tokens, GHash *fontHash,
212                         DisplayFontParamKind kind,
213                         GString *fileName, int line);
214   void parsePSFile(GList *tokens, GString *fileName, int line);
215   void parsePSPaperSize(GList *tokens, GString *fileName, int line);
216   void parsePSImageableArea(GList *tokens, GString *fileName, int line);
217   void parsePSLevel(GList *tokens, GString *fileName, int line);
218   void parsePSFont(GList *tokens, GString *fileName, int line);
219   void parsePSFont16(char *cmdName, GList *fontList,
220                      GList *tokens, GString *fileName, int line);
221   void parseTextEncoding(GList *tokens, GString *fileName, int line);
222   void parseTextEOL(GList *tokens, GString *fileName, int line);
223   void parseFontDir(GList *tokens, GString *fileName, int line);
224   void parseInitialZoom(GList *tokens, GString *fileName, int line);
225   void parseCommand(char *cmdName, GString **val,
226                     GList *tokens, GString *fileName, int line);
227   void parseYesNo(char *cmdName, GBool *flag,
228                   GList *tokens, GString *fileName, int line);
229   GBool parseYesNo2(char *token, GBool *flag);
230   UnicodeMap *getUnicodeMap2(GString *encodingName);
231   
232   //----- config file base path
233
234   GString*path;
235
236   //----- static tables
237
238   NameToCharCode *              // mapping from char name to
239     macRomanReverseMap;         //   MacRomanEncoding index
240
241   //----- user-modifiable settings
242
243   NameToCharCode *              // mapping from char name to Unicode
244     nameToUnicode;
245   GHash *cidToUnicodes;         // files for mappings from char collections
246                                 //   to Unicode, indexed by collection name
247                                 //   [GString]
248   GHash *unicodeToUnicodes;     // files for Unicode-to-Unicode mappings,
249                                 //   indexed by font name pattern [GString]
250   GHash *residentUnicodeMaps;   // mappings from Unicode to char codes,
251                                 //   indexed by encoding name [UnicodeMap]
252   GHash *unicodeMaps;           // files for mappings from Unicode to char
253                                 //   codes, indexed by encoding name [GString]
254   GHash *cMapDirs;              // list of CMap dirs, indexed by collection
255                                 //   name [GList[GString]]
256   GList *toUnicodeDirs;         // list of ToUnicode CMap dirs [GString]
257   GHash *displayFonts;          // display font info, indexed by font name
258                                 //   [DisplayFontParam]
259   GHash *displayCIDFonts;       // display CID font info, indexed by
260                                 //   collection [DisplayFontParam]
261   GHash *displayNamedCIDFonts;  // display CID font info, indexed by
262                                 //   font name [DisplayFontParam]
263   GString *psFile;              // PostScript file or command (for xpdf)
264   int psPaperWidth;             // paper size, in PostScript points, for
265   int psPaperHeight;            //   PostScript output
266   int psImageableLLX,           // imageable area, in PostScript points,
267       psImageableLLY,           //   for PostScript output
268       psImageableURX,
269       psImageableURY;
270   GBool psCrop;                 // crop PS output to CropBox
271   GBool psExpandSmaller;        // expand smaller pages to fill paper
272   GBool psShrinkLarger;         // shrink larger pages to fit paper
273   GBool psCenter;               // center pages on the paper
274   GBool psDuplex;               // enable duplexing in PostScript?
275   PSLevel psLevel;              // PostScript level to generate
276   GHash *psFonts;               // PostScript font info, indexed by PDF
277                                 //   font name [PSFontParam]
278   GList *psNamedFonts16;        // named 16-bit fonts [PSFontParam]
279   GList *psFonts16;             // generic 16-bit fonts [PSFontParam]
280   GBool psEmbedType1;           // embed Type 1 fonts?
281   GBool psEmbedTrueType;        // embed TrueType fonts?
282   GBool psEmbedCIDPostScript;   // embed CID PostScript fonts?
283   GBool psEmbedCIDTrueType;     // embed CID TrueType fonts?
284   GBool psOPI;                  // generate PostScript OPI comments?
285   GBool psASCIIHex;             // use ASCIIHex instead of ASCII85?
286   GString *textEncoding;        // encoding (unicodeMap) to use for text
287                                 //   output
288   EndOfLineKind textEOL;        // type of EOL marker to use for text
289                                 //   output
290   GBool textPageBreaks;         // insert end-of-page markers?
291   GBool textKeepTinyChars;      // keep all characters in text output
292   GList *fontDirs;              // list of font dirs [GString]
293   GString *initialZoom;         // initial zoom level
294   GBool enableT1lib;            // t1lib enable flag
295   GBool enableFreeType;         // FreeType enable flag
296   GBool antialias;              // anti-aliasing enable flag
297   GString *urlCommand;          // command executed for URL links
298   GString *movieCommand;        // command executed for movie annotations
299   GBool mapNumericCharNames;    // map numeric char names (from font subsets)?
300   GBool printCommands;          // print the drawing commands
301   GBool errQuiet;               // suppress error messages?
302
303   CharCodeToUnicodeCache *cidToUnicodeCache;
304   CharCodeToUnicodeCache *unicodeToUnicodeCache;
305   UnicodeMapCache *unicodeMapCache;
306   CMapCache *cMapCache;
307
308 #if MULTITHREADED
309   GMutex mutex;
310   GMutex unicodeMapCacheMutex;
311   GMutex cMapCacheMutex;
312 #endif
313 };
314
315 #endif