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 class SysFontList;
39 
40 //------------------------------------------------------------------------
41 
42 // The global parameters object.
43 extern GlobalParams *globalParams;
44 
45 //------------------------------------------------------------------------
46 
47 enum SysFontType {
48   sysFontPFA,
49   sysFontPFB,
50   sysFontTTF,
51   sysFontTTC
52 };
53 
54 //------------------------------------------------------------------------
55 
56 class PSFontParam16 {
57 public:
58 
59   GString *name;		// PDF font name for psResidentFont16;
60 				//   char collection name for psResidentFontCC
61   int wMode;			// writing mode (0=horiz, 1=vert)
62   GString *psFontName;		// PostScript font name
63   GString *encoding;		// encoding
64 
65   PSFontParam16(GString *nameA, int wModeA,
66 		GString *psFontNameA, GString *encodingA);
67   ~PSFontParam16();
68 };
69 
70 //------------------------------------------------------------------------
71 
72 enum PSLevel {
73   psLevel1,
74   psLevel1Sep,
75   psLevel2,
76   psLevel2Sep,
77   psLevel3,
78   psLevel3Sep
79 };
80 
81 //------------------------------------------------------------------------
82 
83 enum EndOfLineKind {
84   eolUnix,			// LF
85   eolDOS,			// CR+LF
86   eolMac			// CR
87 };
88 
89 //------------------------------------------------------------------------
90 
91 enum ScreenType {
92   screenUnset,
93   screenDispersed,
94   screenClustered,
95   screenStochasticClustered
96 };
97 
98 //------------------------------------------------------------------------
99 
100 class KeyBinding {
101 public:
102 
103   int code;			// 0x20 .. 0xfe = ASCII,
104 				//   >=0x10000 = special keys, mouse buttons,
105 				//   etc. (xpdfKeyCode* symbols)
106   int mods;			// modifiers (xpdfKeyMod* symbols, or-ed
107 				//   together)
108   int context;			// context (xpdfKeyContext* symbols, or-ed
109 				//   together)
110   GList *cmds;			// list of commands [GString]
111 
112   KeyBinding(int codeA, int modsA, int contextA, const char *cmd0);
113   KeyBinding(int codeA, int modsA, int contextA,
114 	     const char *cmd0, const char *cmd1);
115   KeyBinding(int codeA, int modsA, int contextA, GList *cmdsA);
116   ~KeyBinding();
117 };
118 
119 #define xpdfKeyCodeTab            0x1000
120 #define xpdfKeyCodeReturn         0x1001
121 #define xpdfKeyCodeEnter          0x1002
122 #define xpdfKeyCodeBackspace      0x1003
123 #define xpdfKeyCodeInsert         0x1004
124 #define xpdfKeyCodeDelete         0x1005
125 #define xpdfKeyCodeHome           0x1006
126 #define xpdfKeyCodeEnd            0x1007
127 #define xpdfKeyCodePgUp           0x1008
128 #define xpdfKeyCodePgDn           0x1009
129 #define xpdfKeyCodeLeft           0x100a
130 #define xpdfKeyCodeRight          0x100b
131 #define xpdfKeyCodeUp             0x100c
132 #define xpdfKeyCodeDown           0x100d
133 #define xpdfKeyCodeF1             0x1100
134 #define xpdfKeyCodeF35            0x1122
135 #define xpdfKeyPlus               0x1200
136 #define xpdfKeyMinus	           0x1201
137 #define xpdfKeyCodeMousePress1    0x2001
138 #define xpdfKeyCodeMousePress2    0x2002
139 #define xpdfKeyCodeMousePress3    0x2003
140 #define xpdfKeyCodeMousePress4    0x2004
141 #define xpdfKeyCodeMousePress5    0x2005
142 #define xpdfKeyCodeMousePress6    0x2006
143 #define xpdfKeyCodeMousePress7    0x2007
144 // ...
145 #define xpdfKeyCodeMousePress32   0x2020
146 #define xpdfKeyCodeMouseRelease1  0x2101
147 #define xpdfKeyCodeMouseRelease2  0x2102
148 #define xpdfKeyCodeMouseRelease3  0x2103
149 #define xpdfKeyCodeMouseRelease4  0x2104
150 #define xpdfKeyCodeMouseRelease5  0x2105
151 #define xpdfKeyCodeMouseRelease6  0x2106
152 #define xpdfKeyCodeMouseRelease7  0x2107
153 // ...
154 #define xpdfKeyCodeMouseRelease32 0x2120
155 #define xpdfKeyModNone            0
156 #define xpdfKeyModShift           (1 << 0)
157 #define xpdfKeyModCtrl            (1 << 1)
158 #define xpdfKeyModAlt             (1 << 2)
159 #define xpdfKeyContextAny         0
160 #define xpdfKeyContextFullScreen  (1 << 0)
161 #define xpdfKeyContextWindow      (2 << 0)
162 #define xpdfKeyContextContinuous  (1 << 2)
163 #define xpdfKeyContextSinglePage  (2 << 2)
164 #define xpdfKeyContextOverLink    (1 << 4)
165 #define xpdfKeyContextOffLink     (2 << 4)
166 #define xpdfKeyContextOutline     (1 << 6)
167 #define xpdfKeyContextMainWin     (2 << 6)
168 #define xpdfKeyContextScrLockOn   (1 << 8)
169 #define xpdfKeyContextScrLockOff  (2 << 8)
170 
171 //------------------------------------------------------------------------
172 
173 class GlobalParams {
174 public:
175 
176   // Initialize the global parameters by attempting to read a config
177   // file.
178   GlobalParams(const char *cfgFileName);
179 
180   ~GlobalParams();
181 
182   void setBaseDir(char *dir);
183   void setupBaseFonts(char *dir);
184 
185   void parseLine(char *buf, GString *fileName, int line);
186 
187   //----- accessors
188 
189   CharCode getMacRomanCharCode(char *charName);
190 
191   GString *getBaseDir();
192   Unicode mapNameToUnicode(const char *charName);
193   UnicodeMap *getResidentUnicodeMap(GString *encodingName);
194   FILE *getUnicodeMapFile(GString *encodingName);
195   FILE *findCMapFile(GString *collection, GString *cMapName);
196   FILE *findToUnicodeFile(GString *name);
197   GString *findFontFile(GString *fontName);
198   GString *findBase14FontFile(GString *fontName, int *fontNum,
199 			      double *oblique);
200   GString *findSystemFontFile(GString *fontName, SysFontType *type,
201 			      int *fontNum);
202   GString *findCCFontFile(GString *collection);
203   GString *getPSFile();
204   int getPSPaperWidth();
205   int getPSPaperHeight();
206   void getPSImageableArea(int *llx, int *lly, int *urx, int *ury);
207   GBool getPSDuplex();
208   GBool getPSCrop();
209   GBool getPSUseCropBoxAsPage();
210   GBool getPSExpandSmaller();
211   GBool getPSShrinkLarger();
212   GBool getPSCenter();
213   PSLevel getPSLevel();
214   GString *getPSResidentFont(GString *fontName);
215   GList *getPSResidentFonts();
216   PSFontParam16 *getPSResidentFont16(GString *fontName, int wMode);
217   PSFontParam16 *getPSResidentFontCC(GString *collection, int wMode);
218   GBool getPSEmbedType1();
219   GBool getPSEmbedTrueType();
220   GBool getPSEmbedCIDPostScript();
221   GBool getPSEmbedCIDTrueType();
222   GBool getPSFontPassthrough();
223   GBool getPSPreload();
224   GBool getPSOPI();
225   GBool getPSASCIIHex();
226   GBool getPSLZW();
227   GBool getPSUncompressPreloadedImages();
228   double getPSMinLineWidth();
229   double getPSRasterResolution();
230   GBool getPSRasterMono();
231   int getPSRasterSliceSize();
232   GBool getPSAlwaysRasterize();
233   GString *getTextEncodingName();
234   EndOfLineKind getTextEOL();
235   GBool getTextPageBreaks();
236   GBool getTextKeepTinyChars();
237   GString *getInitialZoom();
238   GBool getContinuousView();
239   GBool getEnableFreeType();
240   GBool getDisableFreeTypeHinting();
241   GBool getAntialias();
242   GBool getVectorAntialias();
243   GBool getAntialiasPrinting();
244   GBool getStrokeAdjust();
245   ScreenType getScreenType();
246   int getScreenSize();
247   int getScreenDotRadius();
248   double getScreenGamma();
249   double getScreenBlackThreshold();
250   double getScreenWhiteThreshold();
251   double getMinLineWidth();
252   GBool getDrawAnnotations();
getOverprintPreview()253   GBool getOverprintPreview() { return overprintPreview; }
getLaunchCommand()254   GString *getLaunchCommand() { return launchCommand; }
getURLCommand()255   GString *getURLCommand() { return urlCommand; }
getMovieCommand()256   GString *getMovieCommand() { return movieCommand; }
257   GBool getMapNumericCharNames();
258   GBool getMapUnknownCharNames();
259   GBool getMapExtTrueTypeFontsViaUnicode();
260   GBool getEnableXFA();
261   GList *getKeyBinding(int code, int mods, int context);
262   GBool getPrintCommands();
263   GBool getErrQuiet();
264 
265   CharCodeToUnicode *getCIDToUnicode(GString *collection);
266   CharCodeToUnicode *getUnicodeToUnicode(GString *fontName);
267   UnicodeMap *getUnicodeMap(GString *encodingName);
268   CMap *getCMap(GString *collection, GString *cMapName);
269   UnicodeMap *getTextEncoding();
270 
271   //----- functions to set parameters
272 
273   void addFontFile(GString *fontName, GString *path);
274   void setPSFile(char *file);
275   GBool setPSPaperSize(char *size);
276   void setPSPaperWidth(int width);
277   void setPSPaperHeight(int height);
278   void setPSImageableArea(int llx, int lly, int urx, int ury);
279   void setPSDuplex(GBool duplex);
280   void setPSCrop(GBool crop);
281   void setPSUseCropBoxAsPage(GBool crop);
282   void setPSExpandSmaller(GBool expand);
283   void setPSShrinkLarger(GBool shrink);
284   void setPSCenter(GBool center);
285   void setPSLevel(PSLevel level);
286   void setPSEmbedType1(GBool embed);
287   void setPSEmbedTrueType(GBool embed);
288   void setPSEmbedCIDPostScript(GBool embed);
289   void setPSEmbedCIDTrueType(GBool embed);
290   void setPSFontPassthrough(GBool passthrough);
291   void setPSPreload(GBool preload);
292   void setPSOPI(GBool opi);
293   void setPSASCIIHex(GBool hex);
294   void setTextEncoding(const char *encodingName);
295   GBool setTextEOL(char *s);
296   void setTextPageBreaks(GBool pageBreaks);
297   void setTextKeepTinyChars(GBool keep);
298   void setInitialZoom(char *s);
299   void setContinuousView(GBool cont);
300   GBool setEnableFreeType(char *s);
301   GBool setAntialias(char *s);
302   GBool setVectorAntialias(char *s);
303   void setScreenType(ScreenType t);
304   void setScreenSize(int size);
305   void setScreenDotRadius(int r);
306   void setScreenGamma(double gamma);
307   void setScreenBlackThreshold(double thresh);
308   void setScreenWhiteThreshold(double thresh);
309   void setMapNumericCharNames(GBool map);
310   void setMapUnknownCharNames(GBool map);
311   void setMapExtTrueTypeFontsViaUnicode(GBool map);
312   void setEnableXFA(GBool enable);
313   void setPrintCommands(GBool printCommandsA);
314   void setErrQuiet(GBool errQuietA);
315 
316   //----- security handlers
317 
318   void addSecurityHandler(XpdfSecurityHandler *handler);
319   XpdfSecurityHandler *getSecurityHandler(char *name);
320 
321 private:
322 
323   void createDefaultKeyBindings();
324   void parseFile(GString *fileName, FILE *f);
325   void parseNameToUnicode(GList *tokens, GString *fileName, int line);
326   void parseCIDToUnicode(GList *tokens, GString *fileName, int line);
327   void parseUnicodeToUnicode(GList *tokens, GString *fileName, int line);
328   void parseUnicodeMap(GList *tokens, GString *fileName, int line);
329   void parseCMapDir(GList *tokens, GString *fileName, int line);
330   void parseToUnicodeDir(GList *tokens, GString *fileName, int line);
331   void parseFontFile(GList *tokens, GString *fileName, int line);
332   void parseFontDir(GList *tokens, GString *fileName, int line);
333   void parseFontFileCC(GList *tokens, GString *fileName,
334 		       int line);
335   void parsePSFile(GList *tokens, GString *fileName, int line);
336   void parsePSPaperSize(GList *tokens, GString *fileName, int line);
337   void parsePSImageableArea(GList *tokens, GString *fileName, int line);
338   void parsePSLevel(GList *tokens, GString *fileName, int line);
339   void parsePSResidentFont(GList *tokens, GString *fileName, int line);
340   void parsePSResidentFont16(GList *tokens, GString *fileName, int line);
341   void parsePSResidentFontCC(GList *tokens, GString *fileName, int line);
342   void parseTextEncoding(GList *tokens, GString *fileName, int line);
343   void parseTextEOL(GList *tokens, GString *fileName, int line);
344   void parseInitialZoom(GList *tokens, GString *fileName, int line);
345   void parseScreenType(GList *tokens, GString *fileName, int line);
346   void parseBind(GList *tokens, GString *fileName, int line);
347   void parseUnbind(GList *tokens, GString *fileName, int line);
348   GBool parseKey(GString *modKeyStr, GString *contextStr,
349 		 int *code, int *mods, int *context,
350 		 const char *cmdName,
351 		 GList *tokens, GString *fileName, int line);
352   void parseCommand(const char *cmdName, GString **val,
353 		    GList *tokens, GString *fileName, int line);
354   void parseYesNo(const char *cmdName, GBool *flag,
355 		  GList *tokens, GString *fileName, int line);
356   GBool parseYesNo2(char *token, GBool *flag);
357   void parseInteger(const char *cmdName, int *val,
358 		    GList *tokens, GString *fileName, int line);
359   void parseFloat(const char *cmdName, double *val,
360 		  GList *tokens, GString *fileName, int line);
361   UnicodeMap *getUnicodeMap2(GString *encodingName);
362 #ifdef ENABLE_PLUGINS
363   GBool loadPlugin(char *type, char *name);
364 #endif
365 
366   //----- static tables
367 
368   NameToCharCode *		// mapping from char name to
369     macRomanReverseMap;		//   MacRomanEncoding index
370 
371   //----- user-modifiable settings
372 
373   GString *baseDir;		// base directory - for plugins, etc.
374   NameToCharCode *		// mapping from char name to Unicode
375     nameToUnicode;
376   GHash *cidToUnicodes;		// files for mappings from char collections
377 				//   to Unicode, indexed by collection name
378 				//   [GString]
379   GHash *unicodeToUnicodes;	// files for Unicode-to-Unicode mappings,
380 				//   indexed by font name pattern [GString]
381   GHash *residentUnicodeMaps;	// mappings from Unicode to char codes,
382 				//   indexed by encoding name [UnicodeMap]
383   GHash *unicodeMaps;		// files for mappings from Unicode to char
384 				//   codes, indexed by encoding name [GString]
385   GHash *cMapDirs;		// list of CMap dirs, indexed by collection
386 				//   name [GList[GString]]
387   GList *toUnicodeDirs;		// list of ToUnicode CMap dirs [GString]
388   GHash *fontFiles;		// font files: font name mapped to path
389 				//   [GString]
390   GList *fontDirs;		// list of font dirs [GString]
391   GHash *ccFontFiles;		// character collection font files:
392 				//   collection name  mapped to path [GString]
393   GHash *base14SysFonts;	// Base-14 system font files: font name
394 				//   mapped to path [Base14FontInfo]
395   SysFontList *sysFonts;	// system fonts
396   GString *psFile;		// PostScript file or command (for xpdf)
397   int psPaperWidth;		// paper size, in PostScript points, for
398   int psPaperHeight;		//   PostScript output
399   int psImageableLLX,		// imageable area, in PostScript points,
400       psImageableLLY,		//   for PostScript output
401       psImageableURX,
402       psImageableURY;
403   GBool psCrop;			// crop PS output to CropBox
404   GBool psUseCropBoxAsPage;	// use CropBox as page size
405   GBool psExpandSmaller;	// expand smaller pages to fill paper
406   GBool psShrinkLarger;		// shrink larger pages to fit paper
407   GBool psCenter;		// center pages on the paper
408   GBool psDuplex;		// enable duplexing in PostScript?
409   PSLevel psLevel;		// PostScript level to generate
410   GHash *psResidentFonts;	// 8-bit fonts resident in printer:
411 				//   PDF font name mapped to PS font name
412 				//   [GString]
413   GList *psResidentFonts16;	// 16-bit fonts resident in printer:
414 				//   PDF font name mapped to font info
415 				//   [PSFontParam16]
416   GList *psResidentFontsCC;	// 16-bit character collection fonts
417 				//   resident in printer: collection name
418 				//   mapped to font info [PSFontParam16]
419   GBool psEmbedType1;		// embed Type 1 fonts?
420   GBool psEmbedTrueType;	// embed TrueType fonts?
421   GBool psEmbedCIDPostScript;	// embed CID PostScript fonts?
422   GBool psEmbedCIDTrueType;	// embed CID TrueType fonts?
423   GBool psFontPassthrough;	// pass all fonts through as-is?
424   GBool psPreload;		// preload PostScript images and forms into
425 				//   memory
426   GBool psOPI;			// generate PostScript OPI comments?
427   GBool psASCIIHex;		// use ASCIIHex instead of ASCII85?
428   GBool psLZW;			// false to use RLE instead of LZW
429   GBool psUncompressPreloadedImages;  // uncompress all preloaded images
430   double psMinLineWidth;	// minimum line width for PostScript output
431   double psRasterResolution;	// PostScript rasterization resolution (dpi)
432   GBool psRasterMono;		// true to do PostScript rasterization
433 				//   in monochrome (gray); false to do it
434 				//   in color (RGB/CMYK)
435   int psRasterSliceSize;	// maximum size (pixels) of PostScript
436 				//   rasterization slice
437   GBool psAlwaysRasterize;	// force PostScript rasterization
438   GString *textEncoding;	// encoding (unicodeMap) to use for text
439 				//   output
440   EndOfLineKind textEOL;	// type of EOL marker to use for text
441 				//   output
442   GBool textPageBreaks;		// insert end-of-page markers?
443   GBool textKeepTinyChars;	// keep all characters in text output
444   GString *initialZoom;		// initial zoom level
445   GBool continuousView;		// continuous view mode
446   GBool enableFreeType;		// FreeType enable flag
447   GBool disableFreeTypeHinting;	// FreeType hinting disable flag
448   GBool antialias;		// font anti-aliasing enable flag
449   GBool vectorAntialias;	// vector anti-aliasing enable flag
450   GBool antialiasPrinting;	// allow anti-aliasing when printing
451   GBool strokeAdjust;		// stroke adjustment enable flag
452   ScreenType screenType;	// halftone screen type
453   int screenSize;		// screen matrix size
454   int screenDotRadius;		// screen dot radius
455   double screenGamma;		// screen gamma correction
456   double screenBlackThreshold;	// screen black clamping threshold
457   double screenWhiteThreshold;	// screen white clamping threshold
458   double minLineWidth;		// minimum line width
459   GBool drawAnnotations;	// draw annotations or not
460   GBool overprintPreview;	// enable overprint preview
461   GString *launchCommand;	// command executed for 'launch' links
462   GString *urlCommand;		// command executed for URL links
463   GString *movieCommand;	// command executed for movie annotations
464   GBool mapNumericCharNames;	// map numeric char names (from font subsets)?
465   GBool mapUnknownCharNames;	// map unknown char names?
466   GBool mapExtTrueTypeFontsViaUnicode;  // map char codes to GID via Unicode
467 				        //   for external TrueType fonts?
468   GBool enableXFA;		// enable XFA form rendering
469   GList *keyBindings;		// key & mouse button bindings [KeyBinding]
470   GBool printCommands;		// print the drawing commands
471   GBool errQuiet;		// suppress error messages?
472 
473   CharCodeToUnicodeCache *cidToUnicodeCache;
474   CharCodeToUnicodeCache *unicodeToUnicodeCache;
475   UnicodeMapCache *unicodeMapCache;
476   CMapCache *cMapCache;
477 
478 #ifdef ENABLE_PLUGINS
479   GList *plugins;		// list of plugins [Plugin]
480   GList *securityHandlers;	// list of loaded security handlers
481 				//   [XpdfSecurityHandler]
482 #endif
483 
484 #if MULTITHREADED
485   GMutex mutex;
486   GMutex unicodeMapCacheMutex;
487   GMutex cMapCacheMutex;
488 #endif
489 };
490 
491 #endif
492