Various Datatypes.
[AROS-Contrib.git] / arospdf / xpdf / GlobalParams.cc
bloba7f693bacd341a8d276db71461d8f195e003ca69
1 //========================================================================
2 //
3 // GlobalParams.cc
4 //
5 // Copyright 2001-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
9 #include <aconf.h>
10 #include <aros/debug.h>
11 #ifdef USE_GCC_PRAGMAS
12 #pragma implementation
13 #endif
15 #include <string.h>
16 #include <stdio.h>
17 #include <ctype.h>
18 #ifdef ENABLE_PLUGINS
19 # ifndef WIN32
20 # include <dlfcn.h>
21 # endif
22 #endif
23 #ifdef WIN32
24 # include <shlobj.h>
25 #endif
26 #if HAVE_PAPER_H
27 #include <paper.h>
28 #endif
29 #include "gmem.h"
30 #include "GString.h"
31 #include "GList.h"
32 #include "GHash.h"
33 #include "gfile.h"
34 #include "Error.h"
35 #include "NameToCharCode.h"
36 #include "CharCodeToUnicode.h"
37 #include "UnicodeMap.h"
38 #include "CMap.h"
39 #include "BuiltinFontTables.h"
40 #include "FontEncodingTables.h"
41 #ifdef ENABLE_PLUGINS
42 # include "XpdfPluginAPI.h"
43 #endif
44 #include "GlobalParams.h"
46 #ifdef WIN32
47 # define strcasecmp stricmp
48 #endif
50 #if MULTITHREADED
51 # define lockGlobalParams gLockMutex(&mutex)
52 # define lockUnicodeMapCache gLockMutex(&unicodeMapCacheMutex)
53 # define lockCMapCache gLockMutex(&cMapCacheMutex)
54 # define unlockGlobalParams gUnlockMutex(&mutex)
55 # define unlockUnicodeMapCache gUnlockMutex(&unicodeMapCacheMutex)
56 # define unlockCMapCache gUnlockMutex(&cMapCacheMutex)
57 #else
58 # define lockGlobalParams
59 # define lockUnicodeMapCache
60 # define lockCMapCache
61 # define unlockGlobalParams
62 # define unlockUnicodeMapCache
63 # define unlockCMapCache
64 #endif
66 #include "NameToUnicodeTable.h"
67 #include "UnicodeMapTables.h"
68 #include "UTF8.h"
70 #ifdef ENABLE_PLUGINS
71 # ifdef WIN32
72 extern XpdfPluginVecTable xpdfPluginVecTable;
73 # endif
74 #endif
76 //------------------------------------------------------------------------
78 #define cidToUnicodeCacheSize 4
79 #define unicodeToUnicodeCacheSize 4
81 //------------------------------------------------------------------------
83 static struct {
84 const char *name;
85 const char *t1FileName;
86 const char *ttFileName;
87 } displayFontTab[] = {
88 {"Courier", "n022003l.pfb", "cour.ttf"},
89 {"Courier-Bold", "n022004l.pfb", "courbd.ttf"},
90 {"Courier-BoldOblique", "n022024l.pfb", "courbi.ttf"},
91 {"Courier-Oblique", "n022023l.pfb", "couri.ttf"},
92 {"Helvetica", "n019003l.pfb", "arial.ttf"},
93 {"Helvetica-Bold", "n019004l.pfb", "arialbd.ttf"},
94 {"Helvetica-BoldOblique", "n019024l.pfb", "arialbi.ttf"},
95 {"Helvetica-Oblique", "n019023l.pfb", "ariali.ttf"},
96 {"Symbol", "s050000l.pfb", NULL},
97 {"Times-Bold", "n021004l.pfb", "timesbd.ttf"},
98 {"Times-BoldItalic", "n021024l.pfb", "timesbi.ttf"},
99 {"Times-Italic", "n021023l.pfb", "timesi.ttf"},
100 {"Times-Roman", "n021003l.pfb", "times.ttf"},
101 {"ZapfDingbats", "d050000l.pfb", NULL},
102 {NULL}
105 #ifdef WIN32
106 static char *displayFontDirs[] = {
107 "c:/windows/fonts",
108 "c:/winnt/fonts",
109 NULL
111 #else
112 static char *displayFontDirs[] = {
113 #ifdef __AROS__
114 "progdir:fonts",
115 "fonts:",
116 #else
117 "/usr/local/share/ghostscript/fonts",
118 "/usr/share/fonts/default/Type1",
119 "/usr/share/fonts/default/ghostscript",
120 "/usr/share/fonts/type1/gsfonts",
121 #endif
122 NULL
124 #endif
126 //------------------------------------------------------------------------
128 GlobalParams *globalParams = NULL;
130 //------------------------------------------------------------------------
131 // DisplayFontParam
132 //------------------------------------------------------------------------
134 DisplayFontParam::DisplayFontParam(GString *nameA,
135 DisplayFontParamKind kindA) {
136 name = nameA;
137 kind = kindA;
138 switch (kind) {
139 case displayFontT1:
140 t1.fileName = NULL;
141 break;
142 case displayFontTT:
143 tt.fileName = NULL;
144 break;
148 DisplayFontParam::~DisplayFontParam() {
149 delete name;
150 switch (kind) {
151 case displayFontT1:
152 if (t1.fileName) {
153 delete t1.fileName;
155 break;
156 case displayFontTT:
157 if (tt.fileName) {
158 delete tt.fileName;
160 break;
164 #ifdef WIN32
166 //------------------------------------------------------------------------
167 // WinFontInfo
168 //------------------------------------------------------------------------
170 class WinFontInfo: public DisplayFontParam {
171 public:
173 GBool bold, italic;
175 static WinFontInfo *make(GString *nameA, GBool boldA, GBool italicA,
176 HKEY regKey, char *winFontDir);
177 WinFontInfo(GString *nameA, GBool boldA, GBool italicA,
178 GString *fileNameA);
179 virtual ~WinFontInfo();
180 GBool equals(WinFontInfo *fi);
183 WinFontInfo *WinFontInfo::make(GString *nameA, GBool boldA, GBool italicA,
184 HKEY regKey, char *winFontDir) {
185 GString *regName;
186 GString *fileNameA;
187 char buf[MAX_PATH];
188 DWORD n;
189 char c;
190 int i;
192 //----- find the font file
193 fileNameA = NULL;
194 regName = nameA->copy();
195 if (boldA) {
196 regName->append(" Bold");
198 if (italicA) {
199 regName->append(" Italic");
201 regName->append(" (TrueType)");
202 n = sizeof(buf);
203 if (RegQueryValueEx(regKey, regName->getCString(), NULL, NULL,
204 (LPBYTE)buf, &n) == ERROR_SUCCESS) {
205 fileNameA = new GString(winFontDir);
206 fileNameA->append('\\')->append(buf);
208 delete regName;
209 if (!fileNameA) {
210 delete nameA;
211 return NULL;
214 //----- normalize the font name
215 i = 0;
216 while (i < nameA->getLength()) {
217 c = nameA->getChar(i);
218 if (c == ' ' || c == ',' || c == '-') {
219 nameA->del(i);
220 } else {
221 ++i;
225 return new WinFontInfo(nameA, boldA, italicA, fileNameA);
228 WinFontInfo::WinFontInfo(GString *nameA, GBool boldA, GBool italicA,
229 GString *fileNameA):
230 DisplayFontParam(nameA, displayFontTT)
232 bold = boldA;
233 italic = italicA;
234 tt.fileName = fileNameA;
237 WinFontInfo::~WinFontInfo() {
240 GBool WinFontInfo::equals(WinFontInfo *fi) {
241 return !name->cmp(fi->name) && bold == fi->bold && italic == fi->italic;
244 //------------------------------------------------------------------------
245 // WinFontList
246 //------------------------------------------------------------------------
248 class WinFontList {
249 public:
251 WinFontList(char *winFontDirA);
252 ~WinFontList();
253 WinFontInfo *find(GString *font);
255 private:
257 void add(WinFontInfo *fi);
258 static int CALLBACK enumFunc1(CONST LOGFONT *font,
259 CONST TEXTMETRIC *metrics,
260 DWORD type, LPARAM data);
261 static int CALLBACK enumFunc2(CONST LOGFONT *font,
262 CONST TEXTMETRIC *metrics,
263 DWORD type, LPARAM data);
265 GList *fonts; // [WinFontInfo]
266 HDC dc; // (only used during enumeration)
267 HKEY regKey; // (only used during enumeration)
268 char *winFontDir; // (only used during enumeration)
271 WinFontList::WinFontList(char *winFontDirA) {
272 OSVERSIONINFO version;
273 char *path;
275 fonts = new GList();
276 dc = GetDC(NULL);
277 winFontDir = winFontDirA;
278 version.dwOSVersionInfoSize = sizeof(version);
279 GetVersionEx(&version);
280 if (version.dwPlatformId == VER_PLATFORM_WIN32_NT) {
281 path = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\\";
282 } else {
283 path = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Fonts\\";
285 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, path, 0,
286 KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS,
287 &regKey) == ERROR_SUCCESS) {
288 EnumFonts(dc, NULL, &WinFontList::enumFunc1, (LPARAM)this);
289 RegCloseKey(regKey);
291 ReleaseDC(NULL, dc);
294 WinFontList::~WinFontList() {
295 deleteGList(fonts, WinFontInfo);
298 void WinFontList::add(WinFontInfo *fi) {
299 int i;
301 for (i = 0; i < fonts->getLength(); ++i) {
302 if (((WinFontInfo *)fonts->get(i))->equals(fi)) {
303 delete fi;
304 return;
307 fonts->append(fi);
310 WinFontInfo *WinFontList::find(GString *font) {
311 GString *name;
312 GBool bold, italic;
313 WinFontInfo *fi;
314 char c;
315 int n, i;
317 name = font->copy();
319 // remove space, comma, dash chars
320 i = 0;
321 while (i < name->getLength()) {
322 c = name->getChar(i);
323 if (c == ' ' || c == ',' || c == '-') {
324 name->del(i);
325 } else {
326 ++i;
329 n = name->getLength();
331 // remove trailing "MT" (Foo-MT, Foo-BoldMT, etc.)
332 if (!strcmp(name->getCString() + n - 2, "MT")) {
333 name->del(n - 2, 2);
334 n -= 2;
337 // look for "Italic"
338 if (!strcmp(name->getCString() + n - 6, "Italic")) {
339 name->del(n - 6, 6);
340 italic = gTrue;
341 n -= 6;
342 } else {
343 italic = gFalse;
346 // look for "Bold"
347 if (!strcmp(name->getCString() + n - 4, "Bold")) {
348 name->del(n - 4, 4);
349 bold = gTrue;
350 n -= 4;
351 } else {
352 bold = gFalse;
355 // remove trailing "MT" (FooMT-Bold, etc.)
356 if (!strcmp(name->getCString() + n - 2, "MT")) {
357 name->del(n - 2, 2);
358 n -= 2;
361 // remove trailing "PS"
362 if (!strcmp(name->getCString() + n - 2, "PS")) {
363 name->del(n - 2, 2);
364 n -= 2;
367 // search for the font
368 fi = NULL;
369 for (i = 0; i < fonts->getLength(); ++i) {
370 fi = (WinFontInfo *)fonts->get(i);
371 if (!fi->name->cmp(name) && fi->bold == bold && fi->italic == italic) {
372 break;
374 fi = NULL;
377 delete name;
378 return fi;
381 int CALLBACK WinFontList::enumFunc1(CONST LOGFONT *font,
382 CONST TEXTMETRIC *metrics,
383 DWORD type, LPARAM data) {
384 WinFontList *fl = (WinFontList *)data;
386 EnumFonts(fl->dc, font->lfFaceName, &WinFontList::enumFunc2, (LPARAM)fl);
387 return 1;
390 int CALLBACK WinFontList::enumFunc2(CONST LOGFONT *font,
391 CONST TEXTMETRIC *metrics,
392 DWORD type, LPARAM data) {
393 WinFontList *fl = (WinFontList *)data;
394 WinFontInfo *fi;
396 if (type & TRUETYPE_FONTTYPE) {
397 if ((fi = WinFontInfo::make(new GString(font->lfFaceName),
398 font->lfWeight >= 600,
399 font->lfItalic ? gTrue : gFalse,
400 fl->regKey, fl->winFontDir))) {
401 fl->add(fi);
404 return 1;
407 #endif // WIN32
409 //------------------------------------------------------------------------
410 // PSFontParam
411 //------------------------------------------------------------------------
413 PSFontParam::PSFontParam(GString *pdfFontNameA, int wModeA,
414 GString *psFontNameA, GString *encodingA) {
415 pdfFontName = pdfFontNameA;
416 wMode = wModeA;
417 psFontName = psFontNameA;
418 encoding = encodingA;
421 PSFontParam::~PSFontParam() {
422 delete pdfFontName;
423 delete psFontName;
424 if (encoding) {
425 delete encoding;
429 //------------------------------------------------------------------------
430 // KeyBinding
431 //------------------------------------------------------------------------
433 KeyBinding::KeyBinding(int codeA, int modsA, int contextA, const char *cmd0) {
434 code = codeA;
435 mods = modsA;
436 context = contextA;
437 cmds = new GList();
438 cmds->append(new GString(cmd0));
441 KeyBinding::KeyBinding(int codeA, int modsA, int contextA,
442 const char *cmd0, const char *cmd1) {
443 code = codeA;
444 mods = modsA;
445 context = contextA;
446 cmds = new GList();
447 cmds->append(new GString(cmd0));
448 cmds->append(new GString(cmd1));
451 KeyBinding::KeyBinding(int codeA, int modsA, int contextA, GList *cmdsA) {
452 code = codeA;
453 mods = modsA;
454 context = contextA;
455 cmds = cmdsA;
458 KeyBinding::~KeyBinding() {
459 deleteGList(cmds, GString);
462 #ifdef ENABLE_PLUGINS
463 //------------------------------------------------------------------------
464 // Plugin
465 //------------------------------------------------------------------------
467 class Plugin {
468 public:
470 static Plugin *load(char *type, char *name);
471 ~Plugin();
473 private:
475 #ifdef WIN32
476 Plugin(HMODULE libA);
477 HMODULE lib;
478 #else
479 Plugin(void *dlA);
480 void *dl;
481 #endif
484 Plugin *Plugin::load(char *type, char *name) {
485 GString *path;
486 Plugin *plugin;
487 XpdfPluginVecTable *vt;
488 XpdfBool (*xpdfInitPlugin)(void);
489 #ifdef WIN32
490 HMODULE libA;
491 #else
492 void *dlA;
493 #endif
495 path = globalParams->getBaseDir();
496 appendToPath(path, "plugins");
497 appendToPath(path, type);
498 appendToPath(path, name);
500 #ifdef WIN32
501 path->append(".dll");
502 if (!(libA = LoadLibrary(path->getCString()))) {
503 error(-1, (char*)"Failed to load plugin '%s'",
504 path->getCString());
505 goto err1;
507 if (!(vt = (XpdfPluginVecTable *)
508 GetProcAddress(libA, "xpdfPluginVecTable"))) {
509 error(-1, (char*)"Failed to find xpdfPluginVecTable in plugin '%s'",
510 path->getCString());
511 goto err2;
513 #else
514 //~ need to deal with other extensions here
515 path->append(".so");
516 if (!(dlA = dlopen(path->getCString(), RTLD_NOW))) {
517 error(-1, (char*)"Failed to load plugin '%s': %s",
518 path->getCString(), dlerror());
519 goto err1;
521 if (!(vt = (XpdfPluginVecTable *)dlsym(dlA, "xpdfPluginVecTable"))) {
522 error(-1, (char*)"Failed to find xpdfPluginVecTable in plugin '%s'",
523 path->getCString());
524 goto err2;
526 #endif
528 if (vt->version != xpdfPluginVecTable.version) {
529 error(-1, (char*)"Plugin '%s' is wrong version", path->getCString());
530 goto err2;
532 memcpy(vt, &xpdfPluginVecTable, sizeof(xpdfPluginVecTable));
534 #ifdef WIN32
535 if (!(xpdfInitPlugin = (XpdfBool (*)(void))
536 GetProcAddress(libA, "xpdfInitPlugin"))) {
537 error(-1, (char*)"Failed to find xpdfInitPlugin in plugin '%s'",
538 path->getCString());
539 goto err2;
541 #else
542 if (!(xpdfInitPlugin = (XpdfBool (*)(void))dlsym(dlA, "xpdfInitPlugin"))) {
543 error(-1, (char*)"Failed to find xpdfInitPlugin in plugin '%s'",
544 path->getCString());
545 goto err2;
547 #endif
549 if (!(*xpdfInitPlugin)()) {
550 error(-1, (char*)"Initialization of plugin '%s' failed",
551 path->getCString());
552 goto err2;
555 #ifdef WIN32
556 plugin = new Plugin(libA);
557 #else
558 plugin = new Plugin(dlA);
559 #endif
561 delete path;
562 return plugin;
564 err2:
565 #ifdef WIN32
566 FreeLibrary(libA);
567 #else
568 dlclose(dlA);
569 #endif
570 err1:
571 delete path;
572 return NULL;
575 #ifdef WIN32
576 Plugin::Plugin(HMODULE libA) {
577 lib = libA;
579 #else
580 Plugin::Plugin(void *dlA) {
581 dl = dlA;
583 #endif
585 Plugin::~Plugin() {
586 void (*xpdfFreePlugin)(void);
588 #ifdef WIN32
589 if ((xpdfFreePlugin = (void (*)(void))
590 GetProcAddress(lib, "xpdfFreePlugin"))) {
591 (*xpdfFreePlugin)();
593 FreeLibrary(lib);
594 #else
595 if ((xpdfFreePlugin = (void (*)(void))dlsym(dl, "xpdfFreePlugin"))) {
596 (*xpdfFreePlugin)();
598 dlclose(dl);
599 #endif
602 #endif // ENABLE_PLUGINS
604 //------------------------------------------------------------------------
605 // parsing
606 //------------------------------------------------------------------------
608 GlobalParams::GlobalParams(char *cfgFileName) {
609 UnicodeMap *map;
610 GString *fileName;
611 FILE *f;
612 int i;
614 #if MULTITHREADED
615 gInitMutex(&mutex);
616 gInitMutex(&unicodeMapCacheMutex);
617 gInitMutex(&cMapCacheMutex);
618 #endif
620 initBuiltinFontTables();
622 // scan the encoding in reverse because we want the lowest-numbered
623 // index for each char name ('space' is encoded twice)
624 macRomanReverseMap = new NameToCharCode();
625 for (i = 255; i >= 0; --i) {
626 if (macRomanEncoding[i]) {
627 macRomanReverseMap->add((char *)macRomanEncoding[i], (CharCode)i);
631 #ifdef WIN32
632 // baseDir will be set by a call to setBaseDir
633 baseDir = new GString();
634 #else
635 baseDir = appendToPath(getHomeDir(), ".xpdf");
636 #endif
637 nameToUnicode = new NameToCharCode();
638 cidToUnicodes = new GHash(gTrue);
639 unicodeToUnicodes = new GHash(gTrue);
640 residentUnicodeMaps = new GHash();
641 unicodeMaps = new GHash(gTrue);
642 cMapDirs = new GHash(gTrue);
643 toUnicodeDirs = new GList();
644 displayFonts = new GHash();
645 displayCIDFonts = new GHash();
646 displayNamedCIDFonts = new GHash();
647 #if HAVE_PAPER_H
648 char *paperName;
649 const struct paper *paperType;
650 paperinit();
651 if ((paperName = systempapername())) {
652 paperType = paperinfo(paperName);
653 psPaperWidth = (int)paperpswidth(paperType);
654 psPaperHeight = (int)paperpsheight(paperType);
655 } else {
656 error(-1, (char*)"No paper information available - using defaults");
657 psPaperWidth = defPaperWidth;
658 psPaperHeight = defPaperHeight;
660 paperdone();
661 #else
662 psPaperWidth = defPaperWidth;
663 psPaperHeight = defPaperHeight;
664 #endif
665 psImageableLLX = psImageableLLY = 0;
666 psImageableURX = psPaperWidth;
667 psImageableURY = psPaperHeight;
668 psCrop = gTrue;
669 psExpandSmaller = gFalse;
670 psShrinkLarger = gTrue;
671 psCenter = gTrue;
672 psDuplex = gFalse;
673 psLevel = psLevel2;
674 psFile = NULL;
675 psFonts = new GHash();
676 psNamedFonts16 = new GList();
677 psFonts16 = new GList();
678 psEmbedType1 = gTrue;
679 psEmbedTrueType = gTrue;
680 psEmbedCIDPostScript = gTrue;
681 psEmbedCIDTrueType = gTrue;
682 psPreload = gFalse;
683 psOPI = gFalse;
684 psASCIIHex = gFalse;
685 textEncoding = new GString("Latin1");
686 #if defined(WIN32)
687 textEOL = eolDOS;
688 #elif defined(MACOS)
689 textEOL = eolMac;
690 #else
691 textEOL = eolUnix;
692 #endif
693 textPageBreaks = gTrue;
694 textKeepTinyChars = gFalse;
695 fontDirs = new GList();
696 initialZoom = new GString("125");
697 continuousView = gFalse;
698 enableT1lib = gTrue;
699 enableFreeType = gTrue;
700 antialias = gTrue;
701 vectorAntialias = gTrue;
702 strokeAdjust = gTrue;
703 screenType = screenUnset;
704 screenSize = -1;
705 screenDotRadius = -1;
706 screenGamma = 1.0;
707 screenBlackThreshold = 0.0;
708 screenWhiteThreshold = 1.0;
709 urlCommand = NULL;
710 movieCommand = NULL;
711 mapNumericCharNames = gTrue;
712 mapUnknownCharNames = gFalse;
713 createDefaultKeyBindings();
714 printCommands = gFalse;
715 errQuiet = gFalse;
717 cidToUnicodeCache = new CharCodeToUnicodeCache(cidToUnicodeCacheSize);
718 unicodeToUnicodeCache =
719 new CharCodeToUnicodeCache(unicodeToUnicodeCacheSize);
720 unicodeMapCache = new UnicodeMapCache();
721 cMapCache = new CMapCache();
723 #ifdef WIN32
724 winFontList = NULL;
725 #endif
727 #ifdef ENABLE_PLUGINS
728 plugins = new GList();
729 securityHandlers = new GList();
730 #endif
732 // set up the initial nameToUnicode table
733 for (i = 0; nameToUnicodeTab[i].name; ++i) {
734 nameToUnicode->add((char *)nameToUnicodeTab[i].name, nameToUnicodeTab[i].u);
737 // set up the residentUnicodeMaps table
738 map = new UnicodeMap("Latin1", gFalse,
739 latin1UnicodeMapRanges, latin1UnicodeMapLen);
740 residentUnicodeMaps->add(map->getEncodingName(), map);
741 map = new UnicodeMap("ASCII7", gFalse,
742 ascii7UnicodeMapRanges, ascii7UnicodeMapLen);
743 residentUnicodeMaps->add(map->getEncodingName(), map);
744 map = new UnicodeMap("Symbol", gFalse,
745 symbolUnicodeMapRanges, symbolUnicodeMapLen);
746 residentUnicodeMaps->add(map->getEncodingName(), map);
747 map = new UnicodeMap("ZapfDingbats", gFalse, zapfDingbatsUnicodeMapRanges,
748 zapfDingbatsUnicodeMapLen);
749 residentUnicodeMaps->add(map->getEncodingName(), map);
750 map = new UnicodeMap("UTF-8", gTrue, &mapUTF8);
751 residentUnicodeMaps->add(map->getEncodingName(), map);
752 map = new UnicodeMap("UCS-2", gTrue, &mapUCS2);
753 residentUnicodeMaps->add(map->getEncodingName(), map);
755 #if defined(__AROS__)
756 return;
757 #endif
759 // look for a user config file, then a system-wide config file
760 f = NULL;
761 fileName = NULL;
763 if (cfgFileName && cfgFileName[0]) {
764 fileName = new GString(cfgFileName);
765 if (!(f = fopen(fileName->getCString(), "r"))) {
766 delete fileName;
769 if (!f) {
770 fileName = appendToPath(getHomeDir(), xpdfUserConfigFile);
771 if (!(f = fopen(fileName->getCString(), "r"))) {
772 delete fileName;
775 if (!f) {
776 #if defined(WIN32) && !defined(__CYGWIN32__)
777 char buf[512];
778 i = GetModuleFileName(NULL, buf, sizeof(buf));
779 if (i <= 0 || i >= sizeof(buf)) {
780 // error or path too long for buffer - just use the current dir
781 buf[0] = '\0';
783 fileName = grabPath(buf);
784 appendToPath(fileName, xpdfSysConfigFile);
785 #else
786 fileName = new GString(xpdfSysConfigFile);
787 #endif
788 if (!(f = fopen(fileName->getCString(), "r"))) {
789 delete fileName;
792 if (f) {
793 parseFile(fileName, f);
794 delete fileName;
795 fclose(f);
799 void GlobalParams::createDefaultKeyBindings() {
800 keyBindings = new GList();
802 //----- mouse buttons
803 keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress1, xpdfKeyModNone,
804 xpdfKeyContextAny, "startSelection"));
805 keyBindings->append(new KeyBinding(xpdfKeyCodeMouseRelease1, xpdfKeyModNone,
806 xpdfKeyContextAny, "endSelection",
807 "followLinkNoSel"));
808 keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress2, xpdfKeyModNone,
809 xpdfKeyContextAny, "startPan"));
810 keyBindings->append(new KeyBinding(xpdfKeyCodeMouseRelease2, xpdfKeyModNone,
811 xpdfKeyContextAny, "endPan"));
812 keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress3, xpdfKeyModNone,
813 xpdfKeyContextAny, "postPopupMenu"));
814 keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress4, xpdfKeyModNone,
815 xpdfKeyContextAny,
816 "scrollUpPrevPage(16)"));
817 keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress5, xpdfKeyModNone,
818 xpdfKeyContextAny,
819 "scrollDownNextPage(16)"));
820 keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress6, xpdfKeyModNone,
821 xpdfKeyContextAny, "scrollLeft(16)"));
822 keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress7, xpdfKeyModNone,
823 xpdfKeyContextAny, "scrollRight(16)"));
825 //----- keys
826 keyBindings->append(new KeyBinding(xpdfKeyCodeHome, xpdfKeyModCtrl,
827 xpdfKeyContextAny, "gotoPage(1)"));
828 keyBindings->append(new KeyBinding(xpdfKeyCodeHome, xpdfKeyModNone,
829 xpdfKeyContextAny, "scrollToTopLeft"));
830 keyBindings->append(new KeyBinding(xpdfKeyCodeEnd, xpdfKeyModCtrl,
831 xpdfKeyContextAny, "gotoLastPage"));
832 keyBindings->append(new KeyBinding(xpdfKeyCodeEnd, xpdfKeyModNone,
833 xpdfKeyContextAny,
834 "scrollToBottomRight"));
835 keyBindings->append(new KeyBinding(xpdfKeyCodePgUp, xpdfKeyModNone,
836 xpdfKeyContextAny, "pageUp"));
837 keyBindings->append(new KeyBinding(xpdfKeyCodeBackspace, xpdfKeyModNone,
838 xpdfKeyContextAny, "pageUp"));
839 keyBindings->append(new KeyBinding(xpdfKeyCodeDelete, xpdfKeyModNone,
840 xpdfKeyContextAny, "pageUp"));
841 keyBindings->append(new KeyBinding(xpdfKeyCodePgDn, xpdfKeyModNone,
842 xpdfKeyContextAny, "pageDown"));
843 keyBindings->append(new KeyBinding(' ', xpdfKeyModNone,
844 xpdfKeyContextAny, "pageDown"));
845 keyBindings->append(new KeyBinding(xpdfKeyCodeLeft, xpdfKeyModNone,
846 xpdfKeyContextAny, "scrollLeft(16)"));
847 keyBindings->append(new KeyBinding(xpdfKeyCodeRight, xpdfKeyModNone,
848 xpdfKeyContextAny, "scrollRight(16)"));
849 keyBindings->append(new KeyBinding(xpdfKeyCodeUp, xpdfKeyModNone,
850 xpdfKeyContextAny, "scrollUp(16)"));
851 keyBindings->append(new KeyBinding(xpdfKeyCodeDown, xpdfKeyModNone,
852 xpdfKeyContextAny, "scrollDown(16)"));
853 keyBindings->append(new KeyBinding('o', xpdfKeyModNone,
854 xpdfKeyContextAny, "open"));
855 keyBindings->append(new KeyBinding('O', xpdfKeyModNone,
856 xpdfKeyContextAny, "open"));
857 keyBindings->append(new KeyBinding('r', xpdfKeyModNone,
858 xpdfKeyContextAny, "reload"));
859 keyBindings->append(new KeyBinding('R', xpdfKeyModNone,
860 xpdfKeyContextAny, "reload"));
861 keyBindings->append(new KeyBinding('f', xpdfKeyModNone,
862 xpdfKeyContextAny, "find"));
863 keyBindings->append(new KeyBinding('F', xpdfKeyModNone,
864 xpdfKeyContextAny, "find"));
865 keyBindings->append(new KeyBinding('f', xpdfKeyModCtrl,
866 xpdfKeyContextAny, "find"));
867 keyBindings->append(new KeyBinding('g', xpdfKeyModCtrl,
868 xpdfKeyContextAny, "findNext"));
869 keyBindings->append(new KeyBinding('p', xpdfKeyModCtrl,
870 xpdfKeyContextAny, "print"));
871 keyBindings->append(new KeyBinding('n', xpdfKeyModNone,
872 xpdfKeyContextScrLockOff, "nextPage"));
873 keyBindings->append(new KeyBinding('N', xpdfKeyModNone,
874 xpdfKeyContextScrLockOff, "nextPage"));
875 keyBindings->append(new KeyBinding('n', xpdfKeyModNone,
876 xpdfKeyContextScrLockOn,
877 "nextPageNoScroll"));
878 keyBindings->append(new KeyBinding('N', xpdfKeyModNone,
879 xpdfKeyContextScrLockOn,
880 "nextPageNoScroll"));
881 keyBindings->append(new KeyBinding('p', xpdfKeyModNone,
882 xpdfKeyContextScrLockOff, "prevPage"));
883 keyBindings->append(new KeyBinding('P', xpdfKeyModNone,
884 xpdfKeyContextScrLockOff, "prevPage"));
885 keyBindings->append(new KeyBinding('p', xpdfKeyModNone,
886 xpdfKeyContextScrLockOn,
887 "prevPageNoScroll"));
888 keyBindings->append(new KeyBinding('P', xpdfKeyModNone,
889 xpdfKeyContextScrLockOn,
890 "prevPageNoScroll"));
891 keyBindings->append(new KeyBinding('v', xpdfKeyModNone,
892 xpdfKeyContextAny, "goForward"));
893 keyBindings->append(new KeyBinding('b', xpdfKeyModNone,
894 xpdfKeyContextAny, "goBackward"));
895 keyBindings->append(new KeyBinding('g', xpdfKeyModNone,
896 xpdfKeyContextAny, "focusToPageNum"));
897 keyBindings->append(new KeyBinding('0', xpdfKeyModNone,
898 xpdfKeyContextAny, "zoomPercent(125)"));
899 keyBindings->append(new KeyBinding('+', xpdfKeyModNone,
900 xpdfKeyContextAny, "zoomIn"));
901 keyBindings->append(new KeyBinding('-', xpdfKeyModNone,
902 xpdfKeyContextAny, "zoomOut"));
903 keyBindings->append(new KeyBinding('z', xpdfKeyModNone,
904 xpdfKeyContextAny, "zoomFitPage"));
905 keyBindings->append(new KeyBinding('w', xpdfKeyModNone,
906 xpdfKeyContextAny, "zoomFitWidth"));
907 keyBindings->append(new KeyBinding('f', xpdfKeyModAlt,
908 xpdfKeyContextAny,
909 "toggleFullScreenMode"));
910 keyBindings->append(new KeyBinding('l', xpdfKeyModCtrl,
911 xpdfKeyContextAny, "redraw"));
912 keyBindings->append(new KeyBinding('w', xpdfKeyModCtrl,
913 xpdfKeyContextAny, "closeWindow"));
914 keyBindings->append(new KeyBinding('?', xpdfKeyModNone,
915 xpdfKeyContextAny, "about"));
916 keyBindings->append(new KeyBinding('q', xpdfKeyModNone,
917 xpdfKeyContextAny, "quit"));
918 keyBindings->append(new KeyBinding('Q', xpdfKeyModNone,
919 xpdfKeyContextAny, "quit"));
922 void GlobalParams::parseFile(GString *fileName, FILE *f) {
923 int line;
924 char buf[512];
926 line = 1;
927 while (getLine(buf, sizeof(buf) - 1, f)) {
928 parseLine(buf, fileName, line);
929 ++line;
933 void GlobalParams::parseLine(char *buf, GString *fileName, int line) {
934 GList *tokens;
935 GString *cmd, *incFile;
936 char *p1, *p2;
937 FILE *f2;
939 // break the line into tokens
940 tokens = new GList();
941 p1 = buf;
942 while (*p1) {
943 for (; *p1 && isspace(*p1); ++p1) ;
944 if (!*p1) {
945 break;
947 if (*p1 == '"' || *p1 == '\'') {
948 for (p2 = p1 + 1; *p2 && *p2 != *p1; ++p2) ;
949 ++p1;
950 } else {
951 for (p2 = p1 + 1; *p2 && !isspace(*p2); ++p2) ;
953 tokens->append(new GString(p1, p2 - p1));
954 p1 = *p2 ? p2 + 1 : p2;
957 // parse the line
958 if (tokens->getLength() > 0 &&
959 ((GString *)tokens->get(0))->getChar(0) != '#') {
960 cmd = (GString *)tokens->get(0);
961 if (!cmd->cmp("include")) {
962 if (tokens->getLength() == 2) {
963 incFile = (GString *)tokens->get(1);
964 if ((f2 = fopen(incFile->getCString(), "r"))) {
965 parseFile(incFile, f2);
966 fclose(f2);
967 } else {
968 error(-1, (char*)"Couldn't find included config file: '%s' (%s:%d)",
969 incFile->getCString(), fileName->getCString(), line);
971 } else {
972 error(-1, (char*)"Bad 'include' config file command (%s:%d)",
973 fileName->getCString(), line);
975 } else if (!cmd->cmp("nameToUnicode")) {
976 parseNameToUnicode(tokens, fileName, line);
977 } else if (!cmd->cmp("cidToUnicode")) {
978 parseCIDToUnicode(tokens, fileName, line);
979 } else if (!cmd->cmp("unicodeToUnicode")) {
980 parseUnicodeToUnicode(tokens, fileName, line);
981 } else if (!cmd->cmp("unicodeMap")) {
982 parseUnicodeMap(tokens, fileName, line);
983 } else if (!cmd->cmp("cMapDir")) {
984 parseCMapDir(tokens, fileName, line);
985 } else if (!cmd->cmp("toUnicodeDir")) {
986 parseToUnicodeDir(tokens, fileName, line);
987 } else if (!cmd->cmp("displayFontT1")) {
988 parseDisplayFont(tokens, displayFonts, displayFontT1, fileName, line);
989 } else if (!cmd->cmp("displayFontTT")) {
990 parseDisplayFont(tokens, displayFonts, displayFontTT, fileName, line);
991 } else if (!cmd->cmp("displayNamedCIDFontT1")) {
992 parseDisplayFont(tokens, displayNamedCIDFonts,
993 displayFontT1, fileName, line);
994 } else if (!cmd->cmp("displayCIDFontT1")) {
995 parseDisplayFont(tokens, displayCIDFonts,
996 displayFontT1, fileName, line);
997 } else if (!cmd->cmp("displayNamedCIDFontTT")) {
998 parseDisplayFont(tokens, displayNamedCIDFonts,
999 displayFontTT, fileName, line);
1000 } else if (!cmd->cmp("displayCIDFontTT")) {
1001 parseDisplayFont(tokens, displayCIDFonts,
1002 displayFontTT, fileName, line);
1003 } else if (!cmd->cmp("psFile")) {
1004 parsePSFile(tokens, fileName, line);
1005 } else if (!cmd->cmp("psFont")) {
1006 parsePSFont(tokens, fileName, line);
1007 } else if (!cmd->cmp("psNamedFont16")) {
1008 parsePSFont16("psNamedFont16", psNamedFonts16,
1009 tokens, fileName, line);
1010 } else if (!cmd->cmp("psFont16")) {
1011 parsePSFont16("psFont16", psFonts16, tokens, fileName, line);
1012 } else if (!cmd->cmp("psPaperSize")) {
1013 parsePSPaperSize(tokens, fileName, line);
1014 } else if (!cmd->cmp("psImageableArea")) {
1015 parsePSImageableArea(tokens, fileName, line);
1016 } else if (!cmd->cmp("psCrop")) {
1017 parseYesNo("psCrop", &psCrop, tokens, fileName, line);
1018 } else if (!cmd->cmp("psExpandSmaller")) {
1019 parseYesNo("psExpandSmaller", &psExpandSmaller,
1020 tokens, fileName, line);
1021 } else if (!cmd->cmp("psShrinkLarger")) {
1022 parseYesNo("psShrinkLarger", &psShrinkLarger, tokens, fileName, line);
1023 } else if (!cmd->cmp("psCenter")) {
1024 parseYesNo("psCenter", &psCenter, tokens, fileName, line);
1025 } else if (!cmd->cmp("psDuplex")) {
1026 parseYesNo("psDuplex", &psDuplex, tokens, fileName, line);
1027 } else if (!cmd->cmp("psLevel")) {
1028 parsePSLevel(tokens, fileName, line);
1029 } else if (!cmd->cmp("psEmbedType1Fonts")) {
1030 parseYesNo("psEmbedType1", &psEmbedType1, tokens, fileName, line);
1031 } else if (!cmd->cmp("psEmbedTrueTypeFonts")) {
1032 parseYesNo("psEmbedTrueType", &psEmbedTrueType,
1033 tokens, fileName, line);
1034 } else if (!cmd->cmp("psEmbedCIDPostScriptFonts")) {
1035 parseYesNo("psEmbedCIDPostScript", &psEmbedCIDPostScript,
1036 tokens, fileName, line);
1037 } else if (!cmd->cmp("psEmbedCIDTrueTypeFonts")) {
1038 parseYesNo("psEmbedCIDTrueType", &psEmbedCIDTrueType,
1039 tokens, fileName, line);
1040 } else if (!cmd->cmp("psPreload")) {
1041 parseYesNo("psPreload", &psPreload, tokens, fileName, line);
1042 } else if (!cmd->cmp("psOPI")) {
1043 parseYesNo("psOPI", &psOPI, tokens, fileName, line);
1044 } else if (!cmd->cmp("psASCIIHex")) {
1045 parseYesNo("psASCIIHex", &psASCIIHex, tokens, fileName, line);
1046 } else if (!cmd->cmp("textEncoding")) {
1047 parseTextEncoding(tokens, fileName, line);
1048 } else if (!cmd->cmp("textEOL")) {
1049 parseTextEOL(tokens, fileName, line);
1050 } else if (!cmd->cmp("textPageBreaks")) {
1051 parseYesNo("textPageBreaks", &textPageBreaks,
1052 tokens, fileName, line);
1053 } else if (!cmd->cmp("textKeepTinyChars")) {
1054 parseYesNo("textKeepTinyChars", &textKeepTinyChars,
1055 tokens, fileName, line);
1056 } else if (!cmd->cmp("fontDir")) {
1057 parseFontDir(tokens, fileName, line);
1058 } else if (!cmd->cmp("initialZoom")) {
1059 parseInitialZoom(tokens, fileName, line);
1060 } else if (!cmd->cmp("continuousView")) {
1061 parseYesNo("continuousView", &continuousView, tokens, fileName, line);
1062 } else if (!cmd->cmp("enableT1lib")) {
1063 parseYesNo("enableT1lib", &enableT1lib, tokens, fileName, line);
1064 } else if (!cmd->cmp("enableFreeType")) {
1065 parseYesNo("enableFreeType", &enableFreeType, tokens, fileName, line);
1066 } else if (!cmd->cmp("antialias")) {
1067 parseYesNo("antialias", &antialias, tokens, fileName, line);
1068 } else if (!cmd->cmp("vectorAntialias")) {
1069 parseYesNo("vectorAntialias", &vectorAntialias,
1070 tokens, fileName, line);
1071 } else if (!cmd->cmp("strokeAdjust")) {
1072 parseYesNo("strokeAdjust", &strokeAdjust, tokens, fileName, line);
1073 } else if (!cmd->cmp("screenType")) {
1074 parseScreenType(tokens, fileName, line);
1075 } else if (!cmd->cmp("screenSize")) {
1076 parseInteger("screenSize", &screenSize, tokens, fileName, line);
1077 } else if (!cmd->cmp("screenDotRadius")) {
1078 parseInteger("screenDotRadius", &screenDotRadius,
1079 tokens, fileName, line);
1080 } else if (!cmd->cmp("screenGamma")) {
1081 parseFloat("screenGamma", &screenGamma,
1082 tokens, fileName, line);
1083 } else if (!cmd->cmp("screenBlackThreshold")) {
1084 parseFloat("screenBlackThreshold", &screenBlackThreshold,
1085 tokens, fileName, line);
1086 } else if (!cmd->cmp("screenWhiteThreshold")) {
1087 parseFloat("screenWhiteThreshold", &screenWhiteThreshold,
1088 tokens, fileName, line);
1089 } else if (!cmd->cmp("urlCommand")) {
1090 parseCommand("urlCommand", &urlCommand, tokens, fileName, line);
1091 } else if (!cmd->cmp("movieCommand")) {
1092 parseCommand("movieCommand", &movieCommand, tokens, fileName, line);
1093 } else if (!cmd->cmp("mapNumericCharNames")) {
1094 parseYesNo("mapNumericCharNames", &mapNumericCharNames,
1095 tokens, fileName, line);
1096 } else if (!cmd->cmp("mapUnknownCharNames")) {
1097 parseYesNo("mapUnknownCharNames", &mapUnknownCharNames,
1098 tokens, fileName, line);
1099 } else if (!cmd->cmp("bind")) {
1100 parseBind(tokens, fileName, line);
1101 } else if (!cmd->cmp("unbind")) {
1102 parseUnbind(tokens, fileName, line);
1103 } else if (!cmd->cmp("printCommands")) {
1104 parseYesNo("printCommands", &printCommands, tokens, fileName, line);
1105 } else if (!cmd->cmp("errQuiet")) {
1106 parseYesNo("errQuiet", &errQuiet, tokens, fileName, line);
1107 } else {
1108 error(-1, (char*)"Unknown config file command '%s' (%s:%d)",
1109 cmd->getCString(), fileName->getCString(), line);
1110 if (!cmd->cmp("displayFontX") ||
1111 !cmd->cmp("displayNamedCIDFontX") ||
1112 !cmd->cmp("displayCIDFontX")) {
1113 error(-1, (char*)"-- Xpdf no longer supports X fonts");
1114 } else if (!cmd->cmp("t1libControl") || !cmd->cmp("freetypeControl")) {
1115 error(-1, (char*)"-- The t1libControl and freetypeControl options have been replaced");
1116 error(-1, (char*)" by the enableT1lib, enableFreeType, and antialias options");
1117 } else if (!cmd->cmp("fontpath") || !cmd->cmp("fontmap")) {
1118 error(-1, (char*)"-- the config file format has changed since Xpdf 0.9x");
1123 deleteGList(tokens, GString);
1126 void GlobalParams::parseNameToUnicode(GList *tokens, GString *fileName,
1127 int line) {
1128 GString *name;
1129 char *tok1, *tok2;
1130 FILE *f;
1131 char buf[256];
1132 int line2;
1133 Unicode u;
1135 if (tokens->getLength() != 2) {
1136 error(-1, (char*)"Bad 'nameToUnicode' config file command (%s:%d)",
1137 fileName->getCString(), line);
1138 return;
1140 name = (GString *)tokens->get(1);
1141 if (!(f = fopen(name->getCString(), "r"))) {
1142 error(-1, (char*)"Couldn't open 'nameToUnicode' file '%s'",
1143 name->getCString());
1144 return;
1146 line2 = 1;
1147 while (getLine(buf, sizeof(buf), f)) {
1148 tok1 = strtok(buf, " \t\r\n");
1149 tok2 = strtok(NULL, " \t\r\n");
1150 if (tok1 && tok2) {
1151 sscanf(tok1, "%x", &u);
1152 nameToUnicode->add(tok2, u);
1153 } else {
1154 error(-1, (char*)"Bad line in 'nameToUnicode' file (%s:%d)", name, line2);
1156 ++line2;
1158 fclose(f);
1161 void GlobalParams::parseCIDToUnicode(GList *tokens, GString *fileName,
1162 int line) {
1163 GString *collection, *name, *old;
1165 if (tokens->getLength() != 3) {
1166 error(-1, (char*)"Bad 'cidToUnicode' config file command (%s:%d)",
1167 fileName->getCString(), line);
1168 return;
1170 collection = (GString *)tokens->get(1);
1171 name = (GString *)tokens->get(2);
1172 if ((old = (GString *)cidToUnicodes->remove(collection))) {
1173 delete old;
1175 cidToUnicodes->add(collection->copy(), name->copy());
1178 void GlobalParams::parseUnicodeToUnicode(GList *tokens, GString *fileName,
1179 int line) {
1180 GString *font, *file, *old;
1182 if (tokens->getLength() != 3) {
1183 error(-1, (char*)"Bad 'unicodeToUnicode' config file command (%s:%d)",
1184 fileName->getCString(), line);
1185 return;
1187 font = (GString *)tokens->get(1);
1188 file = (GString *)tokens->get(2);
1189 if ((old = (GString *)unicodeToUnicodes->remove(font))) {
1190 delete old;
1192 unicodeToUnicodes->add(font->copy(), file->copy());
1195 void GlobalParams::parseUnicodeMap(GList *tokens, GString *fileName,
1196 int line) {
1197 GString *encodingName, *name, *old;
1199 if (tokens->getLength() != 3) {
1200 error(-1, (char*)"Bad 'unicodeMap' config file command (%s:%d)",
1201 fileName->getCString(), line);
1202 return;
1204 encodingName = (GString *)tokens->get(1);
1205 name = (GString *)tokens->get(2);
1206 if ((old = (GString *)unicodeMaps->remove(encodingName))) {
1207 delete old;
1209 unicodeMaps->add(encodingName->copy(), name->copy());
1212 void GlobalParams::parseCMapDir(GList *tokens, GString *fileName, int line) {
1213 GString *collection, *dir;
1214 GList *list;
1216 if (tokens->getLength() != 3) {
1217 error(-1, (char*)"Bad 'cMapDir' config file command (%s:%d)",
1218 fileName->getCString(), line);
1219 return;
1221 collection = (GString *)tokens->get(1);
1222 dir = (GString *)tokens->get(2);
1223 if (!(list = (GList *)cMapDirs->lookup(collection))) {
1224 list = new GList();
1225 cMapDirs->add(collection->copy(), list);
1227 list->append(dir->copy());
1230 void GlobalParams::parseToUnicodeDir(GList *tokens, GString *fileName,
1231 int line) {
1232 if (tokens->getLength() != 2) {
1233 error(-1, (char*)"Bad 'toUnicodeDir' config file command (%s:%d)",
1234 fileName->getCString(), line);
1235 return;
1237 toUnicodeDirs->append(((GString *)tokens->get(1))->copy());
1240 void GlobalParams::parseDisplayFont(GList *tokens, GHash *fontHash,
1241 DisplayFontParamKind kind,
1242 GString *fileName, int line) {
1243 DisplayFontParam *param, *old;
1245 if (tokens->getLength() < 2) {
1246 goto err1;
1248 param = new DisplayFontParam(((GString *)tokens->get(1))->copy(), kind);
1250 switch (kind) {
1251 case displayFontT1:
1252 if (tokens->getLength() != 3) {
1253 goto err2;
1255 param->t1.fileName = ((GString *)tokens->get(2))->copy();
1256 break;
1257 case displayFontTT:
1258 if (tokens->getLength() != 3) {
1259 goto err2;
1261 param->tt.fileName = ((GString *)tokens->get(2))->copy();
1262 break;
1265 if ((old = (DisplayFontParam *)fontHash->remove(param->name))) {
1266 delete old;
1268 fontHash->add(param->name, param);
1269 return;
1271 err2:
1272 delete param;
1273 err1:
1274 error(-1, (char*)"Bad 'display*Font*' config file command (%s:%d)",
1275 fileName->getCString(), line);
1278 void GlobalParams::parsePSPaperSize(GList *tokens, GString *fileName,
1279 int line) {
1280 GString *tok;
1282 if (tokens->getLength() == 2) {
1283 tok = (GString *)tokens->get(1);
1284 if (!setPSPaperSize(tok->getCString())) {
1285 error(-1, (char*)"Bad 'psPaperSize' config file command (%s:%d)",
1286 fileName->getCString(), line);
1288 } else if (tokens->getLength() == 3) {
1289 tok = (GString *)tokens->get(1);
1290 psPaperWidth = atoi(tok->getCString());
1291 tok = (GString *)tokens->get(2);
1292 psPaperHeight = atoi(tok->getCString());
1293 psImageableLLX = psImageableLLY = 0;
1294 psImageableURX = psPaperWidth;
1295 psImageableURY = psPaperHeight;
1296 } else {
1297 error(-1, (char*)"Bad 'psPaperSize' config file command (%s:%d)",
1298 fileName->getCString(), line);
1302 void GlobalParams::parsePSImageableArea(GList *tokens, GString *fileName,
1303 int line) {
1304 if (tokens->getLength() != 5) {
1305 error(-1, (char*)"Bad 'psImageableArea' config file command (%s:%d)",
1306 fileName->getCString(), line);
1307 return;
1309 psImageableLLX = atoi(((GString *)tokens->get(1))->getCString());
1310 psImageableLLY = atoi(((GString *)tokens->get(2))->getCString());
1311 psImageableURX = atoi(((GString *)tokens->get(3))->getCString());
1312 psImageableURY = atoi(((GString *)tokens->get(4))->getCString());
1315 void GlobalParams::parsePSLevel(GList *tokens, GString *fileName, int line) {
1316 GString *tok;
1318 if (tokens->getLength() != 2) {
1319 error(-1, (char*)"Bad 'psLevel' config file command (%s:%d)",
1320 fileName->getCString(), line);
1321 return;
1323 tok = (GString *)tokens->get(1);
1324 if (!tok->cmp("level1")) {
1325 psLevel = psLevel1;
1326 } else if (!tok->cmp("level1sep")) {
1327 psLevel = psLevel1Sep;
1328 } else if (!tok->cmp("level2")) {
1329 psLevel = psLevel2;
1330 } else if (!tok->cmp("level2sep")) {
1331 psLevel = psLevel2Sep;
1332 } else if (!tok->cmp("level3")) {
1333 psLevel = psLevel3;
1334 } else if (!tok->cmp("level3Sep")) {
1335 psLevel = psLevel3Sep;
1336 } else {
1337 error(-1, (char*)"Bad 'psLevel' config file command (%s:%d)",
1338 fileName->getCString(), line);
1342 void GlobalParams::parsePSFile(GList *tokens, GString *fileName, int line) {
1343 if (tokens->getLength() != 2) {
1344 error(-1, (char*)"Bad 'psFile' config file command (%s:%d)",
1345 fileName->getCString(), line);
1346 return;
1348 if (psFile) {
1349 delete psFile;
1351 psFile = ((GString *)tokens->get(1))->copy();
1354 void GlobalParams::parsePSFont(GList *tokens, GString *fileName, int line) {
1355 PSFontParam *param;
1357 if (tokens->getLength() != 3) {
1358 error(-1, (char*)"Bad 'psFont' config file command (%s:%d)",
1359 fileName->getCString(), line);
1360 return;
1362 param = new PSFontParam(((GString *)tokens->get(1))->copy(), 0,
1363 ((GString *)tokens->get(2))->copy(), NULL);
1364 psFonts->add(param->pdfFontName, param);
1367 void GlobalParams::parsePSFont16(const char *cmdName, GList *fontList,
1368 GList *tokens, GString *fileName, int line) {
1369 PSFontParam *param;
1370 int wMode;
1371 GString *tok;
1373 if (tokens->getLength() != 5) {
1374 error(-1, (char*)"Bad '%s' config file command (%s:%d)",
1375 cmdName, fileName->getCString(), line);
1376 return;
1378 tok = (GString *)tokens->get(2);
1379 if (!tok->cmp("H")) {
1380 wMode = 0;
1381 } else if (!tok->cmp("V")) {
1382 wMode = 1;
1383 } else {
1384 error(-1, (char*)"Bad '%s' config file command (%s:%d)",
1385 cmdName, fileName->getCString(), line);
1386 return;
1388 param = new PSFontParam(((GString *)tokens->get(1))->copy(),
1389 wMode,
1390 ((GString *)tokens->get(3))->copy(),
1391 ((GString *)tokens->get(4))->copy());
1392 fontList->append(param);
1395 void GlobalParams::parseTextEncoding(GList *tokens, GString *fileName,
1396 int line) {
1397 if (tokens->getLength() != 2) {
1398 error(-1, (char*)"Bad 'textEncoding' config file command (%s:%d)",
1399 fileName->getCString(), line);
1400 return;
1402 delete textEncoding;
1403 textEncoding = ((GString *)tokens->get(1))->copy();
1406 void GlobalParams::parseTextEOL(GList *tokens, GString *fileName, int line) {
1407 GString *tok;
1409 if (tokens->getLength() != 2) {
1410 error(-1, (char*)"Bad 'textEOL' config file command (%s:%d)",
1411 fileName->getCString(), line);
1412 return;
1414 tok = (GString *)tokens->get(1);
1415 if (!tok->cmp("unix")) {
1416 textEOL = eolUnix;
1417 } else if (!tok->cmp("dos")) {
1418 textEOL = eolDOS;
1419 } else if (!tok->cmp("mac")) {
1420 textEOL = eolMac;
1421 } else {
1422 error(-1, (char*)"Bad 'textEOL' config file command (%s:%d)",
1423 fileName->getCString(), line);
1427 void GlobalParams::parseFontDir(GList *tokens, GString *fileName, int line) {
1428 if (tokens->getLength() != 2) {
1429 error(-1, (char*)"Bad 'fontDir' config file command (%s:%d)",
1430 fileName->getCString(), line);
1431 return;
1433 fontDirs->append(((GString *)tokens->get(1))->copy());
1436 void GlobalParams::parseInitialZoom(GList *tokens,
1437 GString *fileName, int line) {
1438 if (tokens->getLength() != 2) {
1439 error(-1, (char*)"Bad 'initialZoom' config file command (%s:%d)",
1440 fileName->getCString(), line);
1441 return;
1443 delete initialZoom;
1444 initialZoom = ((GString *)tokens->get(1))->copy();
1447 void GlobalParams::parseScreenType(GList *tokens, GString *fileName,
1448 int line) {
1449 GString *tok;
1451 if (tokens->getLength() != 2) {
1452 error(-1, (char*)"Bad 'screenType' config file command (%s:%d)",
1453 fileName->getCString(), line);
1454 return;
1456 tok = (GString *)tokens->get(1);
1457 if (!tok->cmp("dispersed")) {
1458 screenType = screenDispersed;
1459 } else if (!tok->cmp("clustered")) {
1460 screenType = screenClustered;
1461 } else if (!tok->cmp("stochasticClustered")) {
1462 screenType = screenStochasticClustered;
1463 } else {
1464 error(-1, (char*)"Bad 'screenType' config file command (%s:%d)",
1465 fileName->getCString(), line);
1469 void GlobalParams::parseBind(GList *tokens, GString *fileName, int line) {
1470 KeyBinding *binding;
1471 GList *cmds;
1472 int code, mods, context, i;
1474 if (tokens->getLength() < 4) {
1475 error(-1, (char*)"Bad 'bind' config file command (%s:%d)",
1476 fileName->getCString(), line);
1477 return;
1479 if (!parseKey((GString *)tokens->get(1), (GString *)tokens->get(2),
1480 &code, &mods, &context,
1481 "bind", tokens, fileName, line)) {
1482 return;
1484 for (i = 0; i < keyBindings->getLength(); ++i) {
1485 binding = (KeyBinding *)keyBindings->get(i);
1486 if (binding->code == code &&
1487 binding->mods == mods &&
1488 binding->context == context) {
1489 delete (KeyBinding *)keyBindings->del(i);
1490 break;
1493 cmds = new GList();
1494 for (i = 3; i < tokens->getLength(); ++i) {
1495 cmds->append(((GString *)tokens->get(i))->copy());
1497 keyBindings->append(new KeyBinding(code, mods, context, cmds));
1500 void GlobalParams::parseUnbind(GList *tokens, GString *fileName, int line) {
1501 KeyBinding *binding;
1502 int code, mods, context, i;
1504 if (tokens->getLength() != 3) {
1505 error(-1, (char*)"Bad 'unbind' config file command (%s:%d)",
1506 fileName->getCString(), line);
1507 return;
1509 if (!parseKey((GString *)tokens->get(1), (GString *)tokens->get(2),
1510 &code, &mods, &context,
1511 "unbind", tokens, fileName, line)) {
1512 return;
1514 for (i = 0; i < keyBindings->getLength(); ++i) {
1515 binding = (KeyBinding *)keyBindings->get(i);
1516 if (binding->code == code &&
1517 binding->mods == mods &&
1518 binding->context == context) {
1519 delete (KeyBinding *)keyBindings->del(i);
1520 break;
1525 GBool GlobalParams::parseKey(GString *modKeyStr, GString *contextStr,
1526 int *code, int *mods, int *context,
1527 const char *cmdName,
1528 GList *tokens, GString *fileName, int line) {
1529 char *p0;
1531 *mods = xpdfKeyModNone;
1532 p0 = modKeyStr->getCString();
1533 while (1) {
1534 if (!strncmp(p0, "shift-", 6)) {
1535 *mods |= xpdfKeyModShift;
1536 p0 += 6;
1537 } else if (!strncmp(p0, "ctrl-", 5)) {
1538 *mods |= xpdfKeyModCtrl;
1539 p0 += 5;
1540 } else if (!strncmp(p0, "alt-", 4)) {
1541 *mods |= xpdfKeyModAlt;
1542 p0 += 4;
1543 } else {
1544 break;
1548 if (!strcmp(p0, "space")) {
1549 *code = ' ';
1550 } else if (!strcmp(p0, "tab")) {
1551 *code = xpdfKeyCodeTab;
1552 } else if (!strcmp(p0, "return")) {
1553 *code = xpdfKeyCodeReturn;
1554 } else if (!strcmp(p0, "enter")) {
1555 *code = xpdfKeyCodeEnter;
1556 } else if (!strcmp(p0, "backspace")) {
1557 *code = xpdfKeyCodeBackspace;
1558 } else if (!strcmp(p0, "insert")) {
1559 *code = xpdfKeyCodeInsert;
1560 } else if (!strcmp(p0, "delete")) {
1561 *code = xpdfKeyCodeDelete;
1562 } else if (!strcmp(p0, "home")) {
1563 *code = xpdfKeyCodeHome;
1564 } else if (!strcmp(p0, "end")) {
1565 *code = xpdfKeyCodeEnd;
1566 } else if (!strcmp(p0, "pgup")) {
1567 *code = xpdfKeyCodePgUp;
1568 } else if (!strcmp(p0, "pgdn")) {
1569 *code = xpdfKeyCodePgDn;
1570 } else if (!strcmp(p0, "left")) {
1571 *code = xpdfKeyCodeLeft;
1572 } else if (!strcmp(p0, "right")) {
1573 *code = xpdfKeyCodeRight;
1574 } else if (!strcmp(p0, "up")) {
1575 *code = xpdfKeyCodeUp;
1576 } else if (!strcmp(p0, "down")) {
1577 *code = xpdfKeyCodeDown;
1578 } else if (p0[0] == 'f' && p0[1] >= '1' && p0[1] <= '9' && !p0[2]) {
1579 *code = xpdfKeyCodeF1 + (p0[1] - '1');
1580 } else if (p0[0] == 'f' &&
1581 ((p0[1] >= '1' && p0[1] <= '2' && p0[2] >= '0' && p0[2] <= '9') ||
1582 (p0[1] == '3' && p0[2] >= '0' && p0[2] <= '5')) &&
1583 !p0[3]) {
1584 *code = xpdfKeyCodeF1 + 10 * (p0[1] - '0') + (p0[2] - '0') - 1;
1585 } else if (!strncmp(p0, "mousePress", 10) &&
1586 p0[10] >= '1' && p0[10] <= '7' && !p0[11]) {
1587 *code = xpdfKeyCodeMousePress1 + (p0[10] - '1');
1588 } else if (!strncmp(p0, "mouseRelease", 12) &&
1589 p0[12] >= '1' && p0[12] <= '7' && !p0[13]) {
1590 *code = xpdfKeyCodeMouseRelease1 + (p0[12] - '1');
1591 } else if (*p0 >= 0x20 && *p0 <= 0x7e && !p0[1]) {
1592 *code = (int)*p0;
1593 } else {
1594 error(-1, (char*)"Bad key/modifier in '%s' config file command (%s:%d)",
1595 cmdName, fileName->getCString(), line);
1596 return gFalse;
1599 p0 = contextStr->getCString();
1600 if (!strcmp(p0, "any")) {
1601 *context = xpdfKeyContextAny;
1602 } else {
1603 *context = xpdfKeyContextAny;
1604 while (1) {
1605 if (!strncmp(p0, "fullScreen", 10)) {
1606 *context |= xpdfKeyContextFullScreen;
1607 p0 += 10;
1608 } else if (!strncmp(p0, "window", 6)) {
1609 *context |= xpdfKeyContextWindow;
1610 p0 += 6;
1611 } else if (!strncmp(p0, "continuous", 10)) {
1612 *context |= xpdfKeyContextContinuous;
1613 p0 += 10;
1614 } else if (!strncmp(p0, "singlePage", 10)) {
1615 *context |= xpdfKeyContextSinglePage;
1616 p0 += 10;
1617 } else if (!strncmp(p0, "overLink", 8)) {
1618 *context |= xpdfKeyContextOverLink;
1619 p0 += 8;
1620 } else if (!strncmp(p0, "offLink", 7)) {
1621 *context |= xpdfKeyContextOffLink;
1622 p0 += 7;
1623 } else if (!strncmp(p0, "outline", 7)) {
1624 *context |= xpdfKeyContextOutline;
1625 p0 += 7;
1626 } else if (!strncmp(p0, "mainWin", 7)) {
1627 *context |= xpdfKeyContextMainWin;
1628 p0 += 7;
1629 } else if (!strncmp(p0, "scrLockOn", 9)) {
1630 *context |= xpdfKeyContextScrLockOn;
1631 p0 += 9;
1632 } else if (!strncmp(p0, "scrLockOff", 10)) {
1633 *context |= xpdfKeyContextScrLockOff;
1634 p0 += 10;
1635 } else {
1636 error(-1, (char*)"Bad context in '%s' config file command (%s:%d)",
1637 cmdName, fileName->getCString(), line);
1638 return gFalse;
1640 if (!*p0) {
1641 break;
1643 if (*p0 != ',') {
1644 error(-1, (char*)"Bad context in '%s' config file command (%s:%d)",
1645 cmdName, fileName->getCString(), line);
1646 return gFalse;
1648 ++p0;
1652 return gTrue;
1655 void GlobalParams::parseCommand(const char *cmdName, GString **val,
1656 GList *tokens, GString *fileName, int line) {
1657 if (tokens->getLength() != 2) {
1658 error(-1, (char*)"Bad '%s' config file command (%s:%d)",
1659 cmdName, fileName->getCString(), line);
1660 return;
1662 if (*val) {
1663 delete *val;
1665 *val = ((GString *)tokens->get(1))->copy();
1668 void GlobalParams::parseYesNo(const char *cmdName, GBool *flag,
1669 GList *tokens, GString *fileName, int line) {
1670 GString *tok;
1672 if (tokens->getLength() != 2) {
1673 error(-1, (char*)"Bad '%s' config file command (%s:%d)",
1674 cmdName, fileName->getCString(), line);
1675 return;
1677 tok = (GString *)tokens->get(1);
1678 if (!parseYesNo2(tok->getCString(), flag)) {
1679 error(-1, (char*)"Bad '%s' config file command (%s:%d)",
1680 cmdName, fileName->getCString(), line);
1684 GBool GlobalParams::parseYesNo2(const char *token, GBool *flag) {
1685 if (!strcmp(token, "yes")) {
1686 *flag = gTrue;
1687 } else if (!strcmp(token, "no")) {
1688 *flag = gFalse;
1689 } else {
1690 return gFalse;
1692 return gTrue;
1695 void GlobalParams::parseInteger(const char *cmdName, int *val,
1696 GList *tokens, GString *fileName, int line) {
1697 GString *tok;
1698 int i;
1700 if (tokens->getLength() != 2) {
1701 error(-1, (char*)"Bad '%s' config file command (%s:%d)",
1702 cmdName, fileName->getCString(), line);
1703 return;
1705 tok = (GString *)tokens->get(1);
1706 if (tok->getLength() == 0) {
1707 error(-1, (char*)"Bad '%s' config file command (%s:%d)",
1708 cmdName, fileName->getCString(), line);
1709 return;
1711 if (tok->getChar(0) == '-') {
1712 i = 1;
1713 } else {
1714 i = 0;
1716 for (; i < tok->getLength(); ++i) {
1717 if (tok->getChar(i) < '0' || tok->getChar(i) > '9') {
1718 error(-1, (char*)"Bad '%s' config file command (%s:%d)",
1719 cmdName, fileName->getCString(), line);
1720 return;
1723 *val = atoi(tok->getCString());
1726 void GlobalParams::parseFloat(const char *cmdName, double *val,
1727 GList *tokens, GString *fileName, int line) {
1728 GString *tok;
1729 int i;
1731 if (tokens->getLength() != 2) {
1732 error(-1, (char*)"Bad '%s' config file command (%s:%d)",
1733 cmdName, fileName->getCString(), line);
1734 return;
1736 tok = (GString *)tokens->get(1);
1737 if (tok->getLength() == 0) {
1738 error(-1, (char*)"Bad '%s' config file command (%s:%d)",
1739 cmdName, fileName->getCString(), line);
1740 return;
1742 if (tok->getChar(0) == '-') {
1743 i = 1;
1744 } else {
1745 i = 0;
1747 for (; i < tok->getLength(); ++i) {
1748 if (!((tok->getChar(i) >= '0' && tok->getChar(i) <= '9') ||
1749 tok->getChar(i) == '.')) {
1750 error(-1, (char*)"Bad '%s' config file command (%s:%d)",
1751 cmdName, fileName->getCString(), line);
1752 return;
1755 *val = atof(tok->getCString());
1758 GlobalParams::~GlobalParams() {
1759 GHashIter *iter;
1760 GString *key;
1761 GList *list;
1763 freeBuiltinFontTables();
1765 delete macRomanReverseMap;
1767 delete baseDir;
1768 delete nameToUnicode;
1769 deleteGHash(cidToUnicodes, GString);
1770 deleteGHash(unicodeToUnicodes, GString);
1771 deleteGHash(residentUnicodeMaps, UnicodeMap);
1772 deleteGHash(unicodeMaps, GString);
1773 deleteGList(toUnicodeDirs, GString);
1774 deleteGHash(displayFonts, DisplayFontParam);
1775 deleteGHash(displayCIDFonts, DisplayFontParam);
1776 deleteGHash(displayNamedCIDFonts, DisplayFontParam);
1777 #ifdef WIN32
1778 if (winFontList) {
1779 delete winFontList;
1781 #endif
1782 if (psFile) {
1783 delete psFile;
1785 deleteGHash(psFonts, PSFontParam);
1786 deleteGList(psNamedFonts16, PSFontParam);
1787 deleteGList(psFonts16, PSFontParam);
1788 delete textEncoding;
1789 deleteGList(fontDirs, GString);
1790 delete initialZoom;
1791 if (urlCommand) {
1792 delete urlCommand;
1794 if (movieCommand) {
1795 delete movieCommand;
1797 deleteGList(keyBindings, KeyBinding);
1799 cMapDirs->startIter(&iter);
1800 while (cMapDirs->getNext(&iter, &key, (void **)&list)) {
1801 deleteGList(list, GString);
1803 delete cMapDirs;
1805 delete cidToUnicodeCache;
1806 delete unicodeToUnicodeCache;
1807 delete unicodeMapCache;
1808 delete cMapCache;
1810 #ifdef ENABLE_PLUGINS
1811 delete securityHandlers;
1812 deleteGList(plugins, Plugin);
1813 #endif
1815 #if MULTITHREADED
1816 gDestroyMutex(&mutex);
1817 gDestroyMutex(&unicodeMapCacheMutex);
1818 gDestroyMutex(&cMapCacheMutex);
1819 #endif
1822 //------------------------------------------------------------------------
1824 void GlobalParams::setBaseDir(char *dir) {
1825 delete baseDir;
1826 baseDir = new GString(dir);
1829 void GlobalParams::setupBaseFonts(char *dir) {
1830 GString *fontName;
1831 GString *fileName;
1832 #ifdef WIN32
1833 HMODULE shell32Lib;
1834 BOOL (__stdcall *SHGetSpecialFolderPathFunc)(HWND hwndOwner,
1835 LPTSTR lpszPath,
1836 int nFolder,
1837 BOOL fCreate);
1838 char winFontDir[MAX_PATH];
1839 #endif
1840 FILE *f;
1841 DisplayFontParamKind kind;
1842 DisplayFontParam *dfp;
1843 int i, j;
1845 #ifdef WIN32
1846 // SHGetSpecialFolderPath isn't available in older versions of
1847 // shell32.dll (Win95 and WinNT4), so do a dynamic load
1848 winFontDir[0] = '\0';
1849 if ((shell32Lib = LoadLibrary("shell32.dll"))) {
1850 if ((SHGetSpecialFolderPathFunc =
1851 (BOOL (__stdcall *)(HWND hwndOwner, LPTSTR lpszPath,
1852 int nFolder, BOOL fCreate))
1853 GetProcAddress(shell32Lib, "SHGetSpecialFolderPathA"))) {
1854 if (!(*SHGetSpecialFolderPathFunc)(NULL, winFontDir,
1855 CSIDL_FONTS, FALSE)) {
1856 winFontDir[0] = '\0';
1860 #endif
1861 for (i = 0; displayFontTab[i].name; ++i) {
1862 fontName = new GString(displayFontTab[i].name);
1863 if (getDisplayFont(fontName)) {
1864 delete fontName;
1865 continue;
1867 fileName = NULL;
1868 kind = displayFontT1; // make gcc happy
1869 if (dir) {
1870 fileName = appendToPath(new GString(dir), (char *)displayFontTab[i].t1FileName);
1871 kind = displayFontT1;
1872 if ((f = fopen(fileName->getCString(), "rb"))) {
1873 fclose(f);
1874 } else {
1875 delete fileName;
1876 fileName = NULL;
1879 #ifdef WIN32
1880 if (!fileName && winFontDir[0] && displayFontTab[i].ttFileName) {
1881 fileName = appendToPath(new GString(winFontDir),
1882 displayFontTab[i].ttFileName);
1883 kind = displayFontTT;
1884 if ((f = fopen(fileName->getCString(), "rb"))) {
1885 fclose(f);
1886 } else {
1887 delete fileName;
1888 fileName = NULL;
1891 // SHGetSpecialFolderPath(CSIDL_FONTS) doesn't work on Win 2k Server
1892 // or Win2003 Server, or with older versions of shell32.dll, so check
1893 // the "standard" directories
1894 if (displayFontTab[i].ttFileName) {
1895 for (j = 0; !fileName && displayFontDirs[j]; ++j) {
1896 fileName = appendToPath(new GString(displayFontDirs[j]),
1897 displayFontTab[i].ttFileName);
1898 kind = displayFontTT;
1899 if ((f = fopen(fileName->getCString(), "rb"))) {
1900 fclose(f);
1901 } else {
1902 delete fileName;
1903 fileName = NULL;
1907 #else
1908 for (j = 0; !fileName && displayFontDirs[j]; ++j) {
1909 fileName = appendToPath(new GString(displayFontDirs[j]),
1910 (char *)displayFontTab[i].t1FileName);
1911 kind = displayFontT1;
1914 if ((f = fopen(fileName->getCString(), "rb"))) {
1915 fclose(f);
1916 } else {
1917 delete fileName;
1918 fileName = NULL;
1921 #endif
1922 if (!fileName) {
1923 error(-1, (char*)"No display font for '%s'", displayFontTab[i].name);
1924 delete fontName;
1925 continue;
1927 dfp = new DisplayFontParam(fontName, kind);
1928 dfp->t1.fileName = fileName;
1929 globalParams->addDisplayFont(dfp);
1932 #ifdef WIN32
1933 if (winFontDir[0]) {
1934 winFontList = new WinFontList(winFontDir);
1936 #endif
1939 //------------------------------------------------------------------------
1940 // accessors
1941 //------------------------------------------------------------------------
1943 CharCode GlobalParams::getMacRomanCharCode(char *charName) {
1944 // no need to lock - macRomanReverseMap is constant
1945 return macRomanReverseMap->lookup(charName);
1948 GString *GlobalParams::getBaseDir() {
1949 GString *s;
1951 lockGlobalParams;
1952 s = baseDir->copy();
1953 unlockGlobalParams;
1954 return s;
1957 Unicode GlobalParams::mapNameToUnicode(char *charName) {
1958 // no need to lock - nameToUnicode is constant
1959 return nameToUnicode->lookup(charName);
1962 UnicodeMap *GlobalParams::getResidentUnicodeMap(GString *encodingName) {
1963 UnicodeMap *map;
1965 lockGlobalParams;
1966 map = (UnicodeMap *)residentUnicodeMaps->lookup(encodingName);
1967 unlockGlobalParams;
1968 if (map) {
1969 map->incRefCnt();
1971 return map;
1974 FILE *GlobalParams::getUnicodeMapFile(GString *encodingName) {
1975 GString *fileName;
1976 FILE *f;
1978 lockGlobalParams;
1979 if ((fileName = (GString *)unicodeMaps->lookup(encodingName))) {
1980 f = fopen(fileName->getCString(), "r");
1981 } else {
1982 f = NULL;
1984 unlockGlobalParams;
1985 return f;
1988 FILE *GlobalParams::findCMapFile(GString *collection, GString *cMapName) {
1989 GList *list;
1990 GString *dir;
1991 GString *fileName;
1992 FILE *f;
1993 int i;
1995 lockGlobalParams;
1996 if (!(list = (GList *)cMapDirs->lookup(collection))) {
1997 unlockGlobalParams;
1998 return NULL;
2000 for (i = 0; i < list->getLength(); ++i) {
2001 dir = (GString *)list->get(i);
2002 fileName = appendToPath(dir->copy(), cMapName->getCString());
2003 f = fopen(fileName->getCString(), "r");
2004 delete fileName;
2005 if (f) {
2006 unlockGlobalParams;
2007 return f;
2010 unlockGlobalParams;
2011 return NULL;
2014 FILE *GlobalParams::findToUnicodeFile(GString *name) {
2015 GString *dir, *fileName;
2016 FILE *f;
2017 int i;
2019 lockGlobalParams;
2020 for (i = 0; i < toUnicodeDirs->getLength(); ++i) {
2021 dir = (GString *)toUnicodeDirs->get(i);
2022 fileName = appendToPath(dir->copy(), name->getCString());
2023 f = fopen(fileName->getCString(), "r");
2024 delete fileName;
2025 if (f) {
2026 unlockGlobalParams;
2027 return f;
2030 unlockGlobalParams;
2031 return NULL;
2034 DisplayFontParam *GlobalParams::getDisplayFont(GString *fontName) {
2035 DisplayFontParam *dfp;
2037 lockGlobalParams;
2038 dfp = (DisplayFontParam *)displayFonts->lookup(fontName);
2039 #ifdef WIN32
2040 if (!dfp && winFontList) {
2041 dfp = winFontList->find(fontName);
2043 #endif
2044 unlockGlobalParams;
2045 return dfp;
2048 DisplayFontParam *GlobalParams::getDisplayCIDFont(GString *fontName,
2049 GString *collection) {
2050 DisplayFontParam *dfp;
2052 lockGlobalParams;
2053 if (!fontName ||
2054 !(dfp = (DisplayFontParam *)displayNamedCIDFonts->lookup(fontName))) {
2055 dfp = (DisplayFontParam *)displayCIDFonts->lookup(collection);
2057 unlockGlobalParams;
2058 return dfp;
2061 GString *GlobalParams::getPSFile() {
2062 GString *s;
2064 lockGlobalParams;
2065 s = psFile ? psFile->copy() : (GString *)NULL;
2066 unlockGlobalParams;
2067 return s;
2070 int GlobalParams::getPSPaperWidth() {
2071 int w;
2073 lockGlobalParams;
2074 w = psPaperWidth;
2075 unlockGlobalParams;
2076 return w;
2079 int GlobalParams::getPSPaperHeight() {
2080 int h;
2082 lockGlobalParams;
2083 h = psPaperHeight;
2084 unlockGlobalParams;
2085 return h;
2088 void GlobalParams::getPSImageableArea(int *llx, int *lly, int *urx, int *ury) {
2089 lockGlobalParams;
2090 *llx = psImageableLLX;
2091 *lly = psImageableLLY;
2092 *urx = psImageableURX;
2093 *ury = psImageableURY;
2094 unlockGlobalParams;
2097 GBool GlobalParams::getPSCrop() {
2098 GBool f;
2100 lockGlobalParams;
2101 f = psCrop;
2102 unlockGlobalParams;
2103 return f;
2106 GBool GlobalParams::getPSExpandSmaller() {
2107 GBool f;
2109 lockGlobalParams;
2110 f = psExpandSmaller;
2111 unlockGlobalParams;
2112 return f;
2115 GBool GlobalParams::getPSShrinkLarger() {
2116 GBool f;
2118 lockGlobalParams;
2119 f = psShrinkLarger;
2120 unlockGlobalParams;
2121 return f;
2124 GBool GlobalParams::getPSCenter() {
2125 GBool f;
2127 lockGlobalParams;
2128 f = psCenter;
2129 unlockGlobalParams;
2130 return f;
2133 GBool GlobalParams::getPSDuplex() {
2134 GBool d;
2136 lockGlobalParams;
2137 d = psDuplex;
2138 unlockGlobalParams;
2139 return d;
2142 PSLevel GlobalParams::getPSLevel() {
2143 PSLevel level;
2145 lockGlobalParams;
2146 level = psLevel;
2147 unlockGlobalParams;
2148 return level;
2151 PSFontParam *GlobalParams::getPSFont(GString *fontName) {
2152 PSFontParam *p;
2154 lockGlobalParams;
2155 p = (PSFontParam *)psFonts->lookup(fontName);
2156 unlockGlobalParams;
2157 return p;
2160 PSFontParam *GlobalParams::getPSFont16(GString *fontName,
2161 GString *collection, int wMode) {
2162 PSFontParam *p;
2163 int i;
2165 lockGlobalParams;
2166 p = NULL;
2167 if (fontName) {
2168 for (i = 0; i < psNamedFonts16->getLength(); ++i) {
2169 p = (PSFontParam *)psNamedFonts16->get(i);
2170 if (!p->pdfFontName->cmp(fontName) &&
2171 p->wMode == wMode) {
2172 break;
2174 p = NULL;
2177 if (!p && collection) {
2178 for (i = 0; i < psFonts16->getLength(); ++i) {
2179 p = (PSFontParam *)psFonts16->get(i);
2180 if (!p->pdfFontName->cmp(collection) &&
2181 p->wMode == wMode) {
2182 break;
2184 p = NULL;
2187 unlockGlobalParams;
2188 return p;
2191 GBool GlobalParams::getPSEmbedType1() {
2192 GBool e;
2194 lockGlobalParams;
2195 e = psEmbedType1;
2196 unlockGlobalParams;
2197 return e;
2200 GBool GlobalParams::getPSEmbedTrueType() {
2201 GBool e;
2203 lockGlobalParams;
2204 e = psEmbedTrueType;
2205 unlockGlobalParams;
2206 return e;
2209 GBool GlobalParams::getPSEmbedCIDPostScript() {
2210 GBool e;
2212 lockGlobalParams;
2213 e = psEmbedCIDPostScript;
2214 unlockGlobalParams;
2215 return e;
2218 GBool GlobalParams::getPSEmbedCIDTrueType() {
2219 GBool e;
2221 lockGlobalParams;
2222 e = psEmbedCIDTrueType;
2223 unlockGlobalParams;
2224 return e;
2227 GBool GlobalParams::getPSPreload() {
2228 GBool preload;
2230 lockGlobalParams;
2231 preload = psPreload;
2232 unlockGlobalParams;
2233 return preload;
2236 GBool GlobalParams::getPSOPI() {
2237 GBool opi;
2239 lockGlobalParams;
2240 opi = psOPI;
2241 unlockGlobalParams;
2242 return opi;
2245 GBool GlobalParams::getPSASCIIHex() {
2246 GBool ah;
2248 lockGlobalParams;
2249 ah = psASCIIHex;
2250 unlockGlobalParams;
2251 return ah;
2254 GString *GlobalParams::getTextEncodingName() {
2255 GString *s;
2257 lockGlobalParams;
2258 s = textEncoding->copy();
2259 unlockGlobalParams;
2260 return s;
2263 EndOfLineKind GlobalParams::getTextEOL() {
2264 EndOfLineKind eol;
2266 lockGlobalParams;
2267 eol = textEOL;
2268 unlockGlobalParams;
2269 return eol;
2272 GBool GlobalParams::getTextPageBreaks() {
2273 GBool pageBreaks;
2275 lockGlobalParams;
2276 pageBreaks = textPageBreaks;
2277 unlockGlobalParams;
2278 return pageBreaks;
2281 GBool GlobalParams::getTextKeepTinyChars() {
2282 GBool tiny;
2284 lockGlobalParams;
2285 tiny = textKeepTinyChars;
2286 unlockGlobalParams;
2287 return tiny;
2290 GString *GlobalParams::findFontFile(GString *fontName, char **exts) {
2291 GString *dir, *fileName;
2292 char **ext;
2293 FILE *f;
2294 int i;
2296 lockGlobalParams;
2297 for (i = 0; i < fontDirs->getLength(); ++i) {
2298 dir = (GString *)fontDirs->get(i);
2299 for (ext = exts; *ext; ++ext) {
2300 fileName = appendToPath(dir->copy(), fontName->getCString());
2301 fileName->append(*ext);
2302 if ((f = fopen(fileName->getCString(), "rb"))) {
2303 fclose(f);
2304 unlockGlobalParams;
2305 return fileName;
2307 delete fileName;
2310 unlockGlobalParams;
2311 return NULL;
2314 GString *GlobalParams::getInitialZoom() {
2315 GString *s;
2317 lockGlobalParams;
2318 s = initialZoom->copy();
2319 unlockGlobalParams;
2320 return s;
2323 GBool GlobalParams::getContinuousView() {
2324 GBool f;
2326 lockGlobalParams;
2327 f = continuousView;
2328 unlockGlobalParams;
2329 return f;
2332 GBool GlobalParams::getEnableT1lib() {
2333 GBool f;
2335 lockGlobalParams;
2336 f = enableT1lib;
2337 unlockGlobalParams;
2338 return f;
2341 GBool GlobalParams::getEnableFreeType() {
2342 GBool f;
2344 lockGlobalParams;
2345 f = enableFreeType;
2346 unlockGlobalParams;
2347 return f;
2351 GBool GlobalParams::getAntialias() {
2352 GBool f;
2354 lockGlobalParams;
2355 f = antialias;
2356 unlockGlobalParams;
2357 return f;
2360 GBool GlobalParams::getVectorAntialias() {
2361 GBool f;
2363 lockGlobalParams;
2364 f = vectorAntialias;
2365 unlockGlobalParams;
2366 return f;
2369 GBool GlobalParams::getStrokeAdjust() {
2370 GBool f;
2372 lockGlobalParams;
2373 f = strokeAdjust;
2374 unlockGlobalParams;
2375 return f;
2378 ScreenType GlobalParams::getScreenType() {
2379 ScreenType t;
2381 lockGlobalParams;
2382 t = screenType;
2383 unlockGlobalParams;
2384 return t;
2387 int GlobalParams::getScreenSize() {
2388 int size;
2390 lockGlobalParams;
2391 size = screenSize;
2392 unlockGlobalParams;
2393 return size;
2396 int GlobalParams::getScreenDotRadius() {
2397 int r;
2399 lockGlobalParams;
2400 r = screenDotRadius;
2401 unlockGlobalParams;
2402 return r;
2405 double GlobalParams::getScreenGamma() {
2406 double gamma;
2408 lockGlobalParams;
2409 gamma = screenGamma;
2410 unlockGlobalParams;
2411 return gamma;
2414 double GlobalParams::getScreenBlackThreshold() {
2415 double thresh;
2417 lockGlobalParams;
2418 thresh = screenBlackThreshold;
2419 unlockGlobalParams;
2420 return thresh;
2423 double GlobalParams::getScreenWhiteThreshold() {
2424 double thresh;
2426 lockGlobalParams;
2427 thresh = screenWhiteThreshold;
2428 unlockGlobalParams;
2429 return thresh;
2432 GBool GlobalParams::getMapNumericCharNames() {
2433 GBool map;
2435 lockGlobalParams;
2436 map = mapNumericCharNames;
2437 unlockGlobalParams;
2438 return map;
2441 GBool GlobalParams::getMapUnknownCharNames() {
2442 GBool map;
2444 lockGlobalParams;
2445 map = mapUnknownCharNames;
2446 unlockGlobalParams;
2447 return map;
2450 GList *GlobalParams::getKeyBinding(int code, int mods, int context) {
2451 KeyBinding *binding;
2452 GList *cmds;
2453 int modMask;
2454 int i, j;
2456 lockGlobalParams;
2457 cmds = NULL;
2458 // for ASCII chars, ignore the shift modifier
2459 modMask = code <= 0xff ? ~xpdfKeyModShift : ~0;
2460 for (i = 0; i < keyBindings->getLength(); ++i) {
2461 binding = (KeyBinding *)keyBindings->get(i);
2462 if (binding->code == code &&
2463 (binding->mods & modMask) == (mods & modMask) &&
2464 (~binding->context | context) == ~0) {
2465 cmds = new GList();
2466 for (j = 0; j < binding->cmds->getLength(); ++j) {
2467 cmds->append(((GString *)binding->cmds->get(j))->copy());
2469 break;
2472 unlockGlobalParams;
2473 return cmds;
2476 GBool GlobalParams::getPrintCommands() {
2477 GBool p;
2479 lockGlobalParams;
2480 p = printCommands;
2481 unlockGlobalParams;
2482 return p;
2485 GBool GlobalParams::getErrQuiet() {
2486 // no locking -- this function may get called from inside a locked
2487 // section
2488 return errQuiet;
2491 CharCodeToUnicode *GlobalParams::getCIDToUnicode(GString *collection) {
2492 GString *fileName;
2493 CharCodeToUnicode *ctu;
2495 lockGlobalParams;
2496 if (!(ctu = cidToUnicodeCache->getCharCodeToUnicode(collection))) {
2497 if ((fileName = (GString *)cidToUnicodes->lookup(collection)) &&
2498 (ctu = CharCodeToUnicode::parseCIDToUnicode(fileName, collection))) {
2499 cidToUnicodeCache->add(ctu);
2502 unlockGlobalParams;
2503 return ctu;
2506 CharCodeToUnicode *GlobalParams::getUnicodeToUnicode(GString *fontName) {
2507 CharCodeToUnicode *ctu;
2508 GHashIter *iter;
2509 GString *fontPattern, *fileName;
2511 lockGlobalParams;
2512 fileName = NULL;
2513 unicodeToUnicodes->startIter(&iter);
2514 while (unicodeToUnicodes->getNext(&iter, &fontPattern, (void **)&fileName)) {
2515 if (strstr(fontName->getCString(), fontPattern->getCString())) {
2516 unicodeToUnicodes->killIter(&iter);
2517 break;
2519 fileName = NULL;
2521 if (fileName) {
2522 if (!(ctu = unicodeToUnicodeCache->getCharCodeToUnicode(fileName))) {
2523 if ((ctu = CharCodeToUnicode::parseUnicodeToUnicode(fileName))) {
2524 unicodeToUnicodeCache->add(ctu);
2527 } else {
2528 ctu = NULL;
2530 unlockGlobalParams;
2531 return ctu;
2534 UnicodeMap *GlobalParams::getUnicodeMap(GString *encodingName) {
2535 return getUnicodeMap2(encodingName);
2538 UnicodeMap *GlobalParams::getUnicodeMap2(GString *encodingName) {
2539 UnicodeMap *map;
2541 if (!(map = getResidentUnicodeMap(encodingName))) {
2542 lockUnicodeMapCache;
2543 map = unicodeMapCache->getUnicodeMap(encodingName);
2544 unlockUnicodeMapCache;
2546 return map;
2549 CMap *GlobalParams::getCMap(GString *collection, GString *cMapName) {
2550 CMap *cMap;
2552 lockCMapCache;
2553 cMap = cMapCache->getCMap(collection, cMapName);
2554 unlockCMapCache;
2555 return cMap;
2558 UnicodeMap *GlobalParams::getTextEncoding() {
2559 return getUnicodeMap2(textEncoding);
2562 //------------------------------------------------------------------------
2563 // functions to set parameters
2564 //------------------------------------------------------------------------
2566 void GlobalParams::addDisplayFont(DisplayFontParam *param) {
2567 DisplayFontParam *old;
2569 lockGlobalParams;
2570 if ((old = (DisplayFontParam *)displayFonts->remove(param->name))) {
2571 delete old;
2573 displayFonts->add(param->name, param);
2574 unlockGlobalParams;
2577 void GlobalParams::setPSFile(char *file) {
2578 lockGlobalParams;
2579 if (psFile) {
2580 delete psFile;
2582 psFile = new GString(file);
2583 unlockGlobalParams;
2586 GBool GlobalParams::setPSPaperSize(char *size) {
2587 lockGlobalParams;
2588 if (!strcmp(size, "match")) {
2589 psPaperWidth = psPaperHeight = -1;
2590 } else if (!strcmp(size, "letter")) {
2591 psPaperWidth = 612;
2592 psPaperHeight = 792;
2593 } else if (!strcmp(size, "legal")) {
2594 psPaperWidth = 612;
2595 psPaperHeight = 1008;
2596 } else if (!strcmp(size, "A4")) {
2597 psPaperWidth = 595;
2598 psPaperHeight = 842;
2599 } else if (!strcmp(size, "A3")) {
2600 psPaperWidth = 842;
2601 psPaperHeight = 1190;
2602 } else {
2603 unlockGlobalParams;
2604 return gFalse;
2606 psImageableLLX = psImageableLLY = 0;
2607 psImageableURX = psPaperWidth;
2608 psImageableURY = psPaperHeight;
2609 unlockGlobalParams;
2610 return gTrue;
2613 void GlobalParams::setPSPaperWidth(int width) {
2614 lockGlobalParams;
2615 psPaperWidth = width;
2616 psImageableLLX = 0;
2617 psImageableURX = psPaperWidth;
2618 unlockGlobalParams;
2621 void GlobalParams::setPSPaperHeight(int height) {
2622 lockGlobalParams;
2623 psPaperHeight = height;
2624 psImageableLLY = 0;
2625 psImageableURY = psPaperHeight;
2626 unlockGlobalParams;
2629 void GlobalParams::setPSImageableArea(int llx, int lly, int urx, int ury) {
2630 lockGlobalParams;
2631 psImageableLLX = llx;
2632 psImageableLLY = lly;
2633 psImageableURX = urx;
2634 psImageableURY = ury;
2635 unlockGlobalParams;
2638 void GlobalParams::setPSCrop(GBool crop) {
2639 lockGlobalParams;
2640 psCrop = crop;
2641 unlockGlobalParams;
2644 void GlobalParams::setPSExpandSmaller(GBool expand) {
2645 lockGlobalParams;
2646 psExpandSmaller = expand;
2647 unlockGlobalParams;
2650 void GlobalParams::setPSShrinkLarger(GBool shrink) {
2651 lockGlobalParams;
2652 psShrinkLarger = shrink;
2653 unlockGlobalParams;
2656 void GlobalParams::setPSCenter(GBool center) {
2657 lockGlobalParams;
2658 psCenter = center;
2659 unlockGlobalParams;
2662 void GlobalParams::setPSDuplex(GBool duplex) {
2663 lockGlobalParams;
2664 psDuplex = duplex;
2665 unlockGlobalParams;
2668 void GlobalParams::setPSLevel(PSLevel level) {
2669 lockGlobalParams;
2670 psLevel = level;
2671 unlockGlobalParams;
2674 void GlobalParams::setPSEmbedType1(GBool embed) {
2675 lockGlobalParams;
2676 psEmbedType1 = embed;
2677 unlockGlobalParams;
2680 void GlobalParams::setPSEmbedTrueType(GBool embed) {
2681 lockGlobalParams;
2682 psEmbedTrueType = embed;
2683 unlockGlobalParams;
2686 void GlobalParams::setPSEmbedCIDPostScript(GBool embed) {
2687 lockGlobalParams;
2688 psEmbedCIDPostScript = embed;
2689 unlockGlobalParams;
2692 void GlobalParams::setPSEmbedCIDTrueType(GBool embed) {
2693 lockGlobalParams;
2694 psEmbedCIDTrueType = embed;
2695 unlockGlobalParams;
2698 void GlobalParams::setPSPreload(GBool preload) {
2699 lockGlobalParams;
2700 psPreload = preload;
2701 unlockGlobalParams;
2704 void GlobalParams::setPSOPI(GBool opi) {
2705 lockGlobalParams;
2706 psOPI = opi;
2707 unlockGlobalParams;
2710 void GlobalParams::setPSASCIIHex(GBool hex) {
2711 lockGlobalParams;
2712 psASCIIHex = hex;
2713 unlockGlobalParams;
2716 void GlobalParams::setTextEncoding(char *encodingName) {
2717 lockGlobalParams;
2718 delete textEncoding;
2719 textEncoding = new GString(encodingName);
2720 unlockGlobalParams;
2723 GBool GlobalParams::setTextEOL(char *s) {
2724 lockGlobalParams;
2725 if (!strcmp(s, "unix")) {
2726 textEOL = eolUnix;
2727 } else if (!strcmp(s, "dos")) {
2728 textEOL = eolDOS;
2729 } else if (!strcmp(s, "mac")) {
2730 textEOL = eolMac;
2731 } else {
2732 unlockGlobalParams;
2733 return gFalse;
2735 unlockGlobalParams;
2736 return gTrue;
2739 void GlobalParams::setTextPageBreaks(GBool pageBreaks) {
2740 lockGlobalParams;
2741 textPageBreaks = pageBreaks;
2742 unlockGlobalParams;
2745 void GlobalParams::setTextKeepTinyChars(GBool keep) {
2746 lockGlobalParams;
2747 textKeepTinyChars = keep;
2748 unlockGlobalParams;
2751 void GlobalParams::setInitialZoom(char *s) {
2752 lockGlobalParams;
2753 delete initialZoom;
2754 initialZoom = new GString(s);
2755 unlockGlobalParams;
2758 void GlobalParams::setContinuousView(GBool cont) {
2759 lockGlobalParams;
2760 continuousView = cont;
2761 unlockGlobalParams;
2764 GBool GlobalParams::setEnableT1lib(char *s) {
2765 GBool ok;
2767 lockGlobalParams;
2768 ok = parseYesNo2(s, &enableT1lib);
2769 unlockGlobalParams;
2770 return ok;
2773 GBool GlobalParams::setEnableFreeType(char *s) {
2774 GBool ok;
2776 lockGlobalParams;
2777 ok = parseYesNo2(s, &enableFreeType);
2778 unlockGlobalParams;
2779 return ok;
2783 GBool GlobalParams::setAntialias(char *s) {
2784 GBool ok;
2786 lockGlobalParams;
2787 ok = parseYesNo2(s, &antialias);
2788 unlockGlobalParams;
2789 return ok;
2792 GBool GlobalParams::setVectorAntialias(char *s) {
2793 GBool ok;
2795 lockGlobalParams;
2796 ok = parseYesNo2(s, &vectorAntialias);
2797 unlockGlobalParams;
2798 return ok;
2801 void GlobalParams::setScreenType(ScreenType t) {
2802 lockGlobalParams;
2803 screenType = t;
2804 unlockGlobalParams;
2807 void GlobalParams::setScreenSize(int size) {
2808 lockGlobalParams;
2809 screenSize = size;
2810 unlockGlobalParams;
2813 void GlobalParams::setScreenDotRadius(int r) {
2814 lockGlobalParams;
2815 screenDotRadius = r;
2816 unlockGlobalParams;
2819 void GlobalParams::setScreenGamma(double gamma) {
2820 lockGlobalParams;
2821 screenGamma = gamma;
2822 unlockGlobalParams;
2825 void GlobalParams::setScreenBlackThreshold(double thresh) {
2826 lockGlobalParams;
2827 screenBlackThreshold = thresh;
2828 unlockGlobalParams;
2831 void GlobalParams::setScreenWhiteThreshold(double thresh) {
2832 lockGlobalParams;
2833 screenWhiteThreshold = thresh;
2834 unlockGlobalParams;
2837 void GlobalParams::setMapNumericCharNames(GBool map) {
2838 lockGlobalParams;
2839 mapNumericCharNames = map;
2840 unlockGlobalParams;
2843 void GlobalParams::setMapUnknownCharNames(GBool map) {
2844 lockGlobalParams;
2845 mapUnknownCharNames = map;
2846 unlockGlobalParams;
2849 void GlobalParams::setPrintCommands(GBool printCommandsA) {
2850 lockGlobalParams;
2851 printCommands = printCommandsA;
2852 unlockGlobalParams;
2855 void GlobalParams::setErrQuiet(GBool errQuietA) {
2856 lockGlobalParams;
2857 errQuiet = errQuietA;
2858 unlockGlobalParams;
2861 void GlobalParams::addSecurityHandler(XpdfSecurityHandler *handler) {
2862 #ifdef ENABLE_PLUGINS
2863 lockGlobalParams;
2864 securityHandlers->append(handler);
2865 unlockGlobalParams;
2866 #endif
2869 XpdfSecurityHandler *GlobalParams::getSecurityHandler(char *name) {
2870 #ifdef ENABLE_PLUGINS
2871 XpdfSecurityHandler *hdlr;
2872 int i;
2874 lockGlobalParams;
2875 for (i = 0; i < securityHandlers->getLength(); ++i) {
2876 hdlr = (XpdfSecurityHandler *)securityHandlers->get(i);
2877 if (!strcasecmp(hdlr->name, name)) {
2878 unlockGlobalParams;
2879 return hdlr;
2882 unlockGlobalParams;
2884 if (!loadPlugin("security", name)) {
2885 return NULL;
2888 lockGlobalParams;
2889 for (i = 0; i < securityHandlers->getLength(); ++i) {
2890 hdlr = (XpdfSecurityHandler *)securityHandlers->get(i);
2891 if (!strcmp(hdlr->name, name)) {
2892 unlockGlobalParams;
2893 return hdlr;
2896 unlockGlobalParams;
2897 #endif
2899 return NULL;
2902 #ifdef ENABLE_PLUGINS
2903 //------------------------------------------------------------------------
2904 // plugins
2905 //------------------------------------------------------------------------
2907 GBool GlobalParams::loadPlugin(char *type, char *name) {
2908 Plugin *plugin;
2910 if (!(plugin = Plugin::load(type, name))) {
2911 return gFalse;
2913 lockGlobalParams;
2914 plugins->append(plugin);
2915 unlockGlobalParams;
2916 return gTrue;
2919 #endif // ENABLE_PLUGINS