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 #ifdef WIN32 39 class WinFontList; 40 #endif 41 42 //------------------------------------------------------------------------ 43 44 // The global parameters object. 45 extern GlobalParams *globalParams; 46 47 //------------------------------------------------------------------------ 48 49 enum DisplayFontParamKind { 50 displayFontT1, 51 displayFontTT 52 }; 53 54 struct DisplayFontParamT1 { 55 GString *fileName; 56 }; 57 58 struct DisplayFontParamTT { 59 GString *fileName; 60 }; 61 62 class DisplayFontParam { 63 public: 64 65 GString *name; // font name for 8-bit fonts and named 66 // CID fonts; collection name for 67 // generic CID fonts 68 DisplayFontParamKind kind; 69 union { 70 DisplayFontParamT1 t1; 71 DisplayFontParamTT tt; 72 }; 73 74 DisplayFontParam(GString *nameA, DisplayFontParamKind kindA); 75 virtual ~DisplayFontParam(); 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 enum ScreenType { 118 screenUnset, 119 screenDispersed, 120 screenClustered, 121 screenStochasticClustered 122 }; 123 124 //------------------------------------------------------------------------ 125 126 class KeyBinding { 127 public: 128 129 int code; // 0x20 .. 0xfe = ASCII, 130 // >=0x10000 = special keys, mouse buttons, 131 // etc. (xpdfKeyCode* symbols) 132 int mods; // modifiers (xpdfKeyMod* symbols, or-ed 133 // together) 134 int context; // context (xpdfKeyContext* symbols, or-ed 135 // together) 136 GList *cmds; // list of commands [GString] 137 138 KeyBinding(int codeA, int modsA, int contextA, char *cmd0); 139 KeyBinding(int codeA, int modsA, int contextA, char *cmd0, char *cmd1); 140 KeyBinding(int codeA, int modsA, int contextA, GList *cmdsA); 141 ~KeyBinding(); 142 }; 143 144 #define xpdfKeyCodeTab 0x1000 145 #define xpdfKeyCodeReturn 0x1001 146 #define xpdfKeyCodeEnter 0x1002 147 #define xpdfKeyCodeBackspace 0x1003 148 #define xpdfKeyCodeInsert 0x1004 149 #define xpdfKeyCodeDelete 0x1005 150 #define xpdfKeyCodeHome 0x1006 151 #define xpdfKeyCodeEnd 0x1007 152 #define xpdfKeyCodePgUp 0x1008 153 #define xpdfKeyCodePgDn 0x1009 154 #define xpdfKeyCodeLeft 0x100a 155 #define xpdfKeyCodeRight 0x100b 156 #define xpdfKeyCodeUp 0x100c 157 #define xpdfKeyCodeDown 0x100d 158 #define xpdfKeyCodeF1 0x1100 159 #define xpdfKeyCodeF35 0x1122 160 #define xpdfKeyCodeMousePress1 0x2001 161 #define xpdfKeyCodeMousePress2 0x2002 162 #define xpdfKeyCodeMousePress3 0x2003 163 #define xpdfKeyCodeMousePress4 0x2004 164 #define xpdfKeyCodeMousePress5 0x2005 165 #define xpdfKeyCodeMousePress6 0x2006 166 #define xpdfKeyCodeMousePress7 0x2007 167 #define xpdfKeyCodeMouseRelease1 0x2101 168 #define xpdfKeyCodeMouseRelease2 0x2102 169 #define xpdfKeyCodeMouseRelease3 0x2103 170 #define xpdfKeyCodeMouseRelease4 0x2104 171 #define xpdfKeyCodeMouseRelease5 0x2105 172 #define xpdfKeyCodeMouseRelease6 0x2106 173 #define xpdfKeyCodeMouseRelease7 0x2107 174 #define xpdfKeyModNone 0 175 #define xpdfKeyModShift (1 << 0) 176 #define xpdfKeyModCtrl (1 << 1) 177 #define xpdfKeyModAlt (1 << 2) 178 #define xpdfKeyContextAny 0 179 #define xpdfKeyContextFullScreen (1 << 0) 180 #define xpdfKeyContextWindow (2 << 0) 181 #define xpdfKeyContextContinuous (1 << 2) 182 #define xpdfKeyContextSinglePage (2 << 2) 183 #define xpdfKeyContextOverLink (1 << 4) 184 #define xpdfKeyContextOffLink (2 << 4) 185 #define xpdfKeyContextOutline (1 << 6) 186 #define xpdfKeyContextMainWin (2 << 6) 187 #define xpdfKeyContextScrLockOn (1 << 8) 188 #define xpdfKeyContextScrLockOff (2 << 8) 189 190 //------------------------------------------------------------------------ 191 192 class GlobalParams { 193 public: 194 195 // Initialize the global parameters by attempting to read a config 196 // file. 197 GlobalParams(char *cfgFileName); 198 199 virtual ~GlobalParams(); 200 201 void setBaseDir(char *dir); 202 void setupBaseFonts(char *dir); 203 204 void parseLine(char *buf, GString *fileName, int line); 205 206 //----- accessors 207 208 CharCode getMacRomanCharCode(char *charName); 209 210 GString *getBaseDir(); 211 Unicode mapNameToUnicode(char *charName); 212 UnicodeMap *getResidentUnicodeMap(GString *encodingName); 213 FILE *getUnicodeMapFile(GString *encodingName); 214 FILE *findCMapFile(GString *collection, GString *cMapName); 215 FILE *findToUnicodeFile(GString *name); 216 virtual DisplayFontParam *getDisplayFont(GString *fontName); 217 virtual DisplayFontParam *getDisplayCIDFont(GString *fontName, GString *collection); 218 GString *getPSFile(); 219 int getPSPaperWidth(); 220 int getPSPaperHeight(); 221 void getPSImageableArea(int *llx, int *lly, int *urx, int *ury); 222 GBool getPSDuplex(); 223 GBool getPSCrop(); 224 GBool getPSExpandSmaller(); 225 GBool getPSShrinkLarger(); 226 GBool getPSCenter(); 227 PSLevel getPSLevel(); 228 PSFontParam *getPSFont(GString *fontName); 229 PSFontParam *getPSFont16(GString *fontName, GString *collection, int wMode); 230 GBool getPSEmbedType1(); 231 GBool getPSEmbedTrueType(); 232 GBool getPSEmbedCIDPostScript(); 233 GBool getPSEmbedCIDTrueType(); 234 GBool getPSPreload(); 235 GBool getPSOPI(); 236 GBool getPSASCIIHex(); 237 GString *getTextEncodingName(); 238 EndOfLineKind getTextEOL(); 239 GBool getTextPageBreaks(); 240 GBool getTextKeepTinyChars(); 241 GString *findFontFile(GString *fontName, char **exts); 242 GString *getInitialZoom(); 243 GBool getContinuousView(); 244 GBool getEnableT1lib(); 245 GBool getEnableFreeType(); 246 GBool getAntialias(); 247 GBool getVectorAntialias(); 248 GBool getStrokeAdjust(); 249 ScreenType getScreenType(); 250 int getScreenSize(); 251 int getScreenDotRadius(); 252 double getScreenGamma(); 253 double getScreenBlackThreshold(); 254 double getScreenWhiteThreshold(); getURLCommand()255 GString *getURLCommand() { return urlCommand; } getMovieCommand()256 GString *getMovieCommand() { return movieCommand; } 257 GBool getMapNumericCharNames(); 258 GBool getMapUnknownCharNames(); 259 GList *getKeyBinding(int code, int mods, int context); 260 GBool getPrintCommands(); 261 GBool getErrQuiet(); 262 263 CharCodeToUnicode *getCIDToUnicode(GString *collection); 264 CharCodeToUnicode *getUnicodeToUnicode(GString *fontName); 265 UnicodeMap *getUnicodeMap(GString *encodingName); 266 CMap *getCMap(GString *collection, GString *cMapName); 267 UnicodeMap *getTextEncoding(); 268 269 //----- functions to set parameters 270 271 void addDisplayFont(DisplayFontParam *param); 272 void setPSFile(char *file); 273 GBool setPSPaperSize(char *size); 274 void setPSPaperWidth(int width); 275 void setPSPaperHeight(int height); 276 void setPSImageableArea(int llx, int lly, int urx, int ury); 277 void setPSDuplex(GBool duplex); 278 void setPSCrop(GBool crop); 279 void setPSExpandSmaller(GBool expand); 280 void setPSShrinkLarger(GBool shrink); 281 void setPSCenter(GBool center); 282 void setPSLevel(PSLevel level); 283 void setPSEmbedType1(GBool embed); 284 void setPSEmbedTrueType(GBool embed); 285 void setPSEmbedCIDPostScript(GBool embed); 286 void setPSEmbedCIDTrueType(GBool embed); 287 void setPSPreload(GBool preload); 288 void setPSOPI(GBool opi); 289 void setPSASCIIHex(GBool hex); 290 void setTextEncoding(char *encodingName); 291 GBool setTextEOL(char *s); 292 void setTextPageBreaks(GBool pageBreaks); 293 void setTextKeepTinyChars(GBool keep); 294 void setInitialZoom(char *s); 295 void setContinuousView(GBool cont); 296 GBool setEnableT1lib(char *s); 297 GBool setEnableFreeType(char *s); 298 GBool setAntialias(char *s); 299 GBool setVectorAntialias(char *s); 300 void setScreenType(ScreenType t); 301 void setScreenSize(int size); 302 void setScreenDotRadius(int r); 303 void setScreenGamma(double gamma); 304 void setScreenBlackThreshold(double thresh); 305 void setScreenWhiteThreshold(double thresh); 306 void setMapNumericCharNames(GBool map); 307 void setMapUnknownCharNames(GBool map); 308 void setPrintCommands(GBool printCommandsA); 309 void setErrQuiet(GBool errQuietA); 310 311 //----- security handlers 312 313 void addSecurityHandler(XpdfSecurityHandler *handler); 314 XpdfSecurityHandler *getSecurityHandler(char *name); 315 316 private: 317 318 void createDefaultKeyBindings(); 319 public: void parseFile(GString *fileName, FILE *f); private: 320 void parseNameToUnicode(GList *tokens, GString *fileName, int line); 321 void parseCIDToUnicode(GList *tokens, GString *fileName, int line); 322 void parseUnicodeToUnicode(GList *tokens, GString *fileName, int line); 323 void parseUnicodeMap(GList *tokens, GString *fileName, int line); 324 void parseCMapDir(GList *tokens, GString *fileName, int line); 325 void parseToUnicodeDir(GList *tokens, GString *fileName, int line); 326 void parseDisplayFont(GList *tokens, GHash *fontHash, 327 DisplayFontParamKind kind, 328 GString *fileName, int line); 329 void parsePSFile(GList *tokens, GString *fileName, int line); 330 void parsePSPaperSize(GList *tokens, GString *fileName, int line); 331 void parsePSImageableArea(GList *tokens, GString *fileName, int line); 332 void parsePSLevel(GList *tokens, GString *fileName, int line); 333 void parsePSFont(GList *tokens, GString *fileName, int line); 334 void parsePSFont16(char *cmdName, GList *fontList, 335 GList *tokens, GString *fileName, int line); 336 void parseTextEncoding(GList *tokens, GString *fileName, int line); 337 void parseTextEOL(GList *tokens, GString *fileName, int line); 338 void parseFontDir(GList *tokens, GString *fileName, int line); 339 void parseInitialZoom(GList *tokens, GString *fileName, int line); 340 void parseScreenType(GList *tokens, GString *fileName, int line); 341 void parseBind(GList *tokens, GString *fileName, int line); 342 void parseUnbind(GList *tokens, GString *fileName, int line); 343 GBool parseKey(GString *modKeyStr, GString *contextStr, 344 int *code, int *mods, int *context, 345 char *cmdName, 346 GList *tokens, GString *fileName, int line); 347 void parseCommand(char *cmdName, GString **val, 348 GList *tokens, GString *fileName, int line); 349 void parseYesNo(char *cmdName, GBool *flag, 350 GList *tokens, GString *fileName, int line); 351 GBool parseYesNo2(char *token, GBool *flag); 352 void parseInteger(char *cmdName, int *val, 353 GList *tokens, GString *fileName, int line); 354 void parseFloat(char *cmdName, double *val, 355 GList *tokens, GString *fileName, int line); 356 UnicodeMap *getUnicodeMap2(GString *encodingName); 357 #ifdef ENABLE_PLUGINS 358 GBool loadPlugin(char *type, char *name); 359 #endif 360 361 //----- config file base path 362 363 GString*path; 364 365 //----- static tables 366 367 NameToCharCode * // mapping from char name to 368 macRomanReverseMap; // MacRomanEncoding index 369 370 //----- user-modifiable settings 371 372 GString *baseDir; // base directory - for plugins, etc. 373 NameToCharCode * // mapping from char name to Unicode 374 nameToUnicode; 375 GHash *cidToUnicodes; // files for mappings from char collections 376 // to Unicode, indexed by collection name 377 // [GString] 378 GHash *unicodeToUnicodes; // files for Unicode-to-Unicode mappings, 379 // indexed by font name pattern [GString] 380 GHash *residentUnicodeMaps; // mappings from Unicode to char codes, 381 // indexed by encoding name [UnicodeMap] 382 GHash *unicodeMaps; // files for mappings from Unicode to char 383 // codes, indexed by encoding name [GString] 384 GHash *cMapDirs; // list of CMap dirs, indexed by collection 385 // name [GList[GString]] 386 GList *toUnicodeDirs; // list of ToUnicode CMap dirs [GString] 387 GHash *displayFonts; // display font info, indexed by font name 388 // [DisplayFontParam] 389 #ifdef WIN32 390 WinFontList *winFontList; // system TrueType fonts 391 #endif 392 GHash *displayCIDFonts; // display CID font info, indexed by 393 // collection [DisplayFontParam] 394 GHash *displayNamedCIDFonts; // display CID font info, indexed by 395 // font name [DisplayFontParam] 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 psExpandSmaller; // expand smaller pages to fill paper 405 GBool psShrinkLarger; // shrink larger pages to fit paper 406 GBool psCenter; // center pages on the paper 407 GBool psDuplex; // enable duplexing in PostScript? 408 PSLevel psLevel; // PostScript level to generate 409 GHash *psFonts; // PostScript font info, indexed by PDF 410 // font name [PSFontParam] 411 GList *psNamedFonts16; // named 16-bit fonts [PSFontParam] 412 GList *psFonts16; // generic 16-bit fonts [PSFontParam] 413 GBool psEmbedType1; // embed Type 1 fonts? 414 GBool psEmbedTrueType; // embed TrueType fonts? 415 GBool psEmbedCIDPostScript; // embed CID PostScript fonts? 416 GBool psEmbedCIDTrueType; // embed CID TrueType fonts? 417 GBool psPreload; // preload PostScript images and forms into 418 // memory 419 GBool psOPI; // generate PostScript OPI comments? 420 GBool psASCIIHex; // use ASCIIHex instead of ASCII85? 421 GString *textEncoding; // encoding (unicodeMap) to use for text 422 // output 423 EndOfLineKind textEOL; // type of EOL marker to use for text 424 // output 425 GBool textPageBreaks; // insert end-of-page markers? 426 GBool textKeepTinyChars; // keep all characters in text output 427 GList *fontDirs; // list of font dirs [GString] 428 GString *initialZoom; // initial zoom level 429 GBool continuousView; // continuous view mode 430 GBool enableT1lib; // t1lib enable flag 431 GBool enableFreeType; // FreeType enable flag 432 GBool antialias; // font anti-aliasing enable flag 433 GBool vectorAntialias; // vector anti-aliasing enable flag 434 GBool strokeAdjust; // stroke adjustment enable flag 435 ScreenType screenType; // halftone screen type 436 int screenSize; // screen matrix size 437 int screenDotRadius; // screen dot radius 438 double screenGamma; // screen gamma correction 439 double screenBlackThreshold; // screen black clamping threshold 440 double screenWhiteThreshold; // screen white clamping threshold 441 GString *urlCommand; // command executed for URL links 442 GString *movieCommand; // command executed for movie annotations 443 GBool mapNumericCharNames; // map numeric char names (from font subsets)? 444 GBool mapUnknownCharNames; // map unknown char names? 445 GList *keyBindings; // key & mouse button bindings [KeyBinding] 446 GBool printCommands; // print the drawing commands 447 GBool errQuiet; // suppress error messages? 448 449 CharCodeToUnicodeCache *cidToUnicodeCache; 450 CharCodeToUnicodeCache *unicodeToUnicodeCache; 451 UnicodeMapCache *unicodeMapCache; 452 CMapCache *cMapCache; 453 454 #ifdef ENABLE_PLUGINS 455 GList *plugins; // list of plugins [Plugin] 456 GList *securityHandlers; // list of loaded security handlers 457 // [XpdfSecurityHandler] 458 #endif 459 460 #if MULTITHREADED 461 GMutex mutex; 462 GMutex unicodeMapCacheMutex; 463 GMutex cMapCacheMutex; 464 #endif 465 }; 466 467 #endif 468