1 //========================================================================
2 //
3 // GlobalParams.cc
4 //
5 // Copyright 2001-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
8 
9 #include <aconf.h>
10 
11 #ifdef USE_GCC_PRAGMAS
12 #pragma implementation
13 #endif
14 
15 #ifdef _WIN32
16 #  define _WIN32_WINNT 0x0500 // for GetSystemWindowsDirectory
17 #  include <windows.h>
18 #endif
19 #include <string.h>
20 #include <stdio.h>
21 #include <ctype.h>
22 #ifdef ENABLE_PLUGINS
23 #  ifndef _WIN32
24 #    include <dlfcn.h>
25 #  endif
26 #endif
27 #ifdef _WIN32
28 #  include <shlobj.h>
29 #endif
30 #if HAVE_PAPER_H
31 #include <paper.h>
32 #endif
33 #include "gmem.h"
34 #include "GString.h"
35 #include "GList.h"
36 #include "GHash.h"
37 #include "gfile.h"
38 #include "FoFiIdentifier.h"
39 #include "Error.h"
40 #include "NameToCharCode.h"
41 #include "CharCodeToUnicode.h"
42 #include "UnicodeMap.h"
43 #include "CMap.h"
44 #include "BuiltinFontTables.h"
45 #include "FontEncodingTables.h"
46 #ifdef ENABLE_PLUGINS
47 #  include "XpdfPluginAPI.h"
48 #endif
49 #include "GlobalParams.h"
50 
51 #ifdef _WIN32
52 #  define strcasecmp stricmp
53 #  define strncasecmp strnicmp
54 #endif
55 
56 #if MULTITHREADED
57 #  define lockGlobalParams            gLockMutex(&mutex)
58 #  define lockUnicodeMapCache         gLockMutex(&unicodeMapCacheMutex)
59 #  define lockCMapCache               gLockMutex(&cMapCacheMutex)
60 #  define unlockGlobalParams          gUnlockMutex(&mutex)
61 #  define unlockUnicodeMapCache       gUnlockMutex(&unicodeMapCacheMutex)
62 #  define unlockCMapCache             gUnlockMutex(&cMapCacheMutex)
63 #else
64 #  define lockGlobalParams
65 #  define lockUnicodeMapCache
66 #  define lockCMapCache
67 #  define unlockGlobalParams
68 #  define unlockUnicodeMapCache
69 #  define unlockCMapCache
70 #endif
71 
72 #include "NameToUnicodeTable.h"
73 #include "UnicodeMapTables.h"
74 #include "UTF8.h"
75 
76 #ifdef ENABLE_PLUGINS
77 #  ifdef _WIN32
78 extern XpdfPluginVecTable xpdfPluginVecTable;
79 #  endif
80 #endif
81 
82 //------------------------------------------------------------------------
83 
84 #define cidToUnicodeCacheSize     4
85 #define unicodeToUnicodeCacheSize 4
86 
87 //------------------------------------------------------------------------
88 
89 static struct {
90   const char *name;
91   const char *t1FileName;
92   const char *ttFileName;
93   const char *macFileName;	// may be .dfont, .ttf, or .ttc
94   const char *macFontName;	// font name inside .dfont or .ttc
95   const char *obliqueFont;	// name of font to oblique
96   double obliqueFactor;		// oblique sheer factor
97 } displayFontTab[] = {
98   {"Courier",               "n022003l.pfb", "cour.ttf",    "Courier",      "Courier",                NULL,             0},
99   {"Courier-Bold",          "n022004l.pfb", "courbd.ttf",  "Courier",      "Courier Bold",           NULL,             0},
100   {"Courier-BoldOblique",   "n022024l.pfb", "courbi.ttf",  "Courier",      "Courier Bold Oblique",   "Courier-Bold",   0.212557},
101   {"Courier-Oblique",       "n022023l.pfb", "couri.ttf",   "Courier",      "Courier Oblique",        "Courier",        0.212557},
102   {"Helvetica",             "n019003l.pfb", "arial.ttf",   "Helvetica",    "Helvetica",              NULL,             0},
103   {"Helvetica-Bold",        "n019004l.pfb", "arialbd.ttf", "Helvetica",    "Helvetica-Bold",         NULL,             0},
104   {"Helvetica-BoldOblique", "n019024l.pfb", "arialbi.ttf", "Helvetica",    "Helvetica Bold Oblique", "Helvetica-Bold", 0.212557},
105   {"Helvetica-Oblique",     "n019023l.pfb", "ariali.ttf",  "Helvetica",    "Helvetica Oblique",      "Helvetica",      0.212557},
106   {"Symbol",                "s050000l.pfb", NULL,          "Symbol",       "Symbol",                 NULL,             0},
107   {"Times-Bold",            "n021004l.pfb", "timesbd.ttf", "Times",        "Times-Bold",             NULL,             0},
108   {"Times-BoldItalic",      "n021024l.pfb", "timesbi.ttf", "Times",        "Times-BoldItalic",       NULL,             0},
109   {"Times-Italic",          "n021023l.pfb", "timesi.ttf",  "Times",        "Times-Italic",           NULL,             0},
110   {"Times-Roman",           "n021003l.pfb", "times.ttf",   "Times",        "Times-Roman",            NULL,             0},
111   {"ZapfDingbats",          "d050000l.pfb", NULL,          "ZapfDingbats", "Zapf Dingbats",          NULL,             0},
112   {NULL}
113 };
114 
115 #ifdef _WIN32
116 static const char *displayFontDirs[] = {
117   "c:/windows/fonts",
118   "c:/winnt/fonts",
119   NULL
120 };
121 #else
122 static const char *displayFontDirs[] = {
123   "/usr/share/ghostscript/fonts",
124   "/usr/local/share/ghostscript/fonts",
125   "/usr/share/fonts/default/Type1",
126   "/usr/share/fonts/default/ghostscript",
127   "/usr/share/fonts/type1/gsfonts",
128 #if defined(__sun) && defined(__SVR4)
129   "/usr/sfw/share/ghostscript/fonts",
130 #endif
131   NULL
132 };
133 #endif
134 
135 #ifdef __APPLE__
136 static const char *macSystemFontPath = "/System/Library/Fonts";
137 #endif
138 
139 struct Base14FontInfo {
Base14FontInfoBase14FontInfo140   Base14FontInfo(GString *fileNameA, int fontNumA, double obliqueA) {
141     fileName = fileNameA;
142     fontNum = fontNumA;
143     oblique = obliqueA;
144   }
~Base14FontInfoBase14FontInfo145   ~Base14FontInfo() {
146     delete fileName;
147   }
148   GString *fileName;
149   int fontNum;
150   double oblique;
151 };
152 
153 //------------------------------------------------------------------------
154 
155 GlobalParams *globalParams = NULL;
156 
157 //------------------------------------------------------------------------
158 // PSFontParam16
159 //------------------------------------------------------------------------
160 
PSFontParam16(GString * nameA,int wModeA,GString * psFontNameA,GString * encodingA)161 PSFontParam16::PSFontParam16(GString *nameA, int wModeA,
162 			     GString *psFontNameA, GString *encodingA) {
163   name = nameA;
164   wMode = wModeA;
165   psFontName = psFontNameA;
166   encoding = encodingA;
167 }
168 
~PSFontParam16()169 PSFontParam16::~PSFontParam16() {
170   delete name;
171   delete psFontName;
172   delete encoding;
173 }
174 
175 //------------------------------------------------------------------------
176 // SysFontInfo
177 //------------------------------------------------------------------------
178 
179 class SysFontInfo {
180 public:
181 
182   GString *name;
183   GBool bold;
184   GBool italic;
185   GString *path;
186   SysFontType type;
187   int fontNum;			// for TrueType collections
188 
189   SysFontInfo(GString *nameA, GBool boldA, GBool italicA,
190 	      GString *pathA, SysFontType typeA, int fontNumA);
191   ~SysFontInfo();
192   GBool match(SysFontInfo *fi);
193   GBool match(GString *nameA, GBool boldA, GBool italicA);
194 };
195 
SysFontInfo(GString * nameA,GBool boldA,GBool italicA,GString * pathA,SysFontType typeA,int fontNumA)196 SysFontInfo::SysFontInfo(GString *nameA, GBool boldA, GBool italicA,
197 			 GString *pathA, SysFontType typeA, int fontNumA) {
198   name = nameA;
199   bold = boldA;
200   italic = italicA;
201   path = pathA;
202   type = typeA;
203   fontNum = fontNumA;
204 }
205 
~SysFontInfo()206 SysFontInfo::~SysFontInfo() {
207   delete name;
208   delete path;
209 }
210 
match(SysFontInfo * fi)211 GBool SysFontInfo::match(SysFontInfo *fi) {
212   return !strcasecmp(name->getCString(), fi->name->getCString()) &&
213          bold == fi->bold && italic == fi->italic;
214 }
215 
match(GString * nameA,GBool boldA,GBool italicA)216 GBool SysFontInfo::match(GString *nameA, GBool boldA, GBool italicA) {
217   return !strcasecmp(name->getCString(), nameA->getCString()) &&
218          bold == boldA && italic == italicA;
219 }
220 
221 //------------------------------------------------------------------------
222 // SysFontList
223 //------------------------------------------------------------------------
224 
225 class SysFontList {
226 public:
227 
228   SysFontList();
229   ~SysFontList();
230   SysFontInfo *find(GString *name);
231 
232 #ifdef _WIN32
233   void scanWindowsFonts(char *winFontDir);
234 #endif
235 
236 private:
237 
238 #ifdef _WIN32
239   SysFontInfo *makeWindowsFont(char *name, int fontNum,
240 			       char *path);
241 #endif
242 
243   GList *fonts;			// [SysFontInfo]
244 };
245 
SysFontList()246 SysFontList::SysFontList() {
247   fonts = new GList();
248 }
249 
~SysFontList()250 SysFontList::~SysFontList() {
251   deleteGList(fonts, SysFontInfo);
252 }
253 
find(GString * name)254 SysFontInfo *SysFontList::find(GString *name) {
255   GString *name2;
256   GBool bold, italic;
257   SysFontInfo *fi;
258   char c;
259   int n, i;
260 
261   name2 = name->copy();
262 
263   // remove space, comma, dash chars
264   i = 0;
265   while (i < name2->getLength()) {
266     c = name2->getChar(i);
267     if (c == ' ' || c == ',' || c == '-') {
268       name2->del(i);
269     } else {
270       ++i;
271     }
272   }
273   n = name2->getLength();
274 
275   // font names like "Arial-BoldMT,Bold" are occasionally used,
276   // so run this loop twice
277   bold = italic = gFalse;
278   for (i = 0; i < 2; ++i) {
279 
280     // remove trailing "MT" (Foo-MT, Foo-BoldMT, etc.)
281     if (n > 2 && !strcmp(name2->getCString() + n - 2, "MT")) {
282       name2->del(n - 2, 2);
283       n -= 2;
284     }
285 
286     // look for "Regular"
287     if (n > 7 && !strcmp(name2->getCString() + n - 7, "Regular")) {
288       name2->del(n - 7, 7);
289       n -= 7;
290     }
291 
292     // look for "Italic"
293     if (n > 6 && !strcmp(name2->getCString() + n - 6, "Italic")) {
294       name2->del(n - 6, 6);
295       italic = gTrue;
296       n -= 6;
297     }
298 
299     // look for "Bold"
300     if (n > 4 && !strcmp(name2->getCString() + n - 4, "Bold")) {
301       name2->del(n - 4, 4);
302       bold = gTrue;
303       n -= 4;
304     }
305   }
306 
307   // remove trailing "PS"
308   if (n > 2 && !strcmp(name2->getCString() + n - 2, "PS")) {
309     name2->del(n - 2, 2);
310     n -= 2;
311   }
312 
313   // remove trailing "IdentityH"
314   if (n > 9 && !strcmp(name2->getCString() + n - 9, "IdentityH")) {
315     name2->del(n - 9, 9);
316     n -= 9;
317   }
318 
319   // search for the font
320   fi = NULL;
321   for (i = 0; i < fonts->getLength(); ++i) {
322     fi = (SysFontInfo *)fonts->get(i);
323     if (fi->match(name2, bold, italic)) {
324       break;
325     }
326     fi = NULL;
327   }
328   if (!fi && bold) {
329     // try ignoring the bold flag
330     for (i = 0; i < fonts->getLength(); ++i) {
331       fi = (SysFontInfo *)fonts->get(i);
332       if (fi->match(name2, gFalse, italic)) {
333 	break;
334       }
335       fi = NULL;
336     }
337   }
338   if (!fi && (bold || italic)) {
339     // try ignoring the bold and italic flags
340     for (i = 0; i < fonts->getLength(); ++i) {
341       fi = (SysFontInfo *)fonts->get(i);
342       if (fi->match(name2, gFalse, gFalse)) {
343 	break;
344       }
345       fi = NULL;
346     }
347   }
348 
349   delete name2;
350   return fi;
351 }
352 
353 #ifdef _WIN32
scanWindowsFonts(char * winFontDir)354 void SysFontList::scanWindowsFonts(char *winFontDir) {
355   OSVERSIONINFO version;
356   char *path;
357   DWORD idx, valNameLen, dataLen, type;
358   HKEY regKey;
359   char valName[1024], data[1024];
360   int n, fontNum;
361   char *p0, *p1;
362   GString *fontPath;
363 
364   version.dwOSVersionInfoSize = sizeof(version);
365   GetVersionEx(&version);
366   if (version.dwPlatformId == VER_PLATFORM_WIN32_NT) {
367     path = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\\";
368   } else {
369     path = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Fonts\\";
370   }
371   if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, path, 0,
372 		    KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS,
373 		    &regKey) == ERROR_SUCCESS) {
374     idx = 0;
375     while (1) {
376       valNameLen = sizeof(valName) - 1;
377       dataLen = sizeof(data) - 1;
378       if (RegEnumValueA(regKey, idx, valName, &valNameLen, NULL,
379 			&type, (LPBYTE)data, &dataLen) != ERROR_SUCCESS) {
380 	break;
381       }
382       if (type == REG_SZ &&
383 	  valNameLen > 0 && valNameLen < sizeof(valName) &&
384 	  dataLen > 0 && dataLen < sizeof(data)) {
385 	valName[valNameLen] = '\0';
386 	data[dataLen] = '\0';
387 	n = (int)strlen(data);
388 	if (!strcasecmp(data + n - 4, ".ttf") ||
389 	    !strcasecmp(data + n - 4, ".ttc")) {
390 	  fontPath = new GString(data);
391 	  if (!(dataLen >= 3 && data[1] == ':' && data[2] == '\\')) {
392 	    fontPath->insert(0, '\\');
393 	    fontPath->insert(0, winFontDir);
394 	  }
395 	  p0 = valName;
396 	  fontNum = 0;
397 	  while (*p0) {
398 	    p1 = strstr(p0, " & ");
399 	    if (p1) {
400 	      *p1 = '\0';
401 	      p1 = p1 + 3;
402 	    } else {
403 	      p1 = p0 + strlen(p0);
404 	    }
405 	    fonts->append(makeWindowsFont(p0, fontNum,
406 					  fontPath->getCString()));
407 	    p0 = p1;
408 	    ++fontNum;
409 	  }
410 	  delete fontPath;
411 	}
412       }
413       ++idx;
414     }
415     RegCloseKey(regKey);
416   }
417 }
418 
makeWindowsFont(char * name,int fontNum,char * path)419 SysFontInfo *SysFontList::makeWindowsFont(char *name, int fontNum,
420 					  char *path) {
421   int n;
422   GBool bold, italic;
423   GString *s;
424   char c;
425   int i;
426   SysFontType type;
427 
428   n = (int)strlen(name);
429   bold = italic = gFalse;
430 
431   // remove trailing ' (TrueType)'
432   if (n > 11 && !strncmp(name + n - 11, " (TrueType)", 11)) {
433     n -= 11;
434   }
435 
436   // remove trailing ' Italic'
437   if (n > 7 && !strncmp(name + n - 7, " Italic", 7)) {
438     n -= 7;
439     italic = gTrue;
440   }
441 
442   // remove trailing ' Bold'
443   if (n > 5 && !strncmp(name + n - 5, " Bold", 5)) {
444     n -= 5;
445     bold = gTrue;
446   }
447 
448   // remove trailing ' Regular'
449   if (n > 8 && !strncmp(name + n - 8, " Regular", 8)) {
450     n -= 8;
451   }
452 
453   //----- normalize the font name
454   s = new GString(name, n);
455   i = 0;
456   while (i < s->getLength()) {
457     c = s->getChar(i);
458     if (c == ' ' || c == ',' || c == '-') {
459       s->del(i);
460     } else {
461       ++i;
462     }
463   }
464 
465   if (!strcasecmp(path + strlen(path) - 4, ".ttc")) {
466     type = sysFontTTC;
467   } else {
468     type = sysFontTTF;
469   }
470   return new SysFontInfo(s, bold, italic, new GString(path), type, fontNum);
471 }
472 #endif
473 
474 //------------------------------------------------------------------------
475 // KeyBinding
476 //------------------------------------------------------------------------
477 
KeyBinding(int codeA,int modsA,int contextA,const char * cmd0)478 KeyBinding::KeyBinding(int codeA, int modsA, int contextA, const char *cmd0) {
479   code = codeA;
480   mods = modsA;
481   context = contextA;
482   cmds = new GList();
483   cmds->append(new GString(cmd0));
484 }
485 
KeyBinding(int codeA,int modsA,int contextA,const char * cmd0,const char * cmd1)486 KeyBinding::KeyBinding(int codeA, int modsA, int contextA,
487 		       const char *cmd0, const char *cmd1) {
488   code = codeA;
489   mods = modsA;
490   context = contextA;
491   cmds = new GList();
492   cmds->append(new GString(cmd0));
493   cmds->append(new GString(cmd1));
494 }
495 
KeyBinding(int codeA,int modsA,int contextA,GList * cmdsA)496 KeyBinding::KeyBinding(int codeA, int modsA, int contextA, GList *cmdsA) {
497   code = codeA;
498   mods = modsA;
499   context = contextA;
500   cmds = cmdsA;
501 }
502 
~KeyBinding()503 KeyBinding::~KeyBinding() {
504   deleteGList(cmds, GString);
505 }
506 
507 #ifdef ENABLE_PLUGINS
508 //------------------------------------------------------------------------
509 // Plugin
510 //------------------------------------------------------------------------
511 
512 class Plugin {
513 public:
514 
515   static Plugin *load(char *type, char *name);
516   ~Plugin();
517 
518 private:
519 
520 #ifdef _WIN32
521   Plugin(HMODULE libA);
522   HMODULE lib;
523 #else
524   Plugin(void *dlA);
525   void *dl;
526 #endif
527 };
528 
load(char * type,char * name)529 Plugin *Plugin::load(char *type, char *name) {
530   GString *path;
531   Plugin *plugin;
532   XpdfPluginVecTable *vt;
533   XpdfBool (*xpdfInitPlugin)(void);
534 #ifdef _WIN32
535   HMODULE libA;
536 #else
537   void *dlA;
538 #endif
539 
540   path = globalParams->getBaseDir();
541   appendToPath(path, "plugins");
542   appendToPath(path, type);
543   appendToPath(path, name);
544 
545 #ifdef _WIN32
546   path->append(".dll");
547   if (!(libA = LoadLibraryA(path->getCString()))) {
548     error(errIO, -1, "Failed to load plugin '{0:t}'", path);
549     goto err1;
550   }
551   if (!(vt = (XpdfPluginVecTable *)
552 	         GetProcAddress(libA, "xpdfPluginVecTable"))) {
553     error(errIO, -1, "Failed to find xpdfPluginVecTable in plugin '{0:t}'",
554 	  path);
555     goto err2;
556   }
557 #else
558   //~ need to deal with other extensions here
559   path->append(".so");
560   if (!(dlA = dlopen(path->getCString(), RTLD_NOW))) {
561     error(errIO, -1, "Failed to load plugin '{0:t}': {1:s}",
562 	  path, dlerror());
563     goto err1;
564   }
565   if (!(vt = (XpdfPluginVecTable *)dlsym(dlA, "xpdfPluginVecTable"))) {
566     error(errIO, -1, "Failed to find xpdfPluginVecTable in plugin '{0:t}'",
567 	  path);
568     goto err2;
569   }
570 #endif
571 
572   if (vt->version != xpdfPluginVecTable.version) {
573     error(errIO, -1, "Plugin '{0:t}' is wrong version", path);
574     goto err2;
575   }
576   memcpy(vt, &xpdfPluginVecTable, sizeof(xpdfPluginVecTable));
577 
578 #ifdef _WIN32
579   if (!(xpdfInitPlugin = (XpdfBool (*)(void))
580 	                     GetProcAddress(libA, "xpdfInitPlugin"))) {
581     error(errIO, -1, "Failed to find xpdfInitPlugin in plugin '{0:t}'",
582 	  path);
583     goto err2;
584   }
585 #else
586   if (!(xpdfInitPlugin = (XpdfBool (*)(void))dlsym(dlA, "xpdfInitPlugin"))) {
587     error(errIO, -1, "Failed to find xpdfInitPlugin in plugin '{0:t}'",
588 	  path);
589     goto err2;
590   }
591 #endif
592 
593   if (!(*xpdfInitPlugin)()) {
594     error(errIO, -1, "Initialization of plugin '{0:t}' failed", path);
595     goto err2;
596   }
597 
598 #ifdef _WIN32
599   plugin = new Plugin(libA);
600 #else
601   plugin = new Plugin(dlA);
602 #endif
603 
604   delete path;
605   return plugin;
606 
607  err2:
608 #ifdef _WIN32
609   FreeLibrary(libA);
610 #else
611   dlclose(dlA);
612 #endif
613  err1:
614   delete path;
615   return NULL;
616 }
617 
618 #ifdef _WIN32
Plugin(HMODULE libA)619 Plugin::Plugin(HMODULE libA) {
620   lib = libA;
621 }
622 #else
Plugin(void * dlA)623 Plugin::Plugin(void *dlA) {
624   dl = dlA;
625 }
626 #endif
627 
~Plugin()628 Plugin::~Plugin() {
629   void (*xpdfFreePlugin)(void);
630 
631 #ifdef _WIN32
632   if ((xpdfFreePlugin = (void (*)(void))
633                             GetProcAddress(lib, "xpdfFreePlugin"))) {
634     (*xpdfFreePlugin)();
635   }
636   FreeLibrary(lib);
637 #else
638   if ((xpdfFreePlugin = (void (*)(void))dlsym(dl, "xpdfFreePlugin"))) {
639     (*xpdfFreePlugin)();
640   }
641   dlclose(dl);
642 #endif
643 }
644 
645 #endif // ENABLE_PLUGINS
646 
647 //------------------------------------------------------------------------
648 // parsing
649 //------------------------------------------------------------------------
650 
GlobalParams(const char * cfgFileName)651 GlobalParams::GlobalParams(const char *cfgFileName) {
652   UnicodeMap *map;
653   GString *fileName;
654   FILE *f;
655   int i;
656 
657 #if MULTITHREADED
658   gInitMutex(&mutex);
659   gInitMutex(&unicodeMapCacheMutex);
660   gInitMutex(&cMapCacheMutex);
661 #endif
662 
663   initBuiltinFontTables();
664 
665   // scan the encoding in reverse because we want the lowest-numbered
666   // index for each char name ('space' is encoded twice)
667   macRomanReverseMap = new NameToCharCode();
668   for (i = 255; i >= 0; --i) {
669     if (macRomanEncoding[i]) {
670       macRomanReverseMap->add(macRomanEncoding[i], (CharCode)i);
671     }
672   }
673 
674 #ifdef _WIN32
675   // baseDir will be set by a call to setBaseDir
676   baseDir = new GString();
677 #else
678   baseDir = appendToPath(getHomeDir(), ".xpdf");
679 #endif
680   nameToUnicode = new NameToCharCode();
681   cidToUnicodes = new GHash(gTrue);
682   unicodeToUnicodes = new GHash(gTrue);
683   residentUnicodeMaps = new GHash();
684   unicodeMaps = new GHash(gTrue);
685   cMapDirs = new GHash(gTrue);
686   toUnicodeDirs = new GList();
687   fontFiles = new GHash(gTrue);
688   fontDirs = new GList();
689   ccFontFiles = new GHash(gTrue);
690   base14SysFonts = new GHash(gTrue);
691   sysFonts = new SysFontList();
692 #if HAVE_PAPER_H
693   char *paperName;
694   const struct paper *paperType;
695   paperinit();
696   if ((paperName = systempapername())) {
697     paperType = paperinfo(paperName);
698     psPaperWidth = (int)paperpswidth(paperType);
699     psPaperHeight = (int)paperpsheight(paperType);
700   } else {
701     error(errConfig, -1, "No paper information available - using defaults");
702     psPaperWidth = defPaperWidth;
703     psPaperHeight = defPaperHeight;
704   }
705   paperdone();
706 #else
707   psPaperWidth = defPaperWidth;
708   psPaperHeight = defPaperHeight;
709 #endif
710   psImageableLLX = psImageableLLY = 0;
711   psImageableURX = psPaperWidth;
712   psImageableURY = psPaperHeight;
713   psCrop = gTrue;
714   psUseCropBoxAsPage = gFalse;
715   psExpandSmaller = gFalse;
716   psShrinkLarger = gTrue;
717   psCenter = gTrue;
718   psDuplex = gFalse;
719   psLevel = psLevel2;
720   psFile = NULL;
721   psResidentFonts = new GHash(gTrue);
722   psResidentFonts16 = new GList();
723   psResidentFontsCC = new GList();
724   psEmbedType1 = gTrue;
725   psEmbedTrueType = gTrue;
726   psEmbedCIDPostScript = gTrue;
727   psEmbedCIDTrueType = gTrue;
728   psFontPassthrough = gFalse;
729   psPreload = gFalse;
730   psOPI = gFalse;
731   psASCIIHex = gFalse;
732   psLZW = gTrue;
733   psUncompressPreloadedImages = gFalse;
734   psMinLineWidth = 0;
735   psRasterResolution = 300;
736   psRasterMono = gFalse;
737   psRasterSliceSize = 20000000;
738   psAlwaysRasterize = gFalse;
739   textEncoding = new GString("Latin1");
740 #if defined(_WIN32)
741   textEOL = eolDOS;
742 #elif defined(MACOS)
743   textEOL = eolMac;
744 #else
745   textEOL = eolUnix;
746 #endif
747   textPageBreaks = gTrue;
748   textKeepTinyChars = gTrue;
749   initialZoom = new GString("125");
750   continuousView = gFalse;
751   enableFreeType = gTrue;
752   disableFreeTypeHinting = gFalse;
753   antialias = gTrue;
754   vectorAntialias = gTrue;
755   antialiasPrinting = gFalse;
756   strokeAdjust = gTrue;
757   screenType = screenUnset;
758   screenSize = -1;
759   screenDotRadius = -1;
760   screenGamma = 1.0;
761   screenBlackThreshold = 0.0;
762   screenWhiteThreshold = 1.0;
763   minLineWidth = 0.0;
764   drawAnnotations = gTrue;
765   overprintPreview = gFalse;
766   launchCommand = NULL;
767   urlCommand = NULL;
768   movieCommand = NULL;
769   mapNumericCharNames = gTrue;
770   mapUnknownCharNames = gFalse;
771   mapExtTrueTypeFontsViaUnicode = gTrue;
772   enableXFA = gTrue;
773   createDefaultKeyBindings();
774   printCommands = gFalse;
775   errQuiet = gFalse;
776 
777   cidToUnicodeCache = new CharCodeToUnicodeCache(cidToUnicodeCacheSize);
778   unicodeToUnicodeCache =
779       new CharCodeToUnicodeCache(unicodeToUnicodeCacheSize);
780   unicodeMapCache = new UnicodeMapCache();
781   cMapCache = new CMapCache();
782 
783 #ifdef ENABLE_PLUGINS
784   plugins = new GList();
785   securityHandlers = new GList();
786 #endif
787 
788   // set up the initial nameToUnicode table
789   for (i = 0; nameToUnicodeTab[i].name; ++i) {
790     nameToUnicode->add(nameToUnicodeTab[i].name, nameToUnicodeTab[i].u);
791   }
792 
793   // set up the residentUnicodeMaps table
794   map = new UnicodeMap("Latin1", gFalse,
795 		       latin1UnicodeMapRanges, latin1UnicodeMapLen);
796   residentUnicodeMaps->add(map->getEncodingName(), map);
797   map = new UnicodeMap("ASCII7", gFalse,
798 		       ascii7UnicodeMapRanges, ascii7UnicodeMapLen);
799   residentUnicodeMaps->add(map->getEncodingName(), map);
800   map = new UnicodeMap("Symbol", gFalse,
801 		       symbolUnicodeMapRanges, symbolUnicodeMapLen);
802   residentUnicodeMaps->add(map->getEncodingName(), map);
803   map = new UnicodeMap("ZapfDingbats", gFalse, zapfDingbatsUnicodeMapRanges,
804 		       zapfDingbatsUnicodeMapLen);
805   residentUnicodeMaps->add(map->getEncodingName(), map);
806   map = new UnicodeMap("UTF-8", gTrue, &mapUTF8);
807   residentUnicodeMaps->add(map->getEncodingName(), map);
808   map = new UnicodeMap("UCS-2", gTrue, &mapUCS2);
809   residentUnicodeMaps->add(map->getEncodingName(), map);
810 
811   // look for a user config file, then a system-wide config file
812   f = NULL;
813   fileName = NULL;
814   if (cfgFileName && cfgFileName[0]) {
815     fileName = new GString(cfgFileName);
816     if (!(f = fopen(fileName->getCString(), "r"))) {
817       delete fileName;
818     }
819   }
820   if (!f) {
821     fileName = appendToPath(getHomeDir(), xpdfUserConfigFile);
822     if (!(f = fopen(fileName->getCString(), "r"))) {
823       delete fileName;
824     }
825   }
826   if (!f) {
827 #ifdef _WIN32
828     char buf[512];
829     i = GetModuleFileNameA(NULL, buf, sizeof(buf));
830     if (i <= 0 || i >= sizeof(buf)) {
831       // error or path too long for buffer - just use the current dir
832       buf[0] = '\0';
833     }
834     fileName = grabPath(buf);
835     appendToPath(fileName, xpdfSysConfigFile);
836 #else
837     fileName = new GString(xpdfSysConfigFile);
838 #endif
839     if (!(f = fopen(fileName->getCString(), "r"))) {
840       delete fileName;
841     }
842   }
843   if (f) {
844     parseFile(fileName, f);
845     delete fileName;
846     fclose(f);
847   }
848 }
849 
createDefaultKeyBindings()850 void GlobalParams::createDefaultKeyBindings() {
851   keyBindings = new GList();
852 
853   //----- mouse buttons
854   keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress1, xpdfKeyModNone,
855 				     xpdfKeyContextAny, "startSelection"));
856   keyBindings->append(new KeyBinding(xpdfKeyCodeMouseRelease1, xpdfKeyModNone,
857 				     xpdfKeyContextAny, "endSelection",
858 				     "followLinkNoSel"));
859   keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress2, xpdfKeyModNone,
860 				     xpdfKeyContextAny, "startPan"));
861   keyBindings->append(new KeyBinding(xpdfKeyCodeMouseRelease2, xpdfKeyModNone,
862 				     xpdfKeyContextAny, "endPan"));
863   keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress3, xpdfKeyModNone,
864 				     xpdfKeyContextAny, "postPopupMenu"));
865   keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress4, xpdfKeyModNone,
866 				     xpdfKeyContextAny,
867 				     "scrollUpPrevPage(16)"));
868   keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress5, xpdfKeyModNone,
869 				     xpdfKeyContextAny,
870 				     "scrollDownNextPage(16)"));
871   keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress6, xpdfKeyModNone,
872 				     xpdfKeyContextAny, "scrollLeft(16)"));
873   keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress7, xpdfKeyModNone,
874 				     xpdfKeyContextAny, "scrollRight(16)"));
875 
876   //----- keys
877   keyBindings->append(new KeyBinding(xpdfKeyCodeHome, xpdfKeyModCtrl,
878 				     xpdfKeyContextAny, "gotoPage(1)"));
879   keyBindings->append(new KeyBinding(xpdfKeyCodeHome, xpdfKeyModNone,
880 				     xpdfKeyContextAny, "scrollToTopLeft"));
881   keyBindings->append(new KeyBinding(xpdfKeyCodeEnd, xpdfKeyModCtrl,
882 				     xpdfKeyContextAny, "gotoLastPage"));
883   keyBindings->append(new KeyBinding(xpdfKeyCodeEnd, xpdfKeyModNone,
884 				     xpdfKeyContextAny,
885 				     "scrollToBottomRight"));
886   keyBindings->append(new KeyBinding(xpdfKeyCodePgUp, xpdfKeyModNone,
887 				     xpdfKeyContextAny, "pageUp"));
888   keyBindings->append(new KeyBinding(xpdfKeyCodeBackspace, xpdfKeyModNone,
889 				     xpdfKeyContextAny, "pageUp"));
890   keyBindings->append(new KeyBinding(xpdfKeyCodeDelete, xpdfKeyModNone,
891 				     xpdfKeyContextAny, "pageUp"));
892   keyBindings->append(new KeyBinding(xpdfKeyCodePgDn, xpdfKeyModNone,
893 				     xpdfKeyContextAny, "pageDown"));
894   keyBindings->append(new KeyBinding(' ', xpdfKeyModNone,
895 				     xpdfKeyContextAny, "pageDown"));
896   keyBindings->append(new KeyBinding(xpdfKeyCodeLeft, xpdfKeyModNone,
897 				     xpdfKeyContextAny, "scrollLeft(16)"));
898   keyBindings->append(new KeyBinding(xpdfKeyCodeRight, xpdfKeyModNone,
899 				     xpdfKeyContextAny, "scrollRight(16)"));
900   keyBindings->append(new KeyBinding(xpdfKeyCodeUp, xpdfKeyModNone,
901 				     xpdfKeyContextAny, "scrollUp(16)"));
902   keyBindings->append(new KeyBinding(xpdfKeyCodeDown, xpdfKeyModNone,
903 				     xpdfKeyContextAny, "scrollDown(16)"));
904   keyBindings->append(new KeyBinding('o', xpdfKeyModNone,
905 				     xpdfKeyContextAny, "open"));
906   keyBindings->append(new KeyBinding('O', xpdfKeyModNone,
907 				     xpdfKeyContextAny, "open"));
908   keyBindings->append(new KeyBinding('r', xpdfKeyModNone,
909 				     xpdfKeyContextAny, "reload"));
910   keyBindings->append(new KeyBinding('R', xpdfKeyModNone,
911 				     xpdfKeyContextAny, "reload"));
912   keyBindings->append(new KeyBinding('f', xpdfKeyModNone,
913 				     xpdfKeyContextAny, "find"));
914   keyBindings->append(new KeyBinding('F', xpdfKeyModNone,
915 				     xpdfKeyContextAny, "find"));
916   keyBindings->append(new KeyBinding('f', xpdfKeyModCtrl,
917 				     xpdfKeyContextAny, "find"));
918   keyBindings->append(new KeyBinding('g', xpdfKeyModCtrl,
919 				     xpdfKeyContextAny, "findNext"));
920   keyBindings->append(new KeyBinding('p', xpdfKeyModCtrl,
921 				     xpdfKeyContextAny, "print"));
922   keyBindings->append(new KeyBinding('n', xpdfKeyModNone,
923 				     xpdfKeyContextScrLockOff, "nextPage"));
924   keyBindings->append(new KeyBinding('N', xpdfKeyModNone,
925 				     xpdfKeyContextScrLockOff, "nextPage"));
926   keyBindings->append(new KeyBinding('n', xpdfKeyModNone,
927 				     xpdfKeyContextScrLockOn,
928 				     "nextPageNoScroll"));
929   keyBindings->append(new KeyBinding('N', xpdfKeyModNone,
930 				     xpdfKeyContextScrLockOn,
931 				     "nextPageNoScroll"));
932   keyBindings->append(new KeyBinding('p', xpdfKeyModNone,
933 				     xpdfKeyContextScrLockOff, "prevPage"));
934   keyBindings->append(new KeyBinding('P', xpdfKeyModNone,
935 				     xpdfKeyContextScrLockOff, "prevPage"));
936   keyBindings->append(new KeyBinding('p', xpdfKeyModNone,
937 				     xpdfKeyContextScrLockOn,
938 				     "prevPageNoScroll"));
939   keyBindings->append(new KeyBinding('P', xpdfKeyModNone,
940 				     xpdfKeyContextScrLockOn,
941 				     "prevPageNoScroll"));
942   keyBindings->append(new KeyBinding('v', xpdfKeyModNone,
943 				     xpdfKeyContextAny, "goForward"));
944   keyBindings->append(new KeyBinding('b', xpdfKeyModNone,
945 				     xpdfKeyContextAny, "goBackward"));
946   keyBindings->append(new KeyBinding('g', xpdfKeyModNone,
947 				     xpdfKeyContextAny, "focusToPageNum"));
948   keyBindings->append(new KeyBinding('0', xpdfKeyModNone,
949 				     xpdfKeyContextAny, "zoomPercent(125)"));
950   keyBindings->append(new KeyBinding('+', xpdfKeyModNone,
951 				     xpdfKeyContextAny, "zoomIn"));
952   keyBindings->append(new KeyBinding('-', xpdfKeyModNone,
953 				     xpdfKeyContextAny, "zoomOut"));
954   keyBindings->append(new KeyBinding('z', xpdfKeyModNone,
955 				     xpdfKeyContextAny, "zoomFitPage"));
956   keyBindings->append(new KeyBinding('w', xpdfKeyModNone,
957 				     xpdfKeyContextAny, "zoomFitWidth"));
958   keyBindings->append(new KeyBinding('f', xpdfKeyModAlt,
959 				     xpdfKeyContextAny,
960 				     "toggleFullScreenMode"));
961   keyBindings->append(new KeyBinding('l', xpdfKeyModCtrl,
962 				     xpdfKeyContextAny, "redraw"));
963   keyBindings->append(new KeyBinding('w', xpdfKeyModCtrl,
964 				     xpdfKeyContextAny, "closeWindowOrQuit"));
965   keyBindings->append(new KeyBinding('?', xpdfKeyModNone,
966 				     xpdfKeyContextAny, "about"));
967   keyBindings->append(new KeyBinding('q', xpdfKeyModNone,
968 				     xpdfKeyContextAny, "quit"));
969   keyBindings->append(new KeyBinding('Q', xpdfKeyModNone,
970 				     xpdfKeyContextAny, "quit"));
971 }
972 
parseFile(GString * fileName,FILE * f)973 void GlobalParams::parseFile(GString *fileName, FILE *f) {
974   int line;
975   char buf[512];
976 
977   line = 1;
978   while (getLine(buf, sizeof(buf) - 1, f)) {
979     parseLine(buf, fileName, line);
980     ++line;
981   }
982 }
983 
parseLine(char * buf,GString * fileName,int line)984 void GlobalParams::parseLine(char *buf, GString *fileName, int line) {
985   GList *tokens;
986   GString *cmd, *incFile;
987   char *p1, *p2;
988   FILE *f2;
989 
990   // break the line into tokens
991   tokens = new GList();
992   p1 = buf;
993   while (*p1) {
994     for (; *p1 && isspace(*p1); ++p1) ;
995     if (!*p1) {
996       break;
997     }
998     if (*p1 == '"' || *p1 == '\'') {
999       for (p2 = p1 + 1; *p2 && *p2 != *p1; ++p2) ;
1000       ++p1;
1001     } else {
1002       for (p2 = p1 + 1; *p2 && !isspace(*p2); ++p2) ;
1003     }
1004     tokens->append(new GString(p1, (int)(p2 - p1)));
1005     p1 = *p2 ? p2 + 1 : p2;
1006   }
1007 
1008   // parse the line
1009   if (tokens->getLength() > 0 &&
1010       ((GString *)tokens->get(0))->getChar(0) != '#') {
1011     cmd = (GString *)tokens->get(0);
1012     if (!cmd->cmp("include")) {
1013       if (tokens->getLength() == 2) {
1014 	incFile = (GString *)tokens->get(1);
1015 	if ((f2 = openFile(incFile->getCString(), "r"))) {
1016 	  parseFile(incFile, f2);
1017 	  fclose(f2);
1018 	} else {
1019 	  error(errConfig, -1,
1020 		"Couldn't find included config file: '{0:t}' ({1:t}:{2:d})",
1021 		incFile, fileName, line);
1022 	}
1023       } else {
1024 	error(errConfig, -1, "Bad 'include' config file command ({0:t}:{1:d})",
1025 	      fileName, line);
1026       }
1027     } else if (!cmd->cmp("nameToUnicode")) {
1028       parseNameToUnicode(tokens, fileName, line);
1029     } else if (!cmd->cmp("cidToUnicode")) {
1030       parseCIDToUnicode(tokens, fileName, line);
1031     } else if (!cmd->cmp("unicodeToUnicode")) {
1032       parseUnicodeToUnicode(tokens, fileName, line);
1033     } else if (!cmd->cmp("unicodeMap")) {
1034       parseUnicodeMap(tokens, fileName, line);
1035     } else if (!cmd->cmp("cMapDir")) {
1036       parseCMapDir(tokens, fileName, line);
1037     } else if (!cmd->cmp("toUnicodeDir")) {
1038       parseToUnicodeDir(tokens, fileName, line);
1039     } else if (!cmd->cmp("fontFile")) {
1040       parseFontFile(tokens, fileName, line);
1041     } else if (!cmd->cmp("fontDir")) {
1042       parseFontDir(tokens, fileName, line);
1043     } else if (!cmd->cmp("fontFileCC")) {
1044       parseFontFileCC(tokens, fileName, line);
1045     } else if (!cmd->cmp("psFile")) {
1046       parsePSFile(tokens, fileName, line);
1047     } else if (!cmd->cmp("psPaperSize")) {
1048       parsePSPaperSize(tokens, fileName, line);
1049     } else if (!cmd->cmp("psImageableArea")) {
1050       parsePSImageableArea(tokens, fileName, line);
1051     } else if (!cmd->cmp("psCrop")) {
1052       parseYesNo("psCrop", &psCrop, tokens, fileName, line);
1053     } else if (!cmd->cmp("psUseCropBoxAsPage")) {
1054       parseYesNo("psUseCropBoxAsPage", &psUseCropBoxAsPage,
1055 		 tokens, fileName, line);
1056     } else if (!cmd->cmp("psExpandSmaller")) {
1057       parseYesNo("psExpandSmaller", &psExpandSmaller,
1058 		 tokens, fileName, line);
1059     } else if (!cmd->cmp("psShrinkLarger")) {
1060       parseYesNo("psShrinkLarger", &psShrinkLarger, tokens, fileName, line);
1061     } else if (!cmd->cmp("psCenter")) {
1062       parseYesNo("psCenter", &psCenter, tokens, fileName, line);
1063     } else if (!cmd->cmp("psDuplex")) {
1064       parseYesNo("psDuplex", &psDuplex, tokens, fileName, line);
1065     } else if (!cmd->cmp("psLevel")) {
1066       parsePSLevel(tokens, fileName, line);
1067     } else if (!cmd->cmp("psResidentFont")) {
1068       parsePSResidentFont(tokens, fileName, line);
1069     } else if (!cmd->cmp("psResidentFont16")) {
1070       parsePSResidentFont16(tokens, fileName, line);
1071     } else if (!cmd->cmp("psResidentFontCC")) {
1072       parsePSResidentFontCC(tokens, fileName, line);
1073     } else if (!cmd->cmp("psEmbedType1Fonts")) {
1074       parseYesNo("psEmbedType1", &psEmbedType1, tokens, fileName, line);
1075     } else if (!cmd->cmp("psEmbedTrueTypeFonts")) {
1076       parseYesNo("psEmbedTrueType", &psEmbedTrueType,
1077 		 tokens, fileName, line);
1078     } else if (!cmd->cmp("psEmbedCIDPostScriptFonts")) {
1079       parseYesNo("psEmbedCIDPostScript", &psEmbedCIDPostScript,
1080 		 tokens, fileName, line);
1081     } else if (!cmd->cmp("psEmbedCIDTrueTypeFonts")) {
1082       parseYesNo("psEmbedCIDTrueType", &psEmbedCIDTrueType,
1083 		 tokens, fileName, line);
1084     } else if (!cmd->cmp("psFontPassthrough")) {
1085       parseYesNo("psFontPassthrough", &psFontPassthrough,
1086 		 tokens, fileName, line);
1087     } else if (!cmd->cmp("psPreload")) {
1088       parseYesNo("psPreload", &psPreload, tokens, fileName, line);
1089     } else if (!cmd->cmp("psOPI")) {
1090       parseYesNo("psOPI", &psOPI, tokens, fileName, line);
1091     } else if (!cmd->cmp("psASCIIHex")) {
1092       parseYesNo("psASCIIHex", &psASCIIHex, tokens, fileName, line);
1093     } else if (!cmd->cmp("psLZW")) {
1094       parseYesNo("psLZW", &psLZW, tokens, fileName, line);
1095     } else if (!cmd->cmp("psUncompressPreloadedImages")) {
1096       parseYesNo("psUncompressPreloadedImages", &psUncompressPreloadedImages,
1097 		 tokens, fileName, line);
1098     } else if (!cmd->cmp("psMinLineWidth")) {
1099       parseFloat("psMinLineWidth", &psMinLineWidth,
1100 		 tokens, fileName, line);
1101     } else if (!cmd->cmp("psRasterResolution")) {
1102       parseFloat("psRasterResolution", &psRasterResolution,
1103 		 tokens, fileName, line);
1104     } else if (!cmd->cmp("psRasterMono")) {
1105       parseYesNo("psRasterMono", &psRasterMono, tokens, fileName, line);
1106     } else if (!cmd->cmp("psRasterSliceSize")) {
1107       parseInteger("psRasterSliceSize", &psRasterSliceSize,
1108 		   tokens, fileName, line);
1109     } else if (!cmd->cmp("psAlwaysRasterize")) {
1110       parseYesNo("psAlwaysRasterize", &psAlwaysRasterize,
1111 		 tokens, fileName, line);
1112     } else if (!cmd->cmp("textEncoding")) {
1113       parseTextEncoding(tokens, fileName, line);
1114     } else if (!cmd->cmp("textEOL")) {
1115       parseTextEOL(tokens, fileName, line);
1116     } else if (!cmd->cmp("textPageBreaks")) {
1117       parseYesNo("textPageBreaks", &textPageBreaks,
1118 		 tokens, fileName, line);
1119     } else if (!cmd->cmp("textKeepTinyChars")) {
1120       parseYesNo("textKeepTinyChars", &textKeepTinyChars,
1121 		 tokens, fileName, line);
1122     } else if (!cmd->cmp("initialZoom")) {
1123       parseInitialZoom(tokens, fileName, line);
1124     } else if (!cmd->cmp("continuousView")) {
1125       parseYesNo("continuousView", &continuousView, tokens, fileName, line);
1126     } else if (!cmd->cmp("enableFreeType")) {
1127       parseYesNo("enableFreeType", &enableFreeType, tokens, fileName, line);
1128     } else if (!cmd->cmp("disableFreeTypeHinting")) {
1129       parseYesNo("disableFreeTypeHinting", &disableFreeTypeHinting,
1130 		 tokens, fileName, line);
1131     } else if (!cmd->cmp("antialias")) {
1132       parseYesNo("antialias", &antialias, tokens, fileName, line);
1133     } else if (!cmd->cmp("vectorAntialias")) {
1134       parseYesNo("vectorAntialias", &vectorAntialias,
1135 		 tokens, fileName, line);
1136     } else if (!cmd->cmp("antialiasPrinting")) {
1137       parseYesNo("antialiasPrinting", &antialiasPrinting,
1138 		 tokens, fileName, line);
1139     } else if (!cmd->cmp("strokeAdjust")) {
1140       parseYesNo("strokeAdjust", &strokeAdjust, tokens, fileName, line);
1141     } else if (!cmd->cmp("screenType")) {
1142       parseScreenType(tokens, fileName, line);
1143     } else if (!cmd->cmp("screenSize")) {
1144       parseInteger("screenSize", &screenSize, tokens, fileName, line);
1145     } else if (!cmd->cmp("screenDotRadius")) {
1146       parseInteger("screenDotRadius", &screenDotRadius,
1147 		   tokens, fileName, line);
1148     } else if (!cmd->cmp("screenGamma")) {
1149       parseFloat("screenGamma", &screenGamma,
1150 		 tokens, fileName, line);
1151     } else if (!cmd->cmp("screenBlackThreshold")) {
1152       parseFloat("screenBlackThreshold", &screenBlackThreshold,
1153 		 tokens, fileName, line);
1154     } else if (!cmd->cmp("screenWhiteThreshold")) {
1155       parseFloat("screenWhiteThreshold", &screenWhiteThreshold,
1156 		 tokens, fileName, line);
1157     } else if (!cmd->cmp("minLineWidth")) {
1158       parseFloat("minLineWidth", &minLineWidth,
1159 		 tokens, fileName, line);
1160     } else if (!cmd->cmp("drawAnnotations")) {
1161       parseYesNo("drawAnnotations", &drawAnnotations,
1162 		 tokens, fileName, line);
1163     } else if (!cmd->cmp("overprintPreview")) {
1164       parseYesNo("overprintPreview", &overprintPreview,
1165 		 tokens, fileName, line);
1166     } else if (!cmd->cmp("launchCommand")) {
1167       parseCommand("launchCommand", &launchCommand, tokens, fileName, line);
1168     } else if (!cmd->cmp("urlCommand")) {
1169       parseCommand("urlCommand", &urlCommand, tokens, fileName, line);
1170     } else if (!cmd->cmp("movieCommand")) {
1171       parseCommand("movieCommand", &movieCommand, tokens, fileName, line);
1172     } else if (!cmd->cmp("mapNumericCharNames")) {
1173       parseYesNo("mapNumericCharNames", &mapNumericCharNames,
1174 		 tokens, fileName, line);
1175     } else if (!cmd->cmp("mapUnknownCharNames")) {
1176       parseYesNo("mapUnknownCharNames", &mapUnknownCharNames,
1177 		 tokens, fileName, line);
1178     } else if (!cmd->cmp("mapExtTrueTypeFontsViaUnicode")) {
1179       parseYesNo("mapExtTrueTypeFontsViaUnicode",
1180 		 &mapExtTrueTypeFontsViaUnicode,
1181 		 tokens, fileName, line);
1182     } else if (!cmd->cmp("enableXFA")) {
1183       parseYesNo("enableXFA", &enableXFA, tokens, fileName, line);
1184     } else if (!cmd->cmp("bind")) {
1185       parseBind(tokens, fileName, line);
1186     } else if (!cmd->cmp("unbind")) {
1187       parseUnbind(tokens, fileName, line);
1188     } else if (!cmd->cmp("printCommands")) {
1189       parseYesNo("printCommands", &printCommands, tokens, fileName, line);
1190     } else if (!cmd->cmp("errQuiet")) {
1191       parseYesNo("errQuiet", &errQuiet, tokens, fileName, line);
1192     } else {
1193       error(errConfig, -1, "Unknown config file command '{0:t}' ({1:t}:{2:d})",
1194 	    cmd, fileName, line);
1195       if (!cmd->cmp("displayFontX") ||
1196 	  !cmd->cmp("displayNamedCIDFontX") ||
1197 	  !cmd->cmp("displayCIDFontX")) {
1198 	error(errConfig, -1, "Xpdf no longer supports X fonts");
1199       } else if (!cmd->cmp("enableT1lib")) {
1200 	error(errConfig, -1, "Xpdf no longer uses t1lib");
1201       } else if (!cmd->cmp("t1libControl") || !cmd->cmp("freetypeControl")) {
1202 	error(errConfig, -1,
1203 	      "The t1libControl and freetypeControl options have been replaced by the enableT1lib, enableFreeType, and antialias options");
1204       } else if (!cmd->cmp("fontpath") || !cmd->cmp("fontmap")) {
1205 	error(errConfig, -1,
1206 	      "The config file format has changed since Xpdf 0.9x");
1207       }
1208     }
1209   }
1210 
1211   deleteGList(tokens, GString);
1212 }
1213 
parseNameToUnicode(GList * tokens,GString * fileName,int line)1214 void GlobalParams::parseNameToUnicode(GList *tokens, GString *fileName,
1215 				      int line) {
1216   GString *name;
1217   char *tok1, *tok2;
1218   FILE *f;
1219   char buf[256];
1220   int line2;
1221   Unicode u;
1222 
1223   if (tokens->getLength() != 2) {
1224     error(errConfig, -1,
1225 	  "Bad 'nameToUnicode' config file command ({0:t}:{1:d})",
1226 	  fileName, line);
1227     return;
1228   }
1229   name = (GString *)tokens->get(1);
1230   if (!(f = openFile(name->getCString(), "r"))) {
1231     error(errConfig, -1, "Couldn't open 'nameToUnicode' file '{0:t}'", name);
1232     return;
1233   }
1234   line2 = 1;
1235   while (getLine(buf, sizeof(buf), f)) {
1236     tok1 = strtok(buf, " \t\r\n");
1237     tok2 = strtok(NULL, " \t\r\n");
1238     if (tok1 && tok2) {
1239       sscanf(tok1, "%x", &u);
1240       nameToUnicode->add(tok2, u);
1241     } else {
1242       error(errConfig, -1, "Bad line in 'nameToUnicode' file ({0:t}:{1:d})",
1243 	    name, line2);
1244     }
1245     ++line2;
1246   }
1247   fclose(f);
1248 }
1249 
parseCIDToUnicode(GList * tokens,GString * fileName,int line)1250 void GlobalParams::parseCIDToUnicode(GList *tokens, GString *fileName,
1251 				     int line) {
1252   GString *collection, *name, *old;
1253 
1254   if (tokens->getLength() != 3) {
1255     error(errConfig, -1,
1256 	  "Bad 'cidToUnicode' config file command ({0:t}:{1:d})",
1257 	  fileName, line);
1258     return;
1259   }
1260   collection = (GString *)tokens->get(1);
1261   name = (GString *)tokens->get(2);
1262   if ((old = (GString *)cidToUnicodes->remove(collection))) {
1263     delete old;
1264   }
1265   cidToUnicodes->add(collection->copy(), name->copy());
1266 }
1267 
parseUnicodeToUnicode(GList * tokens,GString * fileName,int line)1268 void GlobalParams::parseUnicodeToUnicode(GList *tokens, GString *fileName,
1269 					 int line) {
1270   GString *font, *file, *old;
1271 
1272   if (tokens->getLength() != 3) {
1273     error(errConfig, -1,
1274 	  "Bad 'unicodeToUnicode' config file command ({0:t}:{1:d})",
1275 	  fileName, line);
1276     return;
1277   }
1278   font = (GString *)tokens->get(1);
1279   file = (GString *)tokens->get(2);
1280   if ((old = (GString *)unicodeToUnicodes->remove(font))) {
1281     delete old;
1282   }
1283   unicodeToUnicodes->add(font->copy(), file->copy());
1284 }
1285 
parseUnicodeMap(GList * tokens,GString * fileName,int line)1286 void GlobalParams::parseUnicodeMap(GList *tokens, GString *fileName,
1287 				   int line) {
1288   GString *encodingName, *name, *old;
1289 
1290   if (tokens->getLength() != 3) {
1291     error(errConfig, -1, "Bad 'unicodeMap' config file command ({0:t}:{1:d})",
1292 	  fileName, line);
1293     return;
1294   }
1295   encodingName = (GString *)tokens->get(1);
1296   name = (GString *)tokens->get(2);
1297   if ((old = (GString *)unicodeMaps->remove(encodingName))) {
1298     delete old;
1299   }
1300   unicodeMaps->add(encodingName->copy(), name->copy());
1301 }
1302 
parseCMapDir(GList * tokens,GString * fileName,int line)1303 void GlobalParams::parseCMapDir(GList *tokens, GString *fileName, int line) {
1304   GString *collection, *dir;
1305   GList *list;
1306 
1307   if (tokens->getLength() != 3) {
1308     error(errConfig, -1, "Bad 'cMapDir' config file command ({0:t}:{1:d})",
1309 	  fileName, line);
1310     return;
1311   }
1312   collection = (GString *)tokens->get(1);
1313   dir = (GString *)tokens->get(2);
1314   if (!(list = (GList *)cMapDirs->lookup(collection))) {
1315     list = new GList();
1316     cMapDirs->add(collection->copy(), list);
1317   }
1318   list->append(dir->copy());
1319 }
1320 
parseToUnicodeDir(GList * tokens,GString * fileName,int line)1321 void GlobalParams::parseToUnicodeDir(GList *tokens, GString *fileName,
1322 				     int line) {
1323   if (tokens->getLength() != 2) {
1324     error(errConfig, -1,
1325 	  "Bad 'toUnicodeDir' config file command ({0:t}:{1:d})",
1326 	  fileName, line);
1327     return;
1328   }
1329   toUnicodeDirs->append(((GString *)tokens->get(1))->copy());
1330 }
1331 
parseFontFile(GList * tokens,GString * fileName,int line)1332 void GlobalParams::parseFontFile(GList *tokens, GString *fileName, int line) {
1333   if (tokens->getLength() != 3) {
1334     error(errConfig, -1, "Bad 'fontFile' config file command ({0:t}:{1:d})",
1335 	  fileName, line);
1336     return;
1337   }
1338   fontFiles->add(((GString *)tokens->get(1))->copy(),
1339 		 ((GString *)tokens->get(2))->copy());
1340 }
1341 
parseFontDir(GList * tokens,GString * fileName,int line)1342 void GlobalParams::parseFontDir(GList *tokens, GString *fileName, int line) {
1343   if (tokens->getLength() != 2) {
1344     error(errConfig, -1, "Bad 'fontDir' config file command ({0:t}:{1:d})",
1345 	  fileName, line);
1346     return;
1347   }
1348   fontDirs->append(((GString *)tokens->get(1))->copy());
1349 }
1350 
parseFontFileCC(GList * tokens,GString * fileName,int line)1351 void GlobalParams::parseFontFileCC(GList *tokens, GString *fileName,
1352 				   int line) {
1353   if (tokens->getLength() != 3) {
1354     error(errConfig, -1, "Bad 'fontFileCC' config file command ({0:t}:{1:d})",
1355 	  fileName, line);
1356     return;
1357   }
1358   ccFontFiles->add(((GString *)tokens->get(1))->copy(),
1359 		   ((GString *)tokens->get(2))->copy());
1360 }
1361 
parsePSFile(GList * tokens,GString * fileName,int line)1362 void GlobalParams::parsePSFile(GList *tokens, GString *fileName, int line) {
1363   if (tokens->getLength() != 2) {
1364     error(errConfig, -1, "Bad 'psFile' config file command ({0:t}:{1:d})",
1365 	  fileName, line);
1366     return;
1367   }
1368   if (psFile) {
1369     delete psFile;
1370   }
1371   psFile = ((GString *)tokens->get(1))->copy();
1372 }
1373 
parsePSPaperSize(GList * tokens,GString * fileName,int line)1374 void GlobalParams::parsePSPaperSize(GList *tokens, GString *fileName,
1375 				    int line) {
1376   GString *tok;
1377 
1378   if (tokens->getLength() == 2) {
1379     tok = (GString *)tokens->get(1);
1380     if (!setPSPaperSize(tok->getCString())) {
1381       error(errConfig, -1,
1382 	    "Bad 'psPaperSize' config file command ({0:s}:{1:d})",
1383 	    fileName, line);
1384     }
1385   } else if (tokens->getLength() == 3) {
1386     tok = (GString *)tokens->get(1);
1387     psPaperWidth = atoi(tok->getCString());
1388     tok = (GString *)tokens->get(2);
1389     psPaperHeight = atoi(tok->getCString());
1390     psImageableLLX = psImageableLLY = 0;
1391     psImageableURX = psPaperWidth;
1392     psImageableURY = psPaperHeight;
1393   } else {
1394     error(errConfig, -1, "Bad 'psPaperSize' config file command ({0:t}:{1:d})",
1395 	  fileName, line);
1396   }
1397 }
1398 
parsePSImageableArea(GList * tokens,GString * fileName,int line)1399 void GlobalParams::parsePSImageableArea(GList *tokens, GString *fileName,
1400 					int line) {
1401   if (tokens->getLength() != 5) {
1402     error(errConfig, -1,
1403 	  "Bad 'psImageableArea' config file command ({0:t}:{1:d})",
1404 	  fileName, line);
1405     return;
1406   }
1407   psImageableLLX = atoi(((GString *)tokens->get(1))->getCString());
1408   psImageableLLY = atoi(((GString *)tokens->get(2))->getCString());
1409   psImageableURX = atoi(((GString *)tokens->get(3))->getCString());
1410   psImageableURY = atoi(((GString *)tokens->get(4))->getCString());
1411 }
1412 
parsePSLevel(GList * tokens,GString * fileName,int line)1413 void GlobalParams::parsePSLevel(GList *tokens, GString *fileName, int line) {
1414   GString *tok;
1415 
1416   if (tokens->getLength() != 2) {
1417     error(errConfig, -1, "Bad 'psLevel' config file command ({0:t}:{1:d})",
1418 	  fileName, line);
1419     return;
1420   }
1421   tok = (GString *)tokens->get(1);
1422   if (!tok->cmp("level1")) {
1423     psLevel = psLevel1;
1424   } else if (!tok->cmp("level1sep")) {
1425     psLevel = psLevel1Sep;
1426   } else if (!tok->cmp("level2")) {
1427     psLevel = psLevel2;
1428   } else if (!tok->cmp("level2sep")) {
1429     psLevel = psLevel2Sep;
1430   } else if (!tok->cmp("level3")) {
1431     psLevel = psLevel3;
1432   } else if (!tok->cmp("level3Sep")) {
1433     psLevel = psLevel3Sep;
1434   } else {
1435     error(errConfig, -1, "Bad 'psLevel' config file command ({0:t}:{1:d})",
1436 	  fileName, line);
1437   }
1438 }
1439 
parsePSResidentFont(GList * tokens,GString * fileName,int line)1440 void GlobalParams::parsePSResidentFont(GList *tokens, GString *fileName,
1441 				       int line) {
1442   if (tokens->getLength() != 3) {
1443     error(errConfig, -1, "Bad 'psResidentFont' config file command ({0:t}:{1:d})",
1444 	  fileName, line);
1445     return;
1446   }
1447   psResidentFonts->add(((GString *)tokens->get(1))->copy(),
1448 		       ((GString *)tokens->get(2))->copy());
1449 }
1450 
parsePSResidentFont16(GList * tokens,GString * fileName,int line)1451 void GlobalParams::parsePSResidentFont16(GList *tokens, GString *fileName,
1452 					 int line) {
1453   PSFontParam16 *param;
1454   int wMode;
1455   GString *tok;
1456 
1457   if (tokens->getLength() != 5) {
1458     error(errConfig, -1, "Bad 'psResidentFont16' config file command ({0:t}:{1:d})",
1459 	  fileName, line);
1460     return;
1461   }
1462   tok = (GString *)tokens->get(2);
1463   if (!tok->cmp("H")) {
1464     wMode = 0;
1465   } else if (!tok->cmp("V")) {
1466     wMode = 1;
1467   } else {
1468     error(errConfig, -1, "Bad wMode in psResidentFont16 config file command ({1:t}:{2:d})",
1469 	  fileName, line);
1470     return;
1471   }
1472   param = new PSFontParam16(((GString *)tokens->get(1))->copy(),
1473 			    wMode,
1474 			    ((GString *)tokens->get(3))->copy(),
1475 			    ((GString *)tokens->get(4))->copy());
1476   psResidentFonts16->append(param);
1477 }
1478 
parsePSResidentFontCC(GList * tokens,GString * fileName,int line)1479 void GlobalParams::parsePSResidentFontCC(GList *tokens, GString *fileName,
1480 					 int line) {
1481   PSFontParam16 *param;
1482   int wMode;
1483   GString *tok;
1484 
1485   if (tokens->getLength() != 5) {
1486     error(errConfig, -1, "Bad 'psResidentFontCC' config file command ({0:t}:{1:d})",
1487 	  fileName, line);
1488     return;
1489   }
1490   tok = (GString *)tokens->get(2);
1491   if (!tok->cmp("H")) {
1492     wMode = 0;
1493   } else if (!tok->cmp("V")) {
1494     wMode = 1;
1495   } else {
1496     error(errConfig, -1, "Bad wMode in psResidentFontCC config file command ({1:t}:{2:d})",
1497 	  fileName, line);
1498     return;
1499   }
1500   param = new PSFontParam16(((GString *)tokens->get(1))->copy(),
1501 			    wMode,
1502 			    ((GString *)tokens->get(3))->copy(),
1503 			    ((GString *)tokens->get(4))->copy());
1504   psResidentFontsCC->append(param);
1505 }
1506 
parseTextEncoding(GList * tokens,GString * fileName,int line)1507 void GlobalParams::parseTextEncoding(GList *tokens, GString *fileName,
1508 				     int line) {
1509   if (tokens->getLength() != 2) {
1510     error(errConfig, -1,
1511 	  "Bad 'textEncoding' config file command ({0:s}:{1:d})",
1512 	  fileName, line);
1513     return;
1514   }
1515   delete textEncoding;
1516   textEncoding = ((GString *)tokens->get(1))->copy();
1517 }
1518 
parseTextEOL(GList * tokens,GString * fileName,int line)1519 void GlobalParams::parseTextEOL(GList *tokens, GString *fileName, int line) {
1520   GString *tok;
1521 
1522   if (tokens->getLength() != 2) {
1523     error(errConfig, -1, "Bad 'textEOL' config file command ({0:t}:{1:d})",
1524 	  fileName, line);
1525     return;
1526   }
1527   tok = (GString *)tokens->get(1);
1528   if (!tok->cmp("unix")) {
1529     textEOL = eolUnix;
1530   } else if (!tok->cmp("dos")) {
1531     textEOL = eolDOS;
1532   } else if (!tok->cmp("mac")) {
1533     textEOL = eolMac;
1534   } else {
1535     error(errConfig, -1, "Bad 'textEOL' config file command ({0:t}:{1:d})",
1536 	  fileName, line);
1537   }
1538 }
1539 
parseInitialZoom(GList * tokens,GString * fileName,int line)1540 void GlobalParams::parseInitialZoom(GList *tokens,
1541 				    GString *fileName, int line) {
1542   if (tokens->getLength() != 2) {
1543     error(errConfig, -1, "Bad 'initialZoom' config file command ({0:t}:{1:d})",
1544 	  fileName, line);
1545     return;
1546   }
1547   delete initialZoom;
1548   initialZoom = ((GString *)tokens->get(1))->copy();
1549 }
1550 
parseScreenType(GList * tokens,GString * fileName,int line)1551 void GlobalParams::parseScreenType(GList *tokens, GString *fileName,
1552 				   int line) {
1553   GString *tok;
1554 
1555   if (tokens->getLength() != 2) {
1556     error(errConfig, -1, "Bad 'screenType' config file command ({0:t}:{1:d})",
1557 	  fileName, line);
1558     return;
1559   }
1560   tok = (GString *)tokens->get(1);
1561   if (!tok->cmp("dispersed")) {
1562     screenType = screenDispersed;
1563   } else if (!tok->cmp("clustered")) {
1564     screenType = screenClustered;
1565   } else if (!tok->cmp("stochasticClustered")) {
1566     screenType = screenStochasticClustered;
1567   } else {
1568     error(errConfig, -1, "Bad 'screenType' config file command ({0:t}:{1:d})",
1569 	  fileName, line);
1570   }
1571 }
1572 
1573 
parseBind(GList * tokens,GString * fileName,int line)1574 void GlobalParams::parseBind(GList *tokens, GString *fileName, int line) {
1575   KeyBinding *binding;
1576   GList *cmds;
1577   int code, mods, context, i;
1578 
1579   if (tokens->getLength() < 4) {
1580     error(errConfig, -1, "Bad 'bind' config file command ({0:t}:{1:d})",
1581 	  fileName, line);
1582     return;
1583   }
1584   if (!parseKey((GString *)tokens->get(1), (GString *)tokens->get(2),
1585 		&code, &mods, &context,
1586 		"bind", tokens, fileName, line)) {
1587     return;
1588   }
1589   for (i = 0; i < keyBindings->getLength(); ++i) {
1590     binding = (KeyBinding *)keyBindings->get(i);
1591     if (binding->code == code &&
1592 	binding->mods == mods &&
1593 	binding->context == context) {
1594       delete (KeyBinding *)keyBindings->del(i);
1595       break;
1596     }
1597   }
1598   cmds = new GList();
1599   for (i = 3; i < tokens->getLength(); ++i) {
1600     cmds->append(((GString *)tokens->get(i))->copy());
1601   }
1602   keyBindings->append(new KeyBinding(code, mods, context, cmds));
1603 }
1604 
parseUnbind(GList * tokens,GString * fileName,int line)1605 void GlobalParams::parseUnbind(GList *tokens, GString *fileName, int line) {
1606   KeyBinding *binding;
1607   int code, mods, context, i;
1608 
1609   if (tokens->getLength() != 3) {
1610     error(errConfig, -1, "Bad 'unbind' config file command ({0:t}:{1:d})",
1611 	  fileName, line);
1612     return;
1613   }
1614   if (!parseKey((GString *)tokens->get(1), (GString *)tokens->get(2),
1615 		&code, &mods, &context,
1616 		"unbind", tokens, fileName, line)) {
1617     return;
1618   }
1619   for (i = 0; i < keyBindings->getLength(); ++i) {
1620     binding = (KeyBinding *)keyBindings->get(i);
1621     if (binding->code == code &&
1622 	binding->mods == mods &&
1623 	binding->context == context) {
1624       delete (KeyBinding *)keyBindings->del(i);
1625       break;
1626     }
1627   }
1628 }
1629 
parseKey(GString * modKeyStr,GString * contextStr,int * code,int * mods,int * context,const char * cmdName,GList * tokens,GString * fileName,int line)1630 GBool GlobalParams::parseKey(GString *modKeyStr, GString *contextStr,
1631 			     int *code, int *mods, int *context,
1632 			     const char *cmdName,
1633 			     GList *tokens, GString *fileName, int line) {
1634   char *p0;
1635   int btn;
1636 
1637   *mods = xpdfKeyModNone;
1638   p0 = modKeyStr->getCString();
1639   while (1) {
1640     if (!strncmp(p0, "shift-", 6)) {
1641       *mods |= xpdfKeyModShift;
1642       p0 += 6;
1643     } else if (!strncmp(p0, "ctrl-", 5)) {
1644       *mods |= xpdfKeyModCtrl;
1645       p0 += 5;
1646     } else if (!strncmp(p0, "alt-", 4)) {
1647       *mods |= xpdfKeyModAlt;
1648       p0 += 4;
1649     } else {
1650       break;
1651     }
1652   }
1653 
1654   if (!strcmp(p0, "space")) {
1655     *code = ' ';
1656   } else if (!strcmp(p0, "tab")) {
1657     *code = xpdfKeyCodeTab;
1658   } else if (!strcmp(p0, "return")) {
1659     *code = xpdfKeyCodeReturn;
1660   } else if (!strcmp(p0, "enter")) {
1661     *code = xpdfKeyCodeEnter;
1662   } else if (!strcmp(p0, "backspace")) {
1663     *code = xpdfKeyCodeBackspace;
1664   } else if (!strcmp(p0, "insert")) {
1665     *code = xpdfKeyCodeInsert;
1666   } else if (!strcmp(p0, "delete")) {
1667     *code = xpdfKeyCodeDelete;
1668   } else if (!strcmp(p0, "home")) {
1669     *code = xpdfKeyCodeHome;
1670   } else if (!strcmp(p0, "end")) {
1671     *code = xpdfKeyCodeEnd;
1672   } else if (!strcmp(p0, "pgup")) {
1673     *code = xpdfKeyCodePgUp;
1674   } else if (!strcmp(p0, "pgdn")) {
1675     *code = xpdfKeyCodePgDn;
1676   } else if (!strcmp(p0, "left")) {
1677     *code = xpdfKeyCodeLeft;
1678   } else if (!strcmp(p0, "right")) {
1679     *code = xpdfKeyCodeRight;
1680   } else if (!strcmp(p0, "up")) {
1681     *code = xpdfKeyCodeUp;
1682   } else if (!strcmp(p0, "down")) {
1683     *code = xpdfKeyCodeDown;
1684   } else if (!strcmp(p0, "numpad-plus")) {
1685     *code = xpdfKeyPlus;
1686   } else if (!strcmp(p0, "numpad-minus")) {
1687     *code = xpdfKeyMinus;
1688   } else if (p0[0] == 'f' && p0[1] >= '1' && p0[1] <= '9' && !p0[2]) {
1689     *code = xpdfKeyCodeF1 + (p0[1] - '1');
1690   } else if (p0[0] == 'f' &&
1691 	     ((p0[1] >= '1' && p0[1] <= '2' && p0[2] >= '0' && p0[2] <= '9') ||
1692 	      (p0[1] == '3' && p0[2] >= '0' && p0[2] <= '5')) &&
1693 	     !p0[3]) {
1694     *code = xpdfKeyCodeF1 + 10 * (p0[1] - '0') + (p0[2] - '0') - 1;
1695   } else if (!strncmp(p0, "mousePress", 10) &&
1696 	     p0[10] >= '0' && p0[10] <= '9' &&
1697 	     (!p0[11] || (p0[11] >= '0' && p0[11] <= '9' && !p0[12])) &&
1698 	     (btn = atoi(p0 + 10)) >= 1 && btn <= 32) {
1699     *code = xpdfKeyCodeMousePress1 + btn - 1;
1700   } else if (!strncmp(p0, "mouseRelease", 12) &&
1701 	     p0[12] >= '0' && p0[12] <= '9' &&
1702 	     (!p0[13] || (p0[13] >= '0' && p0[13] <= '9' && !p0[14])) &&
1703 	     (btn = atoi(p0 + 12)) >= 1 && btn <= 32) {
1704     *code = xpdfKeyCodeMouseRelease1 + btn - 1;
1705   } else if (*p0 >= 0x20 && *p0 <= 0x7e && !p0[1]) {
1706     *code = (int)*p0;
1707   } else {
1708     error(errConfig, -1,
1709 	  "Bad key/modifier in '{0:s}' config file command ({1:t}:{2:d})",
1710 	  cmdName, fileName, line);
1711     return gFalse;
1712   }
1713 
1714   p0 = contextStr->getCString();
1715   if (!strcmp(p0, "any")) {
1716     *context = xpdfKeyContextAny;
1717   } else {
1718     *context = xpdfKeyContextAny;
1719     while (1) {
1720       if (!strncmp(p0, "fullScreen", 10)) {
1721 	*context |= xpdfKeyContextFullScreen;
1722 	p0 += 10;
1723       } else if (!strncmp(p0, "window", 6)) {
1724 	*context |= xpdfKeyContextWindow;
1725 	p0 += 6;
1726       } else if (!strncmp(p0, "continuous", 10)) {
1727 	*context |= xpdfKeyContextContinuous;
1728 	p0 += 10;
1729       } else if (!strncmp(p0, "singlePage", 10)) {
1730 	*context |= xpdfKeyContextSinglePage;
1731 	p0 += 10;
1732       } else if (!strncmp(p0, "overLink", 8)) {
1733 	*context |= xpdfKeyContextOverLink;
1734 	p0 += 8;
1735       } else if (!strncmp(p0, "offLink", 7)) {
1736 	*context |= xpdfKeyContextOffLink;
1737 	p0 += 7;
1738       } else if (!strncmp(p0, "outline", 7)) {
1739 	*context |= xpdfKeyContextOutline;
1740 	p0 += 7;
1741       } else if (!strncmp(p0, "mainWin", 7)) {
1742 	*context |= xpdfKeyContextMainWin;
1743 	p0 += 7;
1744       } else if (!strncmp(p0, "scrLockOn", 9)) {
1745 	*context |= xpdfKeyContextScrLockOn;
1746 	p0 += 9;
1747       } else if (!strncmp(p0, "scrLockOff", 10)) {
1748 	*context |= xpdfKeyContextScrLockOff;
1749 	p0 += 10;
1750       } else {
1751 	error(errConfig, -1,
1752 	      "Bad context in '{0:s}' config file command ({1:t}:{2:d})",
1753 	      cmdName, fileName, line);
1754 	return gFalse;
1755       }
1756       if (!*p0) {
1757 	break;
1758       }
1759       if (*p0 != ',') {
1760 	error(errConfig, -1,
1761 	      "Bad context in '{0:s}' config file command ({1:t}:{2:d})",
1762 	      cmdName, fileName, line);
1763 	return gFalse;
1764       }
1765       ++p0;
1766     }
1767   }
1768 
1769   return gTrue;
1770 }
1771 
parseCommand(const char * cmdName,GString ** val,GList * tokens,GString * fileName,int line)1772 void GlobalParams::parseCommand(const char *cmdName, GString **val,
1773 				GList *tokens, GString *fileName, int line) {
1774   if (tokens->getLength() != 2) {
1775     error(errConfig, -1, "Bad '{0:s}' config file command ({1:t}:{2:d})",
1776 	  cmdName, fileName, line);
1777     return;
1778   }
1779   if (*val) {
1780     delete *val;
1781   }
1782   *val = ((GString *)tokens->get(1))->copy();
1783 }
1784 
parseYesNo(const char * cmdName,GBool * flag,GList * tokens,GString * fileName,int line)1785 void GlobalParams::parseYesNo(const char *cmdName, GBool *flag,
1786 			      GList *tokens, GString *fileName, int line) {
1787   GString *tok;
1788 
1789   if (tokens->getLength() != 2) {
1790     error(errConfig, -1, "Bad '{0:s}' config file command ({1:t}:{2:d})",
1791 	  cmdName, fileName, line);
1792     return;
1793   }
1794   tok = (GString *)tokens->get(1);
1795   if (!parseYesNo2(tok->getCString(), flag)) {
1796     error(errConfig, -1, "Bad '{0:s}' config file command ({1:t}:{2:d})",
1797 	  cmdName, fileName, line);
1798   }
1799 }
1800 
parseYesNo2(char * token,GBool * flag)1801 GBool GlobalParams::parseYesNo2(char *token, GBool *flag) {
1802   if (!strcmp(token, "yes")) {
1803     *flag = gTrue;
1804   } else if (!strcmp(token, "no")) {
1805     *flag = gFalse;
1806   } else {
1807     return gFalse;
1808   }
1809   return gTrue;
1810 }
1811 
parseInteger(const char * cmdName,int * val,GList * tokens,GString * fileName,int line)1812 void GlobalParams::parseInteger(const char *cmdName, int *val,
1813 				GList *tokens, GString *fileName, int line) {
1814   GString *tok;
1815   int i;
1816 
1817   if (tokens->getLength() != 2) {
1818     error(errConfig, -1, "Bad '{0:s}' config file command ({1:t}:{2:d})",
1819 	  cmdName, fileName, line);
1820     return;
1821   }
1822   tok = (GString *)tokens->get(1);
1823   if (tok->getLength() == 0) {
1824     error(errConfig, -1, "Bad '{0:s}' config file command ({1:t}:{2:d})",
1825 	  cmdName, fileName, line);
1826     return;
1827   }
1828   if (tok->getChar(0) == '-') {
1829     i = 1;
1830   } else {
1831     i = 0;
1832   }
1833   for (; i < tok->getLength(); ++i) {
1834     if (tok->getChar(i) < '0' || tok->getChar(i) > '9') {
1835       error(errConfig, -1, "Bad '{0:s}' config file command ({1:t}:{2:d})",
1836 	    cmdName, fileName, line);
1837       return;
1838     }
1839   }
1840   *val = atoi(tok->getCString());
1841 }
1842 
parseFloat(const char * cmdName,double * val,GList * tokens,GString * fileName,int line)1843 void GlobalParams::parseFloat(const char *cmdName, double *val,
1844 			      GList *tokens, GString *fileName, int line) {
1845   GString *tok;
1846   int i;
1847 
1848   if (tokens->getLength() != 2) {
1849     error(errConfig, -1, "Bad '{0:s}' config file command ({1:t}:{2:d})",
1850 	  cmdName, fileName, line);
1851     return;
1852   }
1853   tok = (GString *)tokens->get(1);
1854   if (tok->getLength() == 0) {
1855     error(errConfig, -1, "Bad '{0:s}' config file command ({1:t}:{2:d})",
1856 	  cmdName, fileName, line);
1857     return;
1858   }
1859   if (tok->getChar(0) == '-') {
1860     i = 1;
1861   } else {
1862     i = 0;
1863   }
1864   for (; i < tok->getLength(); ++i) {
1865     if (!((tok->getChar(i) >= '0' && tok->getChar(i) <= '9') ||
1866 	  tok->getChar(i) == '.')) {
1867       error(errConfig, -1, "Bad '{0:s}' config file command ({1:t}:{2:d})",
1868 	    cmdName, fileName, line);
1869       return;
1870     }
1871   }
1872   *val = atof(tok->getCString());
1873 }
1874 
~GlobalParams()1875 GlobalParams::~GlobalParams() {
1876   GHashIter *iter;
1877   GString *key;
1878   GList *list;
1879 
1880   freeBuiltinFontTables();
1881 
1882   delete macRomanReverseMap;
1883 
1884   delete baseDir;
1885   delete nameToUnicode;
1886   deleteGHash(cidToUnicodes, GString);
1887   deleteGHash(unicodeToUnicodes, GString);
1888   deleteGHash(residentUnicodeMaps, UnicodeMap);
1889   deleteGHash(unicodeMaps, GString);
1890   deleteGList(toUnicodeDirs, GString);
1891   deleteGHash(fontFiles, GString);
1892   deleteGList(fontDirs, GString);
1893   deleteGHash(ccFontFiles, GString);
1894   deleteGHash(base14SysFonts, Base14FontInfo);
1895   delete sysFonts;
1896   if (psFile) {
1897     delete psFile;
1898   }
1899   deleteGHash(psResidentFonts, GString);
1900   deleteGList(psResidentFonts16, PSFontParam16);
1901   deleteGList(psResidentFontsCC, PSFontParam16);
1902   delete textEncoding;
1903   delete initialZoom;
1904   if (launchCommand) {
1905     delete launchCommand;
1906   }
1907   if (urlCommand) {
1908     delete urlCommand;
1909   }
1910   if (movieCommand) {
1911     delete movieCommand;
1912   }
1913   deleteGList(keyBindings, KeyBinding);
1914 
1915   cMapDirs->startIter(&iter);
1916   while (cMapDirs->getNext(&iter, &key, (void **)&list)) {
1917     deleteGList(list, GString);
1918   }
1919   delete cMapDirs;
1920 
1921   delete cidToUnicodeCache;
1922   delete unicodeToUnicodeCache;
1923   delete unicodeMapCache;
1924   delete cMapCache;
1925 
1926 #ifdef ENABLE_PLUGINS
1927   delete securityHandlers;
1928   deleteGList(plugins, Plugin);
1929 #endif
1930 
1931 #if MULTITHREADED
1932   gDestroyMutex(&mutex);
1933   gDestroyMutex(&unicodeMapCacheMutex);
1934   gDestroyMutex(&cMapCacheMutex);
1935 #endif
1936 }
1937 
1938 //------------------------------------------------------------------------
1939 
setBaseDir(char * dir)1940 void GlobalParams::setBaseDir(char *dir) {
1941   delete baseDir;
1942   baseDir = new GString(dir);
1943 }
1944 
1945 #ifdef _WIN32
getWinFontDir(char * winFontDir)1946 static void getWinFontDir(char *winFontDir) {
1947   HMODULE shell32Lib;
1948   BOOL (__stdcall *SHGetSpecialFolderPathFunc)(HWND hwndOwner,
1949 					       LPSTR lpszPath,
1950 					       int nFolder,
1951 					       BOOL fCreate);
1952   char *p;
1953   int i;
1954 
1955   // SHGetSpecialFolderPath isn't available in older versions of
1956   // shell32.dll (Win95 and WinNT4), so do a dynamic load
1957   winFontDir[0] = '\0';
1958   if ((shell32Lib = LoadLibraryA("shell32.dll"))) {
1959     if ((SHGetSpecialFolderPathFunc =
1960 	 (BOOL (__stdcall *)(HWND hwndOwner, LPSTR lpszPath,
1961 			     int nFolder, BOOL fCreate))
1962 	 GetProcAddress(shell32Lib, "SHGetSpecialFolderPathA"))) {
1963       if (!(*SHGetSpecialFolderPathFunc)(NULL, winFontDir,
1964 					 CSIDL_FONTS, FALSE)) {
1965 	winFontDir[0] = '\0';
1966       }
1967       // kludge: Terminal Server changes CSIDL_FONTS to something like
1968       // "C:\Users\whatever\Windows\Fonts", which doesn't actually
1969       // contain any fonts -- kill that, so we hit the fallback code
1970       // below.
1971       for (p = winFontDir; *p; ++p) {
1972 	if (!strncasecmp(p, "\\Users\\", 7)) {
1973 	  winFontDir[0] = '\0';
1974 	  break;
1975 	}
1976       }
1977     }
1978   }
1979   // if something went wrong, or we're on a Terminal Server, try using
1980   // %SYSTEMROOT%\Fonts
1981   if (!winFontDir[0]) {
1982     GetSystemWindowsDirectoryA(winFontDir, MAX_PATH - 6);
1983     winFontDir[MAX_PATH - 7] = '\0';
1984     i = (int)strlen(winFontDir);
1985     if (winFontDir[i-1] != '\\') {
1986       winFontDir[i++] = '\\';
1987     }
1988     strcpy(winFontDir + i, "Fonts");
1989   }
1990 }
1991 #endif
1992 
setupBaseFonts(char * dir)1993 void GlobalParams::setupBaseFonts(char *dir) {
1994   GString *fontName;
1995   GString *fileName;
1996   int fontNum;
1997   const char *s;
1998   Base14FontInfo *base14;
1999 #ifdef _WIN32
2000   char winFontDir[MAX_PATH];
2001 #endif
2002 #ifdef __APPLE__
2003   static const char *macFontExts[3] = { "dfont", "ttc", "ttf" };
2004   GList *dfontFontNames;
2005   GBool found;
2006   int k;
2007 #endif
2008   FILE *f;
2009   int i, j;
2010 
2011 #ifdef _WIN32
2012   getWinFontDir(winFontDir);
2013 #endif
2014 #ifdef __APPLE__
2015   dfontFontNames = NULL;
2016 #endif
2017   for (i = 0; displayFontTab[i].name; ++i) {
2018     if (fontFiles->lookup(displayFontTab[i].name)) {
2019       continue;
2020     }
2021     fontName = new GString(displayFontTab[i].name);
2022     fileName = NULL;
2023     fontNum = 0;
2024     if (dir) {
2025       fileName = appendToPath(new GString(dir), displayFontTab[i].t1FileName);
2026       if ((f = fopen(fileName->getCString(), "rb"))) {
2027 	fclose(f);
2028       } else {
2029 	delete fileName;
2030 	fileName = NULL;
2031       }
2032     }
2033 #ifdef _WIN32
2034     if (!fileName && winFontDir[0] && displayFontTab[i].ttFileName) {
2035       fileName = appendToPath(new GString(winFontDir),
2036 			      displayFontTab[i].ttFileName);
2037       if ((f = fopen(fileName->getCString(), "rb"))) {
2038 	fclose(f);
2039       } else {
2040 	delete fileName;
2041 	fileName = NULL;
2042       }
2043     }
2044 #endif
2045 #ifdef __APPLE__
2046     // Check for Mac OS X system fonts.
2047     s = displayFontTab[i].macFileName;
2048     if (dfontFontNames && i > 0 &&
2049 	(!s || strcmp(s, displayFontTab[i-1].macFileName))) {
2050       deleteGList(dfontFontNames, GString);
2051       dfontFontNames = NULL;
2052     }
2053     if (!fileName && s) {
2054       for (j = 0; j < 3; ++j) {
2055 	fileName = GString::format("{0:s}/{1:s}.{2:s}",
2056 				   macSystemFontPath, s, macFontExts[j]);
2057 	if (!(f = fopen(fileName->getCString(), "rb"))) {
2058 	  delete fileName;
2059 	  fileName = NULL;
2060 	} else {
2061 	  fclose(f);
2062 	  found = gFalse;
2063 	  // for .dfont or .ttc, we need to scan the font list
2064 	  if (j < 2) {
2065 	    if (!dfontFontNames) {
2066 	      dfontFontNames =
2067 	          FoFiIdentifier::getFontList(fileName->getCString());
2068 	    }
2069 	    if (dfontFontNames) {
2070 	      for (k = 0; k < dfontFontNames->getLength(); ++k) {
2071 		if (!((GString *)dfontFontNames->get(k))
2072 		                     ->cmp(displayFontTab[i].macFontName)) {
2073 		  fontNum = k;
2074 		  found = gTrue;
2075 		  break;
2076 		}
2077 	      }
2078 	    }
2079 	  // for .ttf, we just use the font
2080 	  } else {
2081 	    found = gTrue;
2082 	  }
2083 	  if (!found) {
2084 	    delete fileName;
2085 	    fileName = NULL;
2086 	  }
2087 	  break;
2088 	}
2089       }
2090     }
2091 #endif // __APPLE__
2092     // On Linux, this checks the "standard" ghostscript font
2093     // directories.  On Windows, it checks the "standard" system font
2094     // directories (because SHGetSpecialFolderPath(CSIDL_FONTS)
2095     // doesn't work on Win 2k Server or Win2003 Server, or with older
2096     // versions of shell32.dll).
2097 #ifdef _WIN32
2098     s = displayFontTab[i].ttFileName;
2099 #else
2100     s = displayFontTab[i].t1FileName;
2101 #endif
2102     if (!fileName && s) {
2103       for (j = 0; !fileName && displayFontDirs[j]; ++j) {
2104 	fileName = appendToPath(new GString(displayFontDirs[j]), s);
2105 	if ((f = fopen(fileName->getCString(), "rb"))) {
2106 	  fclose(f);
2107 	} else {
2108 	  delete fileName;
2109 	  fileName = NULL;
2110 	}
2111       }
2112     }
2113     if (!fileName) {
2114       delete fontName;
2115       continue;
2116     }
2117     base14SysFonts->add(fontName, new Base14FontInfo(fileName, fontNum, 0));
2118   }
2119 #ifdef __APPLE__
2120   if (dfontFontNames) {
2121     deleteGList(dfontFontNames, GString);
2122   }
2123 #endif
2124   for (i = 0; displayFontTab[i].name; ++i) {
2125     if (!base14SysFonts->lookup(displayFontTab[i].name) &&
2126 	!fontFiles->lookup(displayFontTab[i].name)) {
2127       if (displayFontTab[i].obliqueFont &&
2128 	  ((base14 = (Base14FontInfo *)base14SysFonts
2129 	                 ->lookup(displayFontTab[i].obliqueFont)))) {
2130 	base14SysFonts->add(
2131 	        new GString(displayFontTab[i].name),
2132 		new Base14FontInfo(base14->fileName->copy(),
2133 				   base14->fontNum,
2134 				   displayFontTab[i].obliqueFactor));
2135       } else {
2136 	error(errConfig, -1, "No display font for '{0:s}'",
2137 	      displayFontTab[i].name);
2138       }
2139     }
2140   }
2141 #ifdef _WIN32
2142   if (winFontDir[0]) {
2143     sysFonts->scanWindowsFonts(winFontDir);
2144   }
2145 #endif
2146 }
2147 
2148 //------------------------------------------------------------------------
2149 // accessors
2150 //------------------------------------------------------------------------
2151 
getMacRomanCharCode(char * charName)2152 CharCode GlobalParams::getMacRomanCharCode(char *charName) {
2153   // no need to lock - macRomanReverseMap is constant
2154   return macRomanReverseMap->lookup(charName);
2155 }
2156 
getBaseDir()2157 GString *GlobalParams::getBaseDir() {
2158   GString *s;
2159 
2160   lockGlobalParams;
2161   s = baseDir->copy();
2162   unlockGlobalParams;
2163   return s;
2164 }
2165 
mapNameToUnicode(const char * charName)2166 Unicode GlobalParams::mapNameToUnicode(const char *charName) {
2167   // no need to lock - nameToUnicode is constant
2168   return nameToUnicode->lookup(charName);
2169 }
2170 
getResidentUnicodeMap(GString * encodingName)2171 UnicodeMap *GlobalParams::getResidentUnicodeMap(GString *encodingName) {
2172   UnicodeMap *map;
2173 
2174   lockGlobalParams;
2175   map = (UnicodeMap *)residentUnicodeMaps->lookup(encodingName);
2176   unlockGlobalParams;
2177   if (map) {
2178     map->incRefCnt();
2179   }
2180   return map;
2181 }
2182 
getUnicodeMapFile(GString * encodingName)2183 FILE *GlobalParams::getUnicodeMapFile(GString *encodingName) {
2184   GString *fileName;
2185   FILE *f;
2186 
2187   lockGlobalParams;
2188   if ((fileName = (GString *)unicodeMaps->lookup(encodingName))) {
2189     f = openFile(fileName->getCString(), "r");
2190   } else {
2191     f = NULL;
2192   }
2193   unlockGlobalParams;
2194   return f;
2195 }
2196 
findCMapFile(GString * collection,GString * cMapName)2197 FILE *GlobalParams::findCMapFile(GString *collection, GString *cMapName) {
2198   GList *list;
2199   GString *dir;
2200   GString *fileName;
2201   FILE *f;
2202   int i;
2203 
2204   lockGlobalParams;
2205   if (!(list = (GList *)cMapDirs->lookup(collection))) {
2206     unlockGlobalParams;
2207     return NULL;
2208   }
2209   for (i = 0; i < list->getLength(); ++i) {
2210     dir = (GString *)list->get(i);
2211     fileName = appendToPath(dir->copy(), cMapName->getCString());
2212     f = openFile(fileName->getCString(), "r");
2213     delete fileName;
2214     if (f) {
2215       unlockGlobalParams;
2216       return f;
2217     }
2218   }
2219   unlockGlobalParams;
2220   return NULL;
2221 }
2222 
findToUnicodeFile(GString * name)2223 FILE *GlobalParams::findToUnicodeFile(GString *name) {
2224   GString *dir, *fileName;
2225   FILE *f;
2226   int i;
2227 
2228   lockGlobalParams;
2229   for (i = 0; i < toUnicodeDirs->getLength(); ++i) {
2230     dir = (GString *)toUnicodeDirs->get(i);
2231     fileName = appendToPath(dir->copy(), name->getCString());
2232     f = openFile(fileName->getCString(), "r");
2233     delete fileName;
2234     if (f) {
2235       unlockGlobalParams;
2236       return f;
2237     }
2238   }
2239   unlockGlobalParams;
2240   return NULL;
2241 }
2242 
findFontFile(GString * fontName)2243 GString *GlobalParams::findFontFile(GString *fontName) {
2244   static const char *exts[] = { ".pfa", ".pfb", ".ttf", ".ttc" };
2245   GString *path, *dir;
2246 #ifdef _WIN32
2247   GString *fontNameU;
2248 #endif
2249   const char *ext;
2250   FILE *f;
2251   int i, j;
2252 
2253   lockGlobalParams;
2254   if ((path = (GString *)fontFiles->lookup(fontName))) {
2255     path = path->copy();
2256     unlockGlobalParams;
2257     return path;
2258   }
2259   for (i = 0; i < fontDirs->getLength(); ++i) {
2260     dir = (GString *)fontDirs->get(i);
2261     for (j = 0; j < (int)(sizeof(exts) / sizeof(exts[0])); ++j) {
2262       ext = exts[j];
2263 #ifdef _WIN32
2264       fontNameU = fileNameToUTF8(fontName->getCString());
2265       path = appendToPath(dir->copy(), fontNameU->getCString());
2266       delete fontNameU;
2267 #else
2268       path = appendToPath(dir->copy(), fontName->getCString());
2269 #endif
2270       path->append(ext);
2271       if ((f = openFile(path->getCString(), "rb"))) {
2272 	fclose(f);
2273 	unlockGlobalParams;
2274 	return path;
2275       }
2276       delete path;
2277     }
2278   }
2279   unlockGlobalParams;
2280   return NULL;
2281 }
2282 
findBase14FontFile(GString * fontName,int * fontNum,double * oblique)2283 GString *GlobalParams::findBase14FontFile(GString *fontName, int *fontNum,
2284 					  double *oblique) {
2285   Base14FontInfo *fi;
2286   GString *path;
2287 
2288   lockGlobalParams;
2289   if ((fi = (Base14FontInfo *)base14SysFonts->lookup(fontName))) {
2290     path = fi->fileName->copy();
2291     *fontNum = fi->fontNum;
2292     *oblique = fi->oblique;
2293     unlockGlobalParams;
2294     return path;
2295   }
2296   unlockGlobalParams;
2297   *fontNum = 0;
2298   *oblique = 0;
2299   return findFontFile(fontName);
2300 }
2301 
findSystemFontFile(GString * fontName,SysFontType * type,int * fontNum)2302 GString *GlobalParams::findSystemFontFile(GString *fontName,
2303 					  SysFontType *type,
2304 					  int *fontNum) {
2305   SysFontInfo *fi;
2306   GString *path;
2307 
2308   path = NULL;
2309   lockGlobalParams;
2310   if ((fi = sysFonts->find(fontName))) {
2311     path = fi->path->copy();
2312     *type = fi->type;
2313     *fontNum = fi->fontNum;
2314   }
2315   unlockGlobalParams;
2316   return path;
2317 }
2318 
findCCFontFile(GString * collection)2319 GString *GlobalParams::findCCFontFile(GString *collection) {
2320   GString *path;
2321 
2322   lockGlobalParams;
2323   if ((path = (GString *)ccFontFiles->lookup(collection))) {
2324     path = path->copy();
2325   }
2326   unlockGlobalParams;
2327   return path;
2328 }
2329 
getPSFile()2330 GString *GlobalParams::getPSFile() {
2331   GString *s;
2332 
2333   lockGlobalParams;
2334   s = psFile ? psFile->copy() : (GString *)NULL;
2335   unlockGlobalParams;
2336   return s;
2337 }
2338 
getPSPaperWidth()2339 int GlobalParams::getPSPaperWidth() {
2340   int w;
2341 
2342   lockGlobalParams;
2343   w = psPaperWidth;
2344   unlockGlobalParams;
2345   return w;
2346 }
2347 
getPSPaperHeight()2348 int GlobalParams::getPSPaperHeight() {
2349   int h;
2350 
2351   lockGlobalParams;
2352   h = psPaperHeight;
2353   unlockGlobalParams;
2354   return h;
2355 }
2356 
getPSImageableArea(int * llx,int * lly,int * urx,int * ury)2357 void GlobalParams::getPSImageableArea(int *llx, int *lly, int *urx, int *ury) {
2358   lockGlobalParams;
2359   *llx = psImageableLLX;
2360   *lly = psImageableLLY;
2361   *urx = psImageableURX;
2362   *ury = psImageableURY;
2363   unlockGlobalParams;
2364 }
2365 
getPSCrop()2366 GBool GlobalParams::getPSCrop() {
2367   GBool f;
2368 
2369   lockGlobalParams;
2370   f = psCrop;
2371   unlockGlobalParams;
2372   return f;
2373 }
2374 
getPSUseCropBoxAsPage()2375 GBool GlobalParams::getPSUseCropBoxAsPage() {
2376   GBool f;
2377 
2378   lockGlobalParams;
2379   f = psUseCropBoxAsPage;
2380   unlockGlobalParams;
2381   return f;
2382 }
2383 
getPSExpandSmaller()2384 GBool GlobalParams::getPSExpandSmaller() {
2385   GBool f;
2386 
2387   lockGlobalParams;
2388   f = psExpandSmaller;
2389   unlockGlobalParams;
2390   return f;
2391 }
2392 
getPSShrinkLarger()2393 GBool GlobalParams::getPSShrinkLarger() {
2394   GBool f;
2395 
2396   lockGlobalParams;
2397   f = psShrinkLarger;
2398   unlockGlobalParams;
2399   return f;
2400 }
2401 
getPSCenter()2402 GBool GlobalParams::getPSCenter() {
2403   GBool f;
2404 
2405   lockGlobalParams;
2406   f = psCenter;
2407   unlockGlobalParams;
2408   return f;
2409 }
2410 
getPSDuplex()2411 GBool GlobalParams::getPSDuplex() {
2412   GBool d;
2413 
2414   lockGlobalParams;
2415   d = psDuplex;
2416   unlockGlobalParams;
2417   return d;
2418 }
2419 
getPSLevel()2420 PSLevel GlobalParams::getPSLevel() {
2421   PSLevel level;
2422 
2423   lockGlobalParams;
2424   level = psLevel;
2425   unlockGlobalParams;
2426   return level;
2427 }
2428 
getPSResidentFont(GString * fontName)2429 GString *GlobalParams::getPSResidentFont(GString *fontName) {
2430   GString *psName;
2431 
2432   lockGlobalParams;
2433   if ((psName = (GString *)psResidentFonts->lookup(fontName))) {
2434     psName = psName->copy();
2435   }
2436   unlockGlobalParams;
2437   return psName;
2438 }
2439 
getPSResidentFonts()2440 GList *GlobalParams::getPSResidentFonts() {
2441   GList *names;
2442   GHashIter *iter;
2443   GString *name;
2444   GString *psName;
2445 
2446   names = new GList();
2447   lockGlobalParams;
2448   psResidentFonts->startIter(&iter);
2449   while (psResidentFonts->getNext(&iter, &name, (void **)&psName)) {
2450     names->append(psName->copy());
2451   }
2452   unlockGlobalParams;
2453   return names;
2454 }
2455 
getPSResidentFont16(GString * fontName,int wMode)2456 PSFontParam16 *GlobalParams::getPSResidentFont16(GString *fontName,
2457 						 int wMode) {
2458   PSFontParam16 *p;
2459   int i;
2460 
2461   lockGlobalParams;
2462   p = NULL;
2463   for (i = 0; i < psResidentFonts16->getLength(); ++i) {
2464     p = (PSFontParam16 *)psResidentFonts16->get(i);
2465     if (!(p->name->cmp(fontName)) && p->wMode == wMode) {
2466       break;
2467     }
2468     p = NULL;
2469   }
2470   unlockGlobalParams;
2471   return p;
2472 }
2473 
getPSResidentFontCC(GString * collection,int wMode)2474 PSFontParam16 *GlobalParams::getPSResidentFontCC(GString *collection,
2475 						 int wMode) {
2476   PSFontParam16 *p;
2477   int i;
2478 
2479   lockGlobalParams;
2480   p = NULL;
2481   for (i = 0; i < psResidentFontsCC->getLength(); ++i) {
2482     p = (PSFontParam16 *)psResidentFontsCC->get(i);
2483     if (!(p->name->cmp(collection)) && p->wMode == wMode) {
2484       break;
2485     }
2486     p = NULL;
2487   }
2488   unlockGlobalParams;
2489   return p;
2490 }
2491 
getPSEmbedType1()2492 GBool GlobalParams::getPSEmbedType1() {
2493   GBool e;
2494 
2495   lockGlobalParams;
2496   e = psEmbedType1;
2497   unlockGlobalParams;
2498   return e;
2499 }
2500 
getPSEmbedTrueType()2501 GBool GlobalParams::getPSEmbedTrueType() {
2502   GBool e;
2503 
2504   lockGlobalParams;
2505   e = psEmbedTrueType;
2506   unlockGlobalParams;
2507   return e;
2508 }
2509 
getPSEmbedCIDPostScript()2510 GBool GlobalParams::getPSEmbedCIDPostScript() {
2511   GBool e;
2512 
2513   lockGlobalParams;
2514   e = psEmbedCIDPostScript;
2515   unlockGlobalParams;
2516   return e;
2517 }
2518 
getPSEmbedCIDTrueType()2519 GBool GlobalParams::getPSEmbedCIDTrueType() {
2520   GBool e;
2521 
2522   lockGlobalParams;
2523   e = psEmbedCIDTrueType;
2524   unlockGlobalParams;
2525   return e;
2526 }
2527 
getPSFontPassthrough()2528 GBool GlobalParams::getPSFontPassthrough() {
2529   GBool e;
2530 
2531   lockGlobalParams;
2532   e = psFontPassthrough;
2533   unlockGlobalParams;
2534   return e;
2535 }
2536 
getPSPreload()2537 GBool GlobalParams::getPSPreload() {
2538   GBool preload;
2539 
2540   lockGlobalParams;
2541   preload = psPreload;
2542   unlockGlobalParams;
2543   return preload;
2544 }
2545 
getPSOPI()2546 GBool GlobalParams::getPSOPI() {
2547   GBool opi;
2548 
2549   lockGlobalParams;
2550   opi = psOPI;
2551   unlockGlobalParams;
2552   return opi;
2553 }
2554 
getPSASCIIHex()2555 GBool GlobalParams::getPSASCIIHex() {
2556   GBool ah;
2557 
2558   lockGlobalParams;
2559   ah = psASCIIHex;
2560   unlockGlobalParams;
2561   return ah;
2562 }
2563 
getPSLZW()2564 GBool GlobalParams::getPSLZW() {
2565   GBool ah;
2566 
2567   lockGlobalParams;
2568   ah = psLZW;
2569   unlockGlobalParams;
2570   return ah;
2571 }
2572 
getPSUncompressPreloadedImages()2573 GBool GlobalParams::getPSUncompressPreloadedImages() {
2574   GBool ah;
2575 
2576   lockGlobalParams;
2577   ah = psUncompressPreloadedImages;
2578   unlockGlobalParams;
2579   return ah;
2580 }
2581 
getPSMinLineWidth()2582 double GlobalParams::getPSMinLineWidth() {
2583   double w;
2584 
2585   lockGlobalParams;
2586   w = psMinLineWidth;
2587   unlockGlobalParams;
2588   return w;
2589 }
2590 
getPSRasterResolution()2591 double GlobalParams::getPSRasterResolution() {
2592   double res;
2593 
2594   lockGlobalParams;
2595   res = psRasterResolution;
2596   unlockGlobalParams;
2597   return res;
2598 }
2599 
getPSRasterMono()2600 GBool GlobalParams::getPSRasterMono() {
2601   GBool mono;
2602 
2603   lockGlobalParams;
2604   mono = psRasterMono;
2605   unlockGlobalParams;
2606   return mono;
2607 }
2608 
getPSRasterSliceSize()2609 int GlobalParams::getPSRasterSliceSize() {
2610   int slice;
2611 
2612   lockGlobalParams;
2613   slice = psRasterSliceSize;
2614   unlockGlobalParams;
2615   return slice;
2616 }
2617 
getPSAlwaysRasterize()2618 GBool GlobalParams::getPSAlwaysRasterize() {
2619   GBool rast;
2620 
2621   lockGlobalParams;
2622   rast = psAlwaysRasterize;
2623   unlockGlobalParams;
2624   return rast;
2625 }
2626 
getTextEncodingName()2627 GString *GlobalParams::getTextEncodingName() {
2628   GString *s;
2629 
2630   lockGlobalParams;
2631   s = textEncoding->copy();
2632   unlockGlobalParams;
2633   return s;
2634 }
2635 
getTextEOL()2636 EndOfLineKind GlobalParams::getTextEOL() {
2637   EndOfLineKind eol;
2638 
2639   lockGlobalParams;
2640   eol = textEOL;
2641   unlockGlobalParams;
2642   return eol;
2643 }
2644 
getTextPageBreaks()2645 GBool GlobalParams::getTextPageBreaks() {
2646   GBool pageBreaks;
2647 
2648   lockGlobalParams;
2649   pageBreaks = textPageBreaks;
2650   unlockGlobalParams;
2651   return pageBreaks;
2652 }
2653 
getTextKeepTinyChars()2654 GBool GlobalParams::getTextKeepTinyChars() {
2655   GBool tiny;
2656 
2657   lockGlobalParams;
2658   tiny = textKeepTinyChars;
2659   unlockGlobalParams;
2660   return tiny;
2661 }
2662 
getInitialZoom()2663 GString *GlobalParams::getInitialZoom() {
2664   GString *s;
2665 
2666   lockGlobalParams;
2667   s = initialZoom->copy();
2668   unlockGlobalParams;
2669   return s;
2670 }
2671 
getContinuousView()2672 GBool GlobalParams::getContinuousView() {
2673   GBool f;
2674 
2675   lockGlobalParams;
2676   f = continuousView;
2677   unlockGlobalParams;
2678   return f;
2679 }
2680 
getEnableFreeType()2681 GBool GlobalParams::getEnableFreeType() {
2682   GBool f;
2683 
2684   lockGlobalParams;
2685   f = enableFreeType;
2686   unlockGlobalParams;
2687   return f;
2688 }
2689 
getDisableFreeTypeHinting()2690 GBool GlobalParams::getDisableFreeTypeHinting() {
2691   GBool f;
2692 
2693   lockGlobalParams;
2694   f = disableFreeTypeHinting;
2695   unlockGlobalParams;
2696   return f;
2697 }
2698 
2699 
getAntialias()2700 GBool GlobalParams::getAntialias() {
2701   GBool f;
2702 
2703   lockGlobalParams;
2704   f = antialias;
2705   unlockGlobalParams;
2706   return f;
2707 }
2708 
getVectorAntialias()2709 GBool GlobalParams::getVectorAntialias() {
2710   GBool f;
2711 
2712   lockGlobalParams;
2713   f = vectorAntialias;
2714   unlockGlobalParams;
2715   return f;
2716 }
2717 
getAntialiasPrinting()2718 GBool GlobalParams::getAntialiasPrinting() {
2719   GBool f;
2720 
2721   lockGlobalParams;
2722   f = antialiasPrinting;
2723   unlockGlobalParams;
2724   return f;
2725 }
2726 
getStrokeAdjust()2727 GBool GlobalParams::getStrokeAdjust() {
2728   GBool f;
2729 
2730   lockGlobalParams;
2731   f = strokeAdjust;
2732   unlockGlobalParams;
2733   return f;
2734 }
2735 
getScreenType()2736 ScreenType GlobalParams::getScreenType() {
2737   ScreenType t;
2738 
2739   lockGlobalParams;
2740   t = screenType;
2741   unlockGlobalParams;
2742   return t;
2743 }
2744 
getScreenSize()2745 int GlobalParams::getScreenSize() {
2746   int size;
2747 
2748   lockGlobalParams;
2749   size = screenSize;
2750   unlockGlobalParams;
2751   return size;
2752 }
2753 
getScreenDotRadius()2754 int GlobalParams::getScreenDotRadius() {
2755   int r;
2756 
2757   lockGlobalParams;
2758   r = screenDotRadius;
2759   unlockGlobalParams;
2760   return r;
2761 }
2762 
getScreenGamma()2763 double GlobalParams::getScreenGamma() {
2764   double gamma;
2765 
2766   lockGlobalParams;
2767   gamma = screenGamma;
2768   unlockGlobalParams;
2769   return gamma;
2770 }
2771 
getScreenBlackThreshold()2772 double GlobalParams::getScreenBlackThreshold() {
2773   double thresh;
2774 
2775   lockGlobalParams;
2776   thresh = screenBlackThreshold;
2777   unlockGlobalParams;
2778   return thresh;
2779 }
2780 
getScreenWhiteThreshold()2781 double GlobalParams::getScreenWhiteThreshold() {
2782   double thresh;
2783 
2784   lockGlobalParams;
2785   thresh = screenWhiteThreshold;
2786   unlockGlobalParams;
2787   return thresh;
2788 }
2789 
getMinLineWidth()2790 double GlobalParams::getMinLineWidth() {
2791   double w;
2792 
2793   lockGlobalParams;
2794   w = minLineWidth;
2795   unlockGlobalParams;
2796   return w;
2797 }
2798 
getDrawAnnotations()2799 GBool GlobalParams::getDrawAnnotations() {
2800   GBool draw;
2801 
2802   lockGlobalParams;
2803   draw = drawAnnotations;
2804   unlockGlobalParams;
2805   return draw;
2806 }
2807 
2808 
getMapNumericCharNames()2809 GBool GlobalParams::getMapNumericCharNames() {
2810   GBool map;
2811 
2812   lockGlobalParams;
2813   map = mapNumericCharNames;
2814   unlockGlobalParams;
2815   return map;
2816 }
2817 
getMapUnknownCharNames()2818 GBool GlobalParams::getMapUnknownCharNames() {
2819   GBool map;
2820 
2821   lockGlobalParams;
2822   map = mapUnknownCharNames;
2823   unlockGlobalParams;
2824   return map;
2825 }
2826 
getMapExtTrueTypeFontsViaUnicode()2827 GBool GlobalParams::getMapExtTrueTypeFontsViaUnicode() {
2828   GBool map;
2829 
2830   lockGlobalParams;
2831   map = mapExtTrueTypeFontsViaUnicode;
2832   unlockGlobalParams;
2833   return map;
2834 }
2835 
getEnableXFA()2836 GBool GlobalParams::getEnableXFA() {
2837   GBool enable;
2838 
2839   lockGlobalParams;
2840   enable = enableXFA;
2841   unlockGlobalParams;
2842   return enable;
2843 }
2844 
getKeyBinding(int code,int mods,int context)2845 GList *GlobalParams::getKeyBinding(int code, int mods, int context) {
2846   KeyBinding *binding;
2847   GList *cmds;
2848   int modMask;
2849   int i, j;
2850 
2851   lockGlobalParams;
2852   cmds = NULL;
2853   // for ASCII chars, ignore the shift modifier
2854   modMask = code <= 0xff ? ~xpdfKeyModShift : ~0;
2855   for (i = 0; i < keyBindings->getLength(); ++i) {
2856     binding = (KeyBinding *)keyBindings->get(i);
2857     if (binding->code == code &&
2858 	(binding->mods & modMask) == (mods & modMask) &&
2859 	(~binding->context | context) == ~0) {
2860       cmds = new GList();
2861       for (j = 0; j < binding->cmds->getLength(); ++j) {
2862 	cmds->append(((GString *)binding->cmds->get(j))->copy());
2863       }
2864       break;
2865     }
2866   }
2867   unlockGlobalParams;
2868   return cmds;
2869 }
2870 
getPrintCommands()2871 GBool GlobalParams::getPrintCommands() {
2872   GBool p;
2873 
2874   lockGlobalParams;
2875   p = printCommands;
2876   unlockGlobalParams;
2877   return p;
2878 }
2879 
getErrQuiet()2880 GBool GlobalParams::getErrQuiet() {
2881   // no locking -- this function may get called from inside a locked
2882   // section
2883   return errQuiet;
2884 }
2885 
getCIDToUnicode(GString * collection)2886 CharCodeToUnicode *GlobalParams::getCIDToUnicode(GString *collection) {
2887   GString *fileName;
2888   CharCodeToUnicode *ctu;
2889 
2890   lockGlobalParams;
2891   if (!(ctu = cidToUnicodeCache->getCharCodeToUnicode(collection))) {
2892     if ((fileName = (GString *)cidToUnicodes->lookup(collection)) &&
2893 	(ctu = CharCodeToUnicode::parseCIDToUnicode(fileName, collection))) {
2894       cidToUnicodeCache->add(ctu);
2895     }
2896   }
2897   unlockGlobalParams;
2898   return ctu;
2899 }
2900 
getUnicodeToUnicode(GString * fontName)2901 CharCodeToUnicode *GlobalParams::getUnicodeToUnicode(GString *fontName) {
2902   CharCodeToUnicode *ctu;
2903   GHashIter *iter;
2904   GString *fontPattern, *fileName;
2905 
2906   lockGlobalParams;
2907   fileName = NULL;
2908   unicodeToUnicodes->startIter(&iter);
2909   while (unicodeToUnicodes->getNext(&iter, &fontPattern, (void **)&fileName)) {
2910     if (strstr(fontName->getCString(), fontPattern->getCString())) {
2911       unicodeToUnicodes->killIter(&iter);
2912       break;
2913     }
2914     fileName = NULL;
2915   }
2916   if (fileName) {
2917     if (!(ctu = unicodeToUnicodeCache->getCharCodeToUnicode(fileName))) {
2918       if ((ctu = CharCodeToUnicode::parseUnicodeToUnicode(fileName))) {
2919 	unicodeToUnicodeCache->add(ctu);
2920       }
2921     }
2922   } else {
2923     ctu = NULL;
2924   }
2925   unlockGlobalParams;
2926   return ctu;
2927 }
2928 
getUnicodeMap(GString * encodingName)2929 UnicodeMap *GlobalParams::getUnicodeMap(GString *encodingName) {
2930   return getUnicodeMap2(encodingName);
2931 }
2932 
getUnicodeMap2(GString * encodingName)2933 UnicodeMap *GlobalParams::getUnicodeMap2(GString *encodingName) {
2934   UnicodeMap *map;
2935 
2936   if (!(map = getResidentUnicodeMap(encodingName))) {
2937     lockUnicodeMapCache;
2938     map = unicodeMapCache->getUnicodeMap(encodingName);
2939     unlockUnicodeMapCache;
2940   }
2941   return map;
2942 }
2943 
getCMap(GString * collection,GString * cMapName)2944 CMap *GlobalParams::getCMap(GString *collection, GString *cMapName) {
2945   CMap *cMap;
2946 
2947   lockCMapCache;
2948   cMap = cMapCache->getCMap(collection, cMapName);
2949   unlockCMapCache;
2950   return cMap;
2951 }
2952 
getTextEncoding()2953 UnicodeMap *GlobalParams::getTextEncoding() {
2954   return getUnicodeMap2(textEncoding);
2955 }
2956 
2957 //------------------------------------------------------------------------
2958 // functions to set parameters
2959 //------------------------------------------------------------------------
2960 
addFontFile(GString * fontName,GString * path)2961 void GlobalParams::addFontFile(GString *fontName, GString *path) {
2962   lockGlobalParams;
2963   fontFiles->add(fontName, path);
2964   unlockGlobalParams;
2965 }
2966 
setPSFile(char * file)2967 void GlobalParams::setPSFile(char *file) {
2968   lockGlobalParams;
2969   if (psFile) {
2970     delete psFile;
2971   }
2972   psFile = new GString(file);
2973   unlockGlobalParams;
2974 }
2975 
setPSPaperSize(char * size)2976 GBool GlobalParams::setPSPaperSize(char *size) {
2977   lockGlobalParams;
2978   if (!strcmp(size, "match")) {
2979     psPaperWidth = psPaperHeight = -1;
2980   } else if (!strcmp(size, "letter")) {
2981     psPaperWidth = 612;
2982     psPaperHeight = 792;
2983   } else if (!strcmp(size, "legal")) {
2984     psPaperWidth = 612;
2985     psPaperHeight = 1008;
2986   } else if (!strcmp(size, "A4")) {
2987     psPaperWidth = 595;
2988     psPaperHeight = 842;
2989   } else if (!strcmp(size, "A3")) {
2990     psPaperWidth = 842;
2991     psPaperHeight = 1190;
2992   } else {
2993     unlockGlobalParams;
2994     return gFalse;
2995   }
2996   psImageableLLX = psImageableLLY = 0;
2997   psImageableURX = psPaperWidth;
2998   psImageableURY = psPaperHeight;
2999   unlockGlobalParams;
3000   return gTrue;
3001 }
3002 
setPSPaperWidth(int width)3003 void GlobalParams::setPSPaperWidth(int width) {
3004   lockGlobalParams;
3005   psPaperWidth = width;
3006   psImageableLLX = 0;
3007   psImageableURX = psPaperWidth;
3008   unlockGlobalParams;
3009 }
3010 
setPSPaperHeight(int height)3011 void GlobalParams::setPSPaperHeight(int height) {
3012   lockGlobalParams;
3013   psPaperHeight = height;
3014   psImageableLLY = 0;
3015   psImageableURY = psPaperHeight;
3016   unlockGlobalParams;
3017 }
3018 
setPSImageableArea(int llx,int lly,int urx,int ury)3019 void GlobalParams::setPSImageableArea(int llx, int lly, int urx, int ury) {
3020   lockGlobalParams;
3021   psImageableLLX = llx;
3022   psImageableLLY = lly;
3023   psImageableURX = urx;
3024   psImageableURY = ury;
3025   unlockGlobalParams;
3026 }
3027 
setPSCrop(GBool crop)3028 void GlobalParams::setPSCrop(GBool crop) {
3029   lockGlobalParams;
3030   psCrop = crop;
3031   unlockGlobalParams;
3032 }
3033 
setPSUseCropBoxAsPage(GBool crop)3034 void GlobalParams::setPSUseCropBoxAsPage(GBool crop) {
3035   lockGlobalParams;
3036   psUseCropBoxAsPage = crop;
3037   unlockGlobalParams;
3038 }
3039 
setPSExpandSmaller(GBool expand)3040 void GlobalParams::setPSExpandSmaller(GBool expand) {
3041   lockGlobalParams;
3042   psExpandSmaller = expand;
3043   unlockGlobalParams;
3044 }
3045 
setPSShrinkLarger(GBool shrink)3046 void GlobalParams::setPSShrinkLarger(GBool shrink) {
3047   lockGlobalParams;
3048   psShrinkLarger = shrink;
3049   unlockGlobalParams;
3050 }
3051 
setPSCenter(GBool center)3052 void GlobalParams::setPSCenter(GBool center) {
3053   lockGlobalParams;
3054   psCenter = center;
3055   unlockGlobalParams;
3056 }
3057 
setPSDuplex(GBool duplex)3058 void GlobalParams::setPSDuplex(GBool duplex) {
3059   lockGlobalParams;
3060   psDuplex = duplex;
3061   unlockGlobalParams;
3062 }
3063 
setPSLevel(PSLevel level)3064 void GlobalParams::setPSLevel(PSLevel level) {
3065   lockGlobalParams;
3066   psLevel = level;
3067   unlockGlobalParams;
3068 }
3069 
setPSEmbedType1(GBool embed)3070 void GlobalParams::setPSEmbedType1(GBool embed) {
3071   lockGlobalParams;
3072   psEmbedType1 = embed;
3073   unlockGlobalParams;
3074 }
3075 
setPSEmbedTrueType(GBool embed)3076 void GlobalParams::setPSEmbedTrueType(GBool embed) {
3077   lockGlobalParams;
3078   psEmbedTrueType = embed;
3079   unlockGlobalParams;
3080 }
3081 
setPSEmbedCIDPostScript(GBool embed)3082 void GlobalParams::setPSEmbedCIDPostScript(GBool embed) {
3083   lockGlobalParams;
3084   psEmbedCIDPostScript = embed;
3085   unlockGlobalParams;
3086 }
3087 
setPSEmbedCIDTrueType(GBool embed)3088 void GlobalParams::setPSEmbedCIDTrueType(GBool embed) {
3089   lockGlobalParams;
3090   psEmbedCIDTrueType = embed;
3091   unlockGlobalParams;
3092 }
3093 
setPSFontPassthrough(GBool passthrough)3094 void GlobalParams::setPSFontPassthrough(GBool passthrough) {
3095   lockGlobalParams;
3096   psFontPassthrough = passthrough;
3097   unlockGlobalParams;
3098 }
3099 
setPSPreload(GBool preload)3100 void GlobalParams::setPSPreload(GBool preload) {
3101   lockGlobalParams;
3102   psPreload = preload;
3103   unlockGlobalParams;
3104 }
3105 
setPSOPI(GBool opi)3106 void GlobalParams::setPSOPI(GBool opi) {
3107   lockGlobalParams;
3108   psOPI = opi;
3109   unlockGlobalParams;
3110 }
3111 
setPSASCIIHex(GBool hex)3112 void GlobalParams::setPSASCIIHex(GBool hex) {
3113   lockGlobalParams;
3114   psASCIIHex = hex;
3115   unlockGlobalParams;
3116 }
3117 
setTextEncoding(const char * encodingName)3118 void GlobalParams::setTextEncoding(const char *encodingName) {
3119   lockGlobalParams;
3120   delete textEncoding;
3121   textEncoding = new GString(encodingName);
3122   unlockGlobalParams;
3123 }
3124 
setTextEOL(char * s)3125 GBool GlobalParams::setTextEOL(char *s) {
3126   lockGlobalParams;
3127   if (!strcmp(s, "unix")) {
3128     textEOL = eolUnix;
3129   } else if (!strcmp(s, "dos")) {
3130     textEOL = eolDOS;
3131   } else if (!strcmp(s, "mac")) {
3132     textEOL = eolMac;
3133   } else {
3134     unlockGlobalParams;
3135     return gFalse;
3136   }
3137   unlockGlobalParams;
3138   return gTrue;
3139 }
3140 
setTextPageBreaks(GBool pageBreaks)3141 void GlobalParams::setTextPageBreaks(GBool pageBreaks) {
3142   lockGlobalParams;
3143   textPageBreaks = pageBreaks;
3144   unlockGlobalParams;
3145 }
3146 
setTextKeepTinyChars(GBool keep)3147 void GlobalParams::setTextKeepTinyChars(GBool keep) {
3148   lockGlobalParams;
3149   textKeepTinyChars = keep;
3150   unlockGlobalParams;
3151 }
3152 
setInitialZoom(char * s)3153 void GlobalParams::setInitialZoom(char *s) {
3154   lockGlobalParams;
3155   delete initialZoom;
3156   initialZoom = new GString(s);
3157   unlockGlobalParams;
3158 }
3159 
setContinuousView(GBool cont)3160 void GlobalParams::setContinuousView(GBool cont) {
3161   lockGlobalParams;
3162   continuousView = cont;
3163   unlockGlobalParams;
3164 }
3165 
setEnableFreeType(char * s)3166 GBool GlobalParams::setEnableFreeType(char *s) {
3167   GBool ok;
3168 
3169   lockGlobalParams;
3170   ok = parseYesNo2(s, &enableFreeType);
3171   unlockGlobalParams;
3172   return ok;
3173 }
3174 
3175 
setAntialias(char * s)3176 GBool GlobalParams::setAntialias(char *s) {
3177   GBool ok;
3178 
3179   lockGlobalParams;
3180   ok = parseYesNo2(s, &antialias);
3181   unlockGlobalParams;
3182   return ok;
3183 }
3184 
setVectorAntialias(char * s)3185 GBool GlobalParams::setVectorAntialias(char *s) {
3186   GBool ok;
3187 
3188   lockGlobalParams;
3189   ok = parseYesNo2(s, &vectorAntialias);
3190   unlockGlobalParams;
3191   return ok;
3192 }
3193 
setScreenType(ScreenType t)3194 void GlobalParams::setScreenType(ScreenType t) {
3195   lockGlobalParams;
3196   screenType = t;
3197   unlockGlobalParams;
3198 }
3199 
setScreenSize(int size)3200 void GlobalParams::setScreenSize(int size) {
3201   lockGlobalParams;
3202   screenSize = size;
3203   unlockGlobalParams;
3204 }
3205 
setScreenDotRadius(int r)3206 void GlobalParams::setScreenDotRadius(int r) {
3207   lockGlobalParams;
3208   screenDotRadius = r;
3209   unlockGlobalParams;
3210 }
3211 
setScreenGamma(double gamma)3212 void GlobalParams::setScreenGamma(double gamma) {
3213   lockGlobalParams;
3214   screenGamma = gamma;
3215   unlockGlobalParams;
3216 }
3217 
setScreenBlackThreshold(double thresh)3218 void GlobalParams::setScreenBlackThreshold(double thresh) {
3219   lockGlobalParams;
3220   screenBlackThreshold = thresh;
3221   unlockGlobalParams;
3222 }
3223 
setScreenWhiteThreshold(double thresh)3224 void GlobalParams::setScreenWhiteThreshold(double thresh) {
3225   lockGlobalParams;
3226   screenWhiteThreshold = thresh;
3227   unlockGlobalParams;
3228 }
3229 
setMapNumericCharNames(GBool map)3230 void GlobalParams::setMapNumericCharNames(GBool map) {
3231   lockGlobalParams;
3232   mapNumericCharNames = map;
3233   unlockGlobalParams;
3234 }
3235 
setMapUnknownCharNames(GBool map)3236 void GlobalParams::setMapUnknownCharNames(GBool map) {
3237   lockGlobalParams;
3238   mapUnknownCharNames = map;
3239   unlockGlobalParams;
3240 }
3241 
setMapExtTrueTypeFontsViaUnicode(GBool map)3242 void GlobalParams::setMapExtTrueTypeFontsViaUnicode(GBool map) {
3243   lockGlobalParams;
3244   mapExtTrueTypeFontsViaUnicode = map;
3245   unlockGlobalParams;
3246 }
3247 
setEnableXFA(GBool enable)3248 void GlobalParams::setEnableXFA(GBool enable) {
3249   lockGlobalParams;
3250   enableXFA = enable;
3251   unlockGlobalParams;
3252 }
3253 
setPrintCommands(GBool printCommandsA)3254 void GlobalParams::setPrintCommands(GBool printCommandsA) {
3255   lockGlobalParams;
3256   printCommands = printCommandsA;
3257   unlockGlobalParams;
3258 }
3259 
setErrQuiet(GBool errQuietA)3260 void GlobalParams::setErrQuiet(GBool errQuietA) {
3261   lockGlobalParams;
3262   errQuiet = errQuietA;
3263   unlockGlobalParams;
3264 }
3265 
addSecurityHandler(XpdfSecurityHandler * handler)3266 void GlobalParams::addSecurityHandler(XpdfSecurityHandler *handler) {
3267 #ifdef ENABLE_PLUGINS
3268   lockGlobalParams;
3269   securityHandlers->append(handler);
3270   unlockGlobalParams;
3271 #endif
3272 }
3273 
getSecurityHandler(char * name)3274 XpdfSecurityHandler *GlobalParams::getSecurityHandler(char *name) {
3275 #ifdef ENABLE_PLUGINS
3276   XpdfSecurityHandler *hdlr;
3277   int i;
3278 
3279   lockGlobalParams;
3280   for (i = 0; i < securityHandlers->getLength(); ++i) {
3281     hdlr = (XpdfSecurityHandler *)securityHandlers->get(i);
3282     if (!strcasecmp(hdlr->name, name)) {
3283       unlockGlobalParams;
3284       return hdlr;
3285     }
3286   }
3287   unlockGlobalParams;
3288 
3289   if (!loadPlugin("security", name)) {
3290     return NULL;
3291   }
3292 
3293   lockGlobalParams;
3294   for (i = 0; i < securityHandlers->getLength(); ++i) {
3295     hdlr = (XpdfSecurityHandler *)securityHandlers->get(i);
3296     if (!strcmp(hdlr->name, name)) {
3297       unlockGlobalParams;
3298       return hdlr;
3299     }
3300   }
3301   unlockGlobalParams;
3302 #endif
3303 
3304   return NULL;
3305 }
3306 
3307 #ifdef ENABLE_PLUGINS
3308 //------------------------------------------------------------------------
3309 // plugins
3310 //------------------------------------------------------------------------
3311 
loadPlugin(char * type,char * name)3312 GBool GlobalParams::loadPlugin(char *type, char *name) {
3313   Plugin *plugin;
3314 
3315   if (!(plugin = Plugin::load(type, name))) {
3316     return gFalse;
3317   }
3318   lockGlobalParams;
3319   plugins->append(plugin);
3320   unlockGlobalParams;
3321   return gTrue;
3322 }
3323 
3324 #endif // ENABLE_PLUGINS
3325