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