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