]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/GlobalParams.cc
9aa54e9e7ad32645176b6643933017711cf1939a
[evince.git] / pdf / xpdf / GlobalParams.cc
1 //========================================================================
2 //
3 // GlobalParams.cc
4 //
5 // Copyright 2001-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
8
9 #include <aconf.h>
10
11 #ifdef USE_GCC_PRAGMAS
12 #pragma implementation
13 #endif
14
15 #include <string.h>
16 #include <ctype.h>
17 #if HAVE_PAPER_H
18 #include <paper.h>
19 #endif
20 #include "gmem.h"
21 #include "GString.h"
22 #include "GList.h"
23 #include "GHash.h"
24 #include "gfile.h"
25 #include "Error.h"
26 #include "NameToCharCode.h"
27 #include "CharCodeToUnicode.h"
28 #include "UnicodeMap.h"
29 #include "CMap.h"
30 #include "BuiltinFontTables.h"
31 #include "FontEncodingTables.h"
32 #include "GlobalParams.h"
33
34 #if MULTITHREADED
35 #  define lockGlobalParams            gLockMutex(&mutex)
36 #  define lockUnicodeMapCache         gLockMutex(&unicodeMapCacheMutex)
37 #  define lockCMapCache               gLockMutex(&cMapCacheMutex)
38 #  define unlockGlobalParams          gUnlockMutex(&mutex)
39 #  define unlockUnicodeMapCache       gUnlockMutex(&unicodeMapCacheMutex)
40 #  define unlockCMapCache             gUnlockMutex(&cMapCacheMutex)
41 #else
42 #  define lockGlobalParams
43 #  define lockUnicodeMapCache
44 #  define lockCMapCache
45 #  define unlockGlobalParams
46 #  define unlockUnicodeMapCache
47 #  define unlockCMapCache
48 #endif
49
50 #include "NameToUnicodeTable.h"
51 #include "UnicodeMapTables.h"
52 #include "DisplayFontTable.h"
53 #include "UTF8.h"
54
55 //------------------------------------------------------------------------
56
57 #define cidToUnicodeCacheSize     4
58 #define unicodeToUnicodeCacheSize 4
59
60 //------------------------------------------------------------------------
61
62 GlobalParams *globalParams = NULL;
63
64 //------------------------------------------------------------------------
65 // DisplayFontParam
66 //------------------------------------------------------------------------
67
68 DisplayFontParam::DisplayFontParam(GString *nameA,
69                                    DisplayFontParamKind kindA) {
70   name = nameA;
71   kind = kindA;
72   switch (kind) {
73   case displayFontX:
74     x.xlfd = NULL;
75     x.encoding = NULL;
76     break;
77   case displayFontT1:
78     t1.fileName = NULL;
79     break;
80   case displayFontTT:
81     tt.fileName = NULL;
82     break;
83   }
84 }
85
86 DisplayFontParam::DisplayFontParam(char *nameA, char *xlfdA, char *encodingA) {
87   name = new GString(nameA);
88   kind = displayFontX;
89   x.xlfd = new GString(xlfdA);
90   x.encoding = new GString(encodingA);
91 }
92
93 DisplayFontParam::~DisplayFontParam() {
94   delete name;
95   switch (kind) {
96   case displayFontX:
97     if (x.xlfd) {
98       delete x.xlfd;
99     }
100     if (x.encoding) {
101       delete x.encoding;
102     }
103     break;
104   case displayFontT1:
105     if (t1.fileName) {
106       delete t1.fileName;
107     }
108     break;
109   case displayFontTT:
110     if (tt.fileName) {
111       delete tt.fileName;
112     }
113     break;
114   }
115 }
116
117 //------------------------------------------------------------------------
118 // PSFontParam
119 //------------------------------------------------------------------------
120
121 PSFontParam::PSFontParam(GString *pdfFontNameA, int wModeA,
122                          GString *psFontNameA, GString *encodingA) {
123   pdfFontName = pdfFontNameA;
124   wMode = wModeA;
125   psFontName = psFontNameA;
126   encoding = encodingA;
127 }
128
129 PSFontParam::~PSFontParam() {
130   delete pdfFontName;
131   delete psFontName;
132   if (encoding) {
133     delete encoding;
134   }
135 }
136
137 //------------------------------------------------------------------------
138 // parsing
139 //------------------------------------------------------------------------
140
141 GlobalParams::GlobalParams(char *cfgFileName) {
142   UnicodeMap *map;
143   DisplayFontParam *dfp;
144   GString *fileName;
145   FILE *f;
146   int i;
147
148 #if MULTITHREADED
149   gInitMutex(&mutex);
150   gInitMutex(&unicodeMapCacheMutex);
151   gInitMutex(&cMapCacheMutex);
152 #endif
153
154   initBuiltinFontTables();
155
156   // scan the encoding in reverse because we want the lowest-numbered
157   // index for each char name ('space' is encoded twice)
158   macRomanReverseMap = new NameToCharCode();
159   for (i = 255; i >= 0; --i) {
160     if (macRomanEncoding[i]) {
161       macRomanReverseMap->add(macRomanEncoding[i], (CharCode)i);
162     }
163   }
164
165   nameToUnicode = new NameToCharCode();
166   cidToUnicodes = new GHash(gTrue);
167   unicodeToUnicodes = new GHash(gTrue);
168   residentUnicodeMaps = new GHash();
169   unicodeMaps = new GHash(gTrue);
170   cMapDirs = new GHash(gTrue);
171   toUnicodeDirs = new GList();
172   displayFonts = new GHash();
173   displayCIDFonts = new GHash();
174   displayNamedCIDFonts = new GHash();
175 #if HAVE_PAPER_H
176   char *paperName;
177   const struct paper *paperType;
178   paperinit();
179   if ((paperName = systempapername())) {
180     paperType = paperinfo(paperName);
181     psPaperWidth = (int)paperpswidth(paperType);
182     psPaperHeight = (int)paperpsheight(paperType);
183   } else {
184     error(-1, "No paper information available - using defaults");
185     psPaperWidth = defPaperWidth;
186     psPaperHeight = defPaperHeight;
187   }
188   paperdone();
189 #else
190   psPaperWidth = defPaperWidth;
191   psPaperHeight = defPaperHeight;
192 #endif
193   psDuplex = gFalse;
194   psLevel = psLevel2;
195   psFile = NULL;
196   psFonts = new GHash();
197   psNamedFonts16 = new GList();
198   psFonts16 = new GList();
199   psEmbedType1 = gTrue;
200   psEmbedTrueType = gTrue;
201   psEmbedCIDPostScript = gTrue;
202   psEmbedCIDTrueType = gTrue;
203   psOPI = gFalse;
204   psASCIIHex = gFalse;
205   textEncoding = new GString("Latin1");
206 #if defined(WIN32)
207   textEOL = eolDOS;
208 #elif defined(MACOS)
209   textEOL = eolMac;
210 #else
211   textEOL = eolUnix;
212 #endif
213   textPageBreaks = gTrue;
214   textKeepTinyChars = gFalse;
215   fontDirs = new GList();
216   initialZoom = new GString("125");
217   t1libControl = fontRastAALow;
218   freetypeControl = fontRastAALow;
219   urlCommand = NULL;
220   movieCommand = NULL;
221   mapNumericCharNames = gTrue;
222   printCommands = gFalse;
223   errQuiet = gFalse;
224
225   cidToUnicodeCache = new CharCodeToUnicodeCache(cidToUnicodeCacheSize);
226   unicodeToUnicodeCache =
227       new CharCodeToUnicodeCache(unicodeToUnicodeCacheSize);
228   unicodeMapCache = new UnicodeMapCache();
229   cMapCache = new CMapCache();
230
231   // set up the initial nameToUnicode table
232   for (i = 0; nameToUnicodeTab[i].name; ++i) {
233     nameToUnicode->add(nameToUnicodeTab[i].name, nameToUnicodeTab[i].u);
234   }
235
236   // set up the residentUnicodeMaps table
237   map = new UnicodeMap("Latin1", gFalse,
238                        latin1UnicodeMapRanges, latin1UnicodeMapLen);
239   residentUnicodeMaps->add(map->getEncodingName(), map);
240   map = new UnicodeMap("ASCII7", gFalse,
241                        ascii7UnicodeMapRanges, ascii7UnicodeMapLen);
242   residentUnicodeMaps->add(map->getEncodingName(), map);
243   map = new UnicodeMap("Symbol", gFalse,
244                        symbolUnicodeMapRanges, symbolUnicodeMapLen);
245   residentUnicodeMaps->add(map->getEncodingName(), map);
246   map = new UnicodeMap("ZapfDingbats", gFalse, zapfDingbatsUnicodeMapRanges,
247                        zapfDingbatsUnicodeMapLen);
248   residentUnicodeMaps->add(map->getEncodingName(), map);
249   map = new UnicodeMap("UTF-8", gTrue, &mapUTF8);
250   residentUnicodeMaps->add(map->getEncodingName(), map);
251   map = new UnicodeMap("UCS-2", gTrue, &mapUCS2);
252   residentUnicodeMaps->add(map->getEncodingName(), map);
253
254   // default displayFonts table
255   for (i = 0; displayFontTab[i].name; ++i) {
256     dfp = new DisplayFontParam(displayFontTab[i].name,
257                                displayFontTab[i].xlfd,
258                                displayFontTab[i].encoding);
259     displayFonts->add(dfp->name, dfp);
260   }
261
262   // look for a user config file, then a system-wide config file
263   f = NULL;
264   fileName = NULL;
265   if (cfgFileName && cfgFileName[0]) {
266     fileName = new GString(cfgFileName);
267     if (!(f = fopen(fileName->getCString(), "r"))) {
268       delete fileName;
269     }
270   }
271   if (!f) {
272     fileName = appendToPath(getHomeDir(), xpdfUserConfigFile);
273     if (!(f = fopen(fileName->getCString(), "r"))) {
274       delete fileName;
275     }
276   }
277   if (!f) {
278 #if defined(WIN32) && !defined(__CYGWIN32__)
279     char buf[512];
280     i = GetModuleFileName(NULL, buf, sizeof(buf));
281     if (i <= 0 || i >= sizeof(buf)) {
282       // error or path too long for buffer - just use the current dir
283       buf[0] = '\0';
284     }
285     fileName = grabPath(buf);
286     appendToPath(fileName, xpdfSysConfigFile);
287 #else
288     fileName = new GString(xpdfSysConfigFile);
289 #endif
290     if (!(f = fopen(fileName->getCString(), "r"))) {
291       delete fileName;
292     }
293   }
294   if (f) {
295     parseFile(fileName, f);
296     delete fileName;
297     fclose(f);
298   }
299 }
300
301 void GlobalParams::parseFile(GString *fileName, FILE *f) {
302   int line;
303   GList *tokens;
304   GString *cmd, *incFile;
305   char *p1, *p2;
306   char buf[512];
307   FILE *f2;
308
309   line = 1;
310   while (getLine(buf, sizeof(buf) - 1, f)) {
311
312     // break the line into tokens
313     tokens = new GList();
314     p1 = buf;
315     while (*p1) {
316       for (; *p1 && isspace(*p1); ++p1) ;
317       if (!*p1) {
318         break;
319       }
320       if (*p1 == '"' || *p1 == '\'') {
321         for (p2 = p1 + 1; *p2 && *p2 != *p1; ++p2) ;
322         ++p1;
323       } else {
324         for (p2 = p1 + 1; *p2 && !isspace(*p2); ++p2) ;
325       }
326       tokens->append(new GString(p1, p2 - p1));
327       p1 = *p2 ? p2 + 1 : p2;
328     }
329
330     if (tokens->getLength() > 0 &&
331         ((GString *)tokens->get(0))->getChar(0) != '#') {
332       cmd = (GString *)tokens->get(0);
333       if (!cmd->cmp("include")) {
334         if (tokens->getLength() == 2) {
335           incFile = (GString *)tokens->get(1);
336           if ((f2 = fopen(incFile->getCString(), "r"))) {
337             parseFile(incFile, f2);
338             fclose(f2);
339           } else {
340             error(-1, "Couldn't find included config file: '%s' (%s:%d)",
341                   incFile->getCString(), fileName->getCString(), line);
342           }
343         } else {
344           error(-1, "Bad 'include' config file command (%s:%d)",
345                 fileName->getCString(), line);
346         }
347       } else if (!cmd->cmp("nameToUnicode")) {
348         parseNameToUnicode(tokens, fileName, line);
349       } else if (!cmd->cmp("cidToUnicode")) {
350         parseCIDToUnicode(tokens, fileName, line);
351       } else if (!cmd->cmp("unicodeToUnicode")) {
352         parseUnicodeToUnicode(tokens, fileName, line);
353       } else if (!cmd->cmp("unicodeMap")) {
354         parseUnicodeMap(tokens, fileName, line);
355       } else if (!cmd->cmp("cMapDir")) {
356         parseCMapDir(tokens, fileName, line);
357       } else if (!cmd->cmp("toUnicodeDir")) {
358         parseToUnicodeDir(tokens, fileName, line);
359       } else if (!cmd->cmp("displayFontX")) {
360         parseDisplayFont(tokens, displayFonts, displayFontX, fileName, line);
361       } else if (!cmd->cmp("displayFontT1")) {
362         parseDisplayFont(tokens, displayFonts, displayFontT1, fileName, line);
363       } else if (!cmd->cmp("displayFontTT")) {
364         parseDisplayFont(tokens, displayFonts, displayFontTT, fileName, line);
365       } else if (!cmd->cmp("displayNamedCIDFontX")) {
366         parseDisplayFont(tokens, displayNamedCIDFonts,
367                          displayFontX, fileName, line);
368       } else if (!cmd->cmp("displayCIDFontX")) {
369         parseDisplayFont(tokens, displayCIDFonts,
370                          displayFontX, fileName, line);
371       } else if (!cmd->cmp("displayNamedCIDFontT1")) {
372         parseDisplayFont(tokens, displayNamedCIDFonts,
373                          displayFontT1, fileName, line);
374       } else if (!cmd->cmp("displayCIDFontT1")) {
375         parseDisplayFont(tokens, displayCIDFonts,
376                          displayFontT1, fileName, line);
377       } else if (!cmd->cmp("displayNamedCIDFontTT")) {
378         parseDisplayFont(tokens, displayNamedCIDFonts,
379                          displayFontTT, fileName, line);
380       } else if (!cmd->cmp("displayCIDFontTT")) {
381         parseDisplayFont(tokens, displayCIDFonts,
382                          displayFontTT, fileName, line);
383       } else if (!cmd->cmp("psFile")) {
384         parsePSFile(tokens, fileName, line);
385       } else if (!cmd->cmp("psFont")) {
386         parsePSFont(tokens, fileName, line);
387       } else if (!cmd->cmp("psNamedFont16")) {
388         parsePSFont16("psNamedFont16", psNamedFonts16,
389                       tokens, fileName, line);
390       } else if (!cmd->cmp("psFont16")) {
391         parsePSFont16("psFont16", psFonts16, tokens, fileName, line);
392       } else if (!cmd->cmp("psPaperSize")) {
393         parsePSPaperSize(tokens, fileName, line);
394       } else if (!cmd->cmp("psDuplex")) {
395         parseYesNo("psDuplex", &psDuplex, tokens, fileName, line);
396       } else if (!cmd->cmp("psLevel")) {
397         parsePSLevel(tokens, fileName, line);
398       } else if (!cmd->cmp("psEmbedType1Fonts")) {
399         parseYesNo("psEmbedType1", &psEmbedType1, tokens, fileName, line);
400       } else if (!cmd->cmp("psEmbedTrueTypeFonts")) {
401         parseYesNo("psEmbedTrueType", &psEmbedTrueType,
402                    tokens, fileName, line);
403       } else if (!cmd->cmp("psEmbedCIDPostScriptFonts")) {
404         parseYesNo("psEmbedCIDPostScript", &psEmbedCIDPostScript,
405                    tokens, fileName, line);
406       } else if (!cmd->cmp("psEmbedCIDTrueTypeFonts")) {
407         parseYesNo("psEmbedCIDTrueType", &psEmbedCIDTrueType,
408                    tokens, fileName, line);
409       } else if (!cmd->cmp("psOPI")) {
410         parseYesNo("psOPI", &psOPI, tokens, fileName, line);
411       } else if (!cmd->cmp("psASCIIHex")) {
412         parseYesNo("psASCIIHex", &psASCIIHex, tokens, fileName, line);
413       } else if (!cmd->cmp("textEncoding")) {
414         parseTextEncoding(tokens, fileName, line);
415       } else if (!cmd->cmp("textEOL")) {
416         parseTextEOL(tokens, fileName, line);
417       } else if (!cmd->cmp("textPageBreaks")) {
418         parseYesNo("textPageBreaks", &textPageBreaks,
419                    tokens, fileName, line);
420       } else if (!cmd->cmp("textKeepTinyChars")) {
421         parseYesNo("textKeepTinyChars", &textKeepTinyChars,
422                    tokens, fileName, line);
423       } else if (!cmd->cmp("fontDir")) {
424         parseFontDir(tokens, fileName, line);
425       } else if (!cmd->cmp("initialZoom")) {
426         parseInitialZoom(tokens, fileName, line);
427       } else if (!cmd->cmp("t1libControl")) {
428         parseFontRastControl("t1libControl", &t1libControl,
429                              tokens, fileName, line);
430       } else if (!cmd->cmp("freetypeControl")) {
431         parseFontRastControl("freetypeControl", &freetypeControl,
432                              tokens, fileName, line);
433       } else if (!cmd->cmp("urlCommand")) {
434         parseCommand("urlCommand", &urlCommand, tokens, fileName, line);
435       } else if (!cmd->cmp("movieCommand")) {
436         parseCommand("movieCommand", &movieCommand, tokens, fileName, line);
437       } else if (!cmd->cmp("mapNumericCharNames")) {
438         parseYesNo("mapNumericCharNames", &mapNumericCharNames,
439                    tokens, fileName, line);
440       } else if (!cmd->cmp("printCommands")) {
441         parseYesNo("printCommands", &printCommands, tokens, fileName, line);
442       } else if (!cmd->cmp("errQuiet")) {
443         parseYesNo("errQuiet", &errQuiet, tokens, fileName, line);
444       } else if (!cmd->cmp("fontpath") || !cmd->cmp("fontmap")) {
445         error(-1, "Unknown config file command");
446         error(-1, "-- the config file format has changed since Xpdf 0.9x");
447       } else {
448         error(-1, "Unknown config file command '%s' (%s:%d)",
449               cmd->getCString(), fileName->getCString(), line);
450       }
451     }
452
453     deleteGList(tokens, GString);
454     ++line;
455   }
456 }
457
458 void GlobalParams::parseNameToUnicode(GList *tokens, GString *fileName,
459                                          int line) {
460   GString *name;
461   char *tok1, *tok2;
462   FILE *f;
463   char buf[256];
464   int line2;
465   Unicode u;
466
467   if (tokens->getLength() != 2) {
468     error(-1, "Bad 'nameToUnicode' config file command (%s:%d)",
469           fileName->getCString(), line);
470     return;
471   }
472   name = (GString *)tokens->get(1);
473   if (!(f = fopen(name->getCString(), "r"))) {
474     error(-1, "Couldn't open 'nameToUnicode' file '%s'",
475           name->getCString());
476     return;
477   }
478   line2 = 1;
479   while (getLine(buf, sizeof(buf), f)) {
480     tok1 = strtok(buf, " \t\r\n");
481     tok2 = strtok(NULL, " \t\r\n");
482     if (tok1 && tok2) {
483       sscanf(tok1, "%x", &u);
484       nameToUnicode->add(tok2, u);
485     } else {
486       error(-1, "Bad line in 'nameToUnicode' file (%s:%d)", name, line2);
487     }
488     ++line2;
489   }
490   fclose(f);
491 }
492
493 void GlobalParams::parseCIDToUnicode(GList *tokens, GString *fileName,
494                                      int line) {
495   GString *collection, *name, *old;
496
497   if (tokens->getLength() != 3) {
498     error(-1, "Bad 'cidToUnicode' config file command (%s:%d)",
499           fileName->getCString(), line);
500     return;
501   }
502   collection = (GString *)tokens->get(1);
503   name = (GString *)tokens->get(2);
504   if ((old = (GString *)cidToUnicodes->remove(collection))) {
505     delete old;
506   }
507   cidToUnicodes->add(collection->copy(), name->copy());
508 }
509
510 void GlobalParams::parseUnicodeToUnicode(GList *tokens, GString *fileName,
511                                          int line) {
512   GString *font, *file, *old;
513
514   if (tokens->getLength() != 3) {
515     error(-1, "Bad 'unicodeToUnicode' config file command (%s:%d)",
516           fileName->getCString(), line);
517     return;
518   }
519   font = (GString *)tokens->get(1);
520   file = (GString *)tokens->get(2);
521   if ((old = (GString *)unicodeToUnicodes->remove(font))) {
522     delete old;
523   }
524   unicodeToUnicodes->add(font->copy(), file->copy());
525 }
526
527 void GlobalParams::parseUnicodeMap(GList *tokens, GString *fileName,
528                                    int line) {
529   GString *encodingName, *name, *old;
530
531   if (tokens->getLength() != 3) {
532     error(-1, "Bad 'unicodeMap' config file command (%s:%d)",
533           fileName->getCString(), line);
534     return;
535   }
536   encodingName = (GString *)tokens->get(1);
537   name = (GString *)tokens->get(2);
538   if ((old = (GString *)unicodeMaps->remove(encodingName))) {
539     delete old;
540   }
541   unicodeMaps->add(encodingName->copy(), name->copy());
542 }
543
544 void GlobalParams::parseCMapDir(GList *tokens, GString *fileName, int line) {
545   GString *collection, *dir;
546   GList *list;
547
548   if (tokens->getLength() != 3) {
549     error(-1, "Bad 'cMapDir' config file command (%s:%d)",
550           fileName->getCString(), line);
551     return;
552   }
553   collection = (GString *)tokens->get(1);
554   dir = (GString *)tokens->get(2);
555   if (!(list = (GList *)cMapDirs->lookup(collection))) {
556     list = new GList();
557     cMapDirs->add(collection->copy(), list);
558   }
559   list->append(dir->copy());
560 }
561
562 void GlobalParams::parseToUnicodeDir(GList *tokens, GString *fileName,
563                                      int line) {
564   if (tokens->getLength() != 2) {
565     error(-1, "Bad 'toUnicodeDir' config file command (%s:%d)",
566           fileName->getCString(), line);
567     return;
568   }
569   toUnicodeDirs->append(((GString *)tokens->get(1))->copy());
570 }
571
572 void GlobalParams::parseDisplayFont(GList *tokens, GHash *fontHash,
573                                     DisplayFontParamKind kind,
574                                     GString *fileName, int line) {
575   DisplayFontParam *param, *old;
576
577   if (tokens->getLength() < 2) {
578     goto err1;
579   }
580   param = new DisplayFontParam(((GString *)tokens->get(1))->copy(), kind);
581   
582   switch (kind) {
583   case displayFontX:
584     if (tokens->getLength() != 4) {
585       goto err2;
586     }
587     param->x.xlfd = ((GString *)tokens->get(2))->copy();
588     param->x.encoding = ((GString *)tokens->get(3))->copy();
589     break;
590   case displayFontT1:
591     if (tokens->getLength() != 3) {
592       goto err2;
593     }
594     param->t1.fileName = ((GString *)tokens->get(2))->copy();
595     break;
596   case displayFontTT:
597     if (tokens->getLength() != 3) {
598       goto err2;
599     }
600     param->tt.fileName = ((GString *)tokens->get(2))->copy();
601     break;
602   }
603
604   if ((old = (DisplayFontParam *)fontHash->remove(param->name))) {
605     delete old;
606   }
607   fontHash->add(param->name, param);
608   return;
609
610  err2:
611   delete param;
612  err1:
613   error(-1, "Bad 'display*Font*' config file command (%s:%d)",
614         fileName->getCString(), line);
615 }
616
617 void GlobalParams::parsePSPaperSize(GList *tokens, GString *fileName,
618                                     int line) {
619   GString *tok;
620
621   if (tokens->getLength() == 2) {
622     tok = (GString *)tokens->get(1);
623     if (!setPSPaperSize(tok->getCString())) {
624       error(-1, "Bad 'psPaperSize' config file command (%s:%d)",
625             fileName->getCString(), line);
626     }
627   } else if (tokens->getLength() == 3) {
628     tok = (GString *)tokens->get(1);
629     psPaperWidth = atoi(tok->getCString());
630     tok = (GString *)tokens->get(2);
631     psPaperHeight = atoi(tok->getCString());
632   } else {
633     error(-1, "Bad 'psPaperSize' config file command (%s:%d)",
634           fileName->getCString(), line);
635   }
636 }
637
638 void GlobalParams::parsePSLevel(GList *tokens, GString *fileName, int line) {
639   GString *tok;
640
641   if (tokens->getLength() != 2) {
642     error(-1, "Bad 'psLevel' config file command (%s:%d)",
643           fileName->getCString(), line);
644     return;
645   }
646   tok = (GString *)tokens->get(1);
647   if (!tok->cmp("level1")) {
648     psLevel = psLevel1;
649   } else if (!tok->cmp("level1sep")) {
650     psLevel = psLevel1Sep;
651   } else if (!tok->cmp("level2")) {
652     psLevel = psLevel2;
653   } else if (!tok->cmp("level2sep")) {
654     psLevel = psLevel2Sep;
655   } else if (!tok->cmp("level3")) {
656     psLevel = psLevel3;
657   } else if (!tok->cmp("level3Sep")) {
658     psLevel = psLevel3Sep;
659   } else {
660     error(-1, "Bad 'psLevel' config file command (%s:%d)",
661           fileName->getCString(), line);
662   }
663 }
664
665 void GlobalParams::parsePSFile(GList *tokens, GString *fileName, int line) {
666   if (tokens->getLength() != 2) {
667     error(-1, "Bad 'psFile' config file command (%s:%d)",
668           fileName->getCString(), line);
669     return;
670   }
671   if (psFile) {
672     delete psFile;
673   }
674   psFile = ((GString *)tokens->get(1))->copy();
675 }
676
677 void GlobalParams::parsePSFont(GList *tokens, GString *fileName, int line) {
678   PSFontParam *param;
679
680   if (tokens->getLength() != 3) {
681     error(-1, "Bad 'psFont' config file command (%s:%d)",
682           fileName->getCString(), line);
683     return;
684   }
685   param = new PSFontParam(((GString *)tokens->get(1))->copy(), 0,
686                           ((GString *)tokens->get(2))->copy(), NULL);
687   psFonts->add(param->pdfFontName, param);
688 }
689
690 void GlobalParams::parsePSFont16(char *cmdName, GList *fontList,
691                                  GList *tokens, GString *fileName, int line) {
692   PSFontParam *param;
693   int wMode;
694   GString *tok;
695
696   if (tokens->getLength() != 5) {
697     error(-1, "Bad '%s' config file command (%s:%d)",
698           cmdName, fileName->getCString(), line);
699     return;
700   }
701   tok = (GString *)tokens->get(2);
702   if (!tok->cmp("H")) {
703     wMode = 0;
704   } else if (!tok->cmp("V")) {
705     wMode = 1;
706   } else {
707     error(-1, "Bad '%s' config file command (%s:%d)",
708           cmdName, fileName->getCString(), line);
709     return;
710   }
711   param = new PSFontParam(((GString *)tokens->get(1))->copy(),
712                           wMode,
713                           ((GString *)tokens->get(3))->copy(),
714                           ((GString *)tokens->get(4))->copy());
715   fontList->append(param);
716 }
717
718 void GlobalParams::parseTextEncoding(GList *tokens, GString *fileName,
719                                      int line) {
720   if (tokens->getLength() != 2) {
721     error(-1, "Bad 'textEncoding' config file command (%s:%d)",
722           fileName->getCString(), line);
723     return;
724   }
725   delete textEncoding;
726   textEncoding = ((GString *)tokens->get(1))->copy();
727 }
728
729 void GlobalParams::parseTextEOL(GList *tokens, GString *fileName, int line) {
730   GString *tok;
731
732   if (tokens->getLength() != 2) {
733     error(-1, "Bad 'textEOL' config file command (%s:%d)",
734           fileName->getCString(), line);
735     return;
736   }
737   tok = (GString *)tokens->get(1);
738   if (!tok->cmp("unix")) {
739     textEOL = eolUnix;
740   } else if (!tok->cmp("dos")) {
741     textEOL = eolDOS;
742   } else if (!tok->cmp("mac")) {
743     textEOL = eolMac;
744   } else {
745     error(-1, "Bad 'textEOL' config file command (%s:%d)",
746           fileName->getCString(), line);
747   }
748 }
749
750 void GlobalParams::parseFontDir(GList *tokens, GString *fileName, int line) {
751   if (tokens->getLength() != 2) {
752     error(-1, "Bad 'fontDir' config file command (%s:%d)",
753           fileName->getCString(), line);
754     return;
755   }
756   fontDirs->append(((GString *)tokens->get(1))->copy());
757 }
758
759 void GlobalParams::parseInitialZoom(GList *tokens,
760                                     GString *fileName, int line) {
761   if (tokens->getLength() != 2) {
762     error(-1, "Bad 'initialZoom' config file command (%s:%d)",
763           fileName->getCString(), line);
764     return;
765   }
766   delete initialZoom;
767   initialZoom = ((GString *)tokens->get(1))->copy();
768 }
769
770 void GlobalParams::parseFontRastControl(char *cmdName, FontRastControl *val,
771                                         GList *tokens, GString *fileName,
772                                         int line) {
773   GString *tok;
774
775   if (tokens->getLength() != 2) {
776     error(-1, "Bad '%s' config file command (%s:%d)",
777           cmdName, fileName->getCString(), line);
778     return;
779   }
780   tok = (GString *)tokens->get(1);
781   if (!setFontRastControl(val, tok->getCString())) {
782     error(-1, "Bad '%s' config file command (%s:%d)",
783           cmdName, fileName->getCString(), line);
784   }
785 }
786
787 void GlobalParams::parseCommand(char *cmdName, GString **val,
788                                 GList *tokens, GString *fileName, int line) {
789   if (tokens->getLength() != 2) {
790     error(-1, "Bad '%s' config file command (%s:%d)",
791           cmdName, fileName->getCString(), line);
792     return;
793   }
794   if (*val) {
795     delete *val;
796   }
797   *val = ((GString *)tokens->get(1))->copy();
798 }
799
800 void GlobalParams::parseYesNo(char *cmdName, GBool *flag,
801                               GList *tokens, GString *fileName, int line) {
802   GString *tok;
803
804   if (tokens->getLength() != 2) {
805     error(-1, "Bad '%s' config file command (%s:%d)",
806           cmdName, fileName->getCString(), line);
807     return;
808   }
809   tok = (GString *)tokens->get(1);
810   if (!tok->cmp("yes")) {
811     *flag = gTrue;
812   } else if (!tok->cmp("no")) {
813     *flag = gFalse;
814   } else {
815     error(-1, "Bad '%s' config file command (%s:%d)",
816           cmdName, fileName->getCString(), line);
817   }
818 }
819
820 GlobalParams::~GlobalParams() {
821   GHashIter *iter;
822   GString *key;
823   GList *list;
824
825   freeBuiltinFontTables();
826
827   delete macRomanReverseMap;
828
829   delete nameToUnicode;
830   deleteGHash(cidToUnicodes, GString);
831   deleteGHash(unicodeToUnicodes, GString);
832   deleteGHash(residentUnicodeMaps, UnicodeMap);
833   deleteGHash(unicodeMaps, GString);
834   deleteGList(toUnicodeDirs, GString);
835   deleteGHash(displayFonts, DisplayFontParam);
836   deleteGHash(displayCIDFonts, DisplayFontParam);
837   deleteGHash(displayNamedCIDFonts, DisplayFontParam);
838   if (psFile) {
839     delete psFile;
840   }
841   deleteGHash(psFonts, PSFontParam);
842   deleteGList(psNamedFonts16, PSFontParam);
843   deleteGList(psFonts16, PSFontParam);
844   delete textEncoding;
845   deleteGList(fontDirs, GString);
846   delete initialZoom;
847   if (urlCommand) {
848     delete urlCommand;
849   }
850   if (movieCommand) {
851     delete movieCommand;
852   }
853
854   cMapDirs->startIter(&iter);
855   while (cMapDirs->getNext(&iter, &key, (void **)&list)) {
856     deleteGList(list, GString);
857   }
858   delete cMapDirs;
859
860   delete cidToUnicodeCache;
861   delete unicodeToUnicodeCache;
862   delete unicodeMapCache;
863   delete cMapCache;
864
865 #if MULTITHREADED
866   gDestroyMutex(&mutex);
867   gDestroyMutex(&unicodeMapCacheMutex);
868   gDestroyMutex(&cMapCacheMutex);
869 #endif
870 }
871
872 //------------------------------------------------------------------------
873 // accessors
874 //------------------------------------------------------------------------
875
876 CharCode GlobalParams::getMacRomanCharCode(char *charName) {
877   // no need to lock - macRomanReverseMap is constant
878   return macRomanReverseMap->lookup(charName);
879 }
880
881 Unicode GlobalParams::mapNameToUnicode(char *charName) {
882   // no need to lock - nameToUnicode is constant
883   return nameToUnicode->lookup(charName);
884 }
885
886 UnicodeMap *GlobalParams::getResidentUnicodeMap(GString *encodingName) {
887   UnicodeMap *map;
888
889   lockGlobalParams;
890   map = (UnicodeMap *)residentUnicodeMaps->lookup(encodingName);
891   unlockGlobalParams;
892   if (map) {
893     map->incRefCnt();
894   }
895   return map;
896 }
897
898 FILE *GlobalParams::getUnicodeMapFile(GString *encodingName) {
899   GString *fileName;
900   FILE *f;
901
902   lockGlobalParams;
903   if ((fileName = (GString *)unicodeMaps->lookup(encodingName))) {
904     f = fopen(fileName->getCString(), "r");
905   } else {
906     f = NULL;
907   }
908   unlockGlobalParams;
909   return f;
910 }
911
912 FILE *GlobalParams::findCMapFile(GString *collection, GString *cMapName) {
913   GList *list;
914   GString *dir;
915   GString *fileName;
916   FILE *f;
917   int i;
918
919   lockGlobalParams;
920   if (!(list = (GList *)cMapDirs->lookup(collection))) {
921     unlockGlobalParams;
922     return NULL;
923   }
924   for (i = 0; i < list->getLength(); ++i) {
925     dir = (GString *)list->get(i);
926     fileName = appendToPath(dir->copy(), cMapName->getCString());
927     f = fopen(fileName->getCString(), "r");
928     delete fileName;
929     if (f) {
930       unlockGlobalParams;
931       return f;
932     }
933   }
934   unlockGlobalParams;
935   return NULL;
936 }
937
938 FILE *GlobalParams::findToUnicodeFile(GString *name) {
939   GString *dir, *fileName;
940   FILE *f;
941   int i;
942
943   lockGlobalParams;
944   for (i = 0; i < toUnicodeDirs->getLength(); ++i) {
945     dir = (GString *)toUnicodeDirs->get(i);
946     fileName = appendToPath(dir->copy(), name->getCString());
947     f = fopen(fileName->getCString(), "r");
948     delete fileName;
949     if (f) {
950       unlockGlobalParams;
951       return f;
952     }
953   }
954   unlockGlobalParams;
955   return NULL;
956 }
957
958 DisplayFontParam *GlobalParams::getDisplayFont(GString *fontName) {
959   DisplayFontParam *dfp;
960
961   lockGlobalParams;
962   dfp = (DisplayFontParam *)displayFonts->lookup(fontName);
963   unlockGlobalParams;
964   return dfp;
965 }
966
967 DisplayFontParam *GlobalParams::getDisplayCIDFont(GString *fontName,
968                                                   GString *collection) {
969   DisplayFontParam *dfp;
970
971   lockGlobalParams;
972   if (!fontName ||
973       !(dfp = (DisplayFontParam *)displayNamedCIDFonts->lookup(fontName))) {
974     dfp = (DisplayFontParam *)displayCIDFonts->lookup(collection);
975   }
976   unlockGlobalParams;
977   return dfp;
978 }
979
980 GString *GlobalParams::getPSFile() {
981   GString *s;
982
983   lockGlobalParams;
984   s = psFile ? psFile->copy() : (GString *)NULL;
985   unlockGlobalParams;
986   return s;
987 }
988
989 int GlobalParams::getPSPaperWidth() {
990   int w;
991
992   lockGlobalParams;
993   w = psPaperWidth;
994   unlockGlobalParams;
995   return w;
996 }
997
998 int GlobalParams::getPSPaperHeight() {
999   int h;
1000
1001   lockGlobalParams;
1002   h = psPaperHeight;
1003   unlockGlobalParams;
1004   return h;
1005 }
1006
1007 GBool GlobalParams::getPSDuplex() {
1008   GBool d;
1009
1010   lockGlobalParams;
1011   d = psDuplex;
1012   unlockGlobalParams;
1013   return d;
1014 }
1015
1016 PSLevel GlobalParams::getPSLevel() {
1017   PSLevel level;
1018
1019   lockGlobalParams;
1020   level = psLevel;
1021   unlockGlobalParams;
1022   return level;
1023 }
1024
1025 PSFontParam *GlobalParams::getPSFont(GString *fontName) {
1026   PSFontParam *p;
1027
1028   lockGlobalParams;
1029   p = (PSFontParam *)psFonts->lookup(fontName);
1030   unlockGlobalParams;
1031   return p;
1032 }
1033
1034 PSFontParam *GlobalParams::getPSFont16(GString *fontName,
1035                                        GString *collection, int wMode) {
1036   PSFontParam *p;
1037   int i;
1038
1039   lockGlobalParams;
1040   p = NULL;
1041   if (fontName) {
1042     for (i = 0; i < psNamedFonts16->getLength(); ++i) {
1043       p = (PSFontParam *)psNamedFonts16->get(i);
1044       if (!p->pdfFontName->cmp(fontName) &&
1045           p->wMode == wMode) {
1046         break;
1047       }
1048       p = NULL;
1049     }
1050   }
1051   if (!p && collection) {
1052     for (i = 0; i < psFonts16->getLength(); ++i) {
1053       p = (PSFontParam *)psFonts16->get(i);
1054       if (!p->pdfFontName->cmp(collection) &&
1055           p->wMode == wMode) {
1056         break;
1057       }
1058       p = NULL;
1059     }
1060   }
1061   unlockGlobalParams;
1062   return p;
1063 }
1064
1065 GBool GlobalParams::getPSEmbedType1() {
1066   GBool e;
1067
1068   lockGlobalParams;
1069   e = psEmbedType1;
1070   unlockGlobalParams;
1071   return e;
1072 }
1073
1074 GBool GlobalParams::getPSEmbedTrueType() {
1075   GBool e;
1076
1077   lockGlobalParams;
1078   e = psEmbedTrueType;
1079   unlockGlobalParams;
1080   return e;
1081 }
1082
1083 GBool GlobalParams::getPSEmbedCIDPostScript() {
1084   GBool e;
1085
1086   lockGlobalParams;
1087   e = psEmbedCIDPostScript;
1088   unlockGlobalParams;
1089   return e;
1090 }
1091
1092 GBool GlobalParams::getPSEmbedCIDTrueType() {
1093   GBool e;
1094
1095   lockGlobalParams;
1096   e = psEmbedCIDTrueType;
1097   unlockGlobalParams;
1098   return e;
1099 }
1100
1101 GBool GlobalParams::getPSOPI() {
1102   GBool opi;
1103
1104   lockGlobalParams;
1105   opi = psOPI;
1106   unlockGlobalParams;
1107   return opi;
1108 }
1109
1110 GBool GlobalParams::getPSASCIIHex() {
1111   GBool ah;
1112
1113   lockGlobalParams;
1114   ah = psASCIIHex;
1115   unlockGlobalParams;
1116   return ah;
1117 }
1118
1119 GString *GlobalParams::getTextEncodingName() {
1120   GString *s;
1121
1122   lockGlobalParams;
1123   s = textEncoding->copy();
1124   unlockGlobalParams;
1125   return s;
1126 }
1127
1128 EndOfLineKind GlobalParams::getTextEOL() {
1129   EndOfLineKind eol;
1130
1131   lockGlobalParams;
1132   eol = textEOL;
1133   unlockGlobalParams;
1134   return eol;
1135 }
1136
1137 GBool GlobalParams::getTextPageBreaks() {
1138   GBool pageBreaks;
1139
1140   lockGlobalParams;
1141   pageBreaks = textPageBreaks;
1142   unlockGlobalParams;
1143   return pageBreaks;
1144 }
1145
1146 GBool GlobalParams::getTextKeepTinyChars() {
1147   GBool tiny;
1148
1149   lockGlobalParams;
1150   tiny = textKeepTinyChars;
1151   unlockGlobalParams;
1152   return tiny;
1153 }
1154
1155 GString *GlobalParams::findFontFile(GString *fontName, char **exts) {
1156   GString *dir, *fileName;
1157   char **ext;
1158   FILE *f;
1159   int i;
1160
1161   lockGlobalParams;
1162   for (i = 0; i < fontDirs->getLength(); ++i) {
1163     dir = (GString *)fontDirs->get(i);
1164     for (ext = exts; *ext; ++ext) {
1165       fileName = appendToPath(dir->copy(), fontName->getCString());
1166       fileName->append(*ext);
1167       if ((f = fopen(fileName->getCString(), "rb"))) {
1168         fclose(f);
1169         unlockGlobalParams;
1170         return fileName;
1171       }
1172       delete fileName;
1173     }
1174   }
1175   unlockGlobalParams;
1176   return NULL;
1177 }
1178
1179 GString *GlobalParams::getInitialZoom() {
1180   GString *s;
1181
1182   lockGlobalParams;
1183   s = initialZoom->copy();
1184   unlockGlobalParams;
1185   return s;
1186 }
1187
1188 FontRastControl GlobalParams::getT1libControl() {
1189   FontRastControl c;
1190
1191   lockGlobalParams;
1192   c = t1libControl;
1193   unlockGlobalParams;
1194   return c;
1195 }
1196
1197 FontRastControl GlobalParams::getFreeTypeControl() {
1198   FontRastControl c;
1199
1200   lockGlobalParams;
1201   c = freetypeControl;
1202   unlockGlobalParams;
1203   return c;
1204 }
1205
1206 GBool GlobalParams::getMapNumericCharNames() {
1207   GBool map;
1208
1209   lockGlobalParams;
1210   map = mapNumericCharNames;
1211   unlockGlobalParams;
1212   return map;
1213 }
1214
1215 GBool GlobalParams::getPrintCommands() {
1216   GBool p;
1217
1218   lockGlobalParams;
1219   p = printCommands;
1220   unlockGlobalParams;
1221   return p;
1222 }
1223
1224 GBool GlobalParams::getErrQuiet() {
1225   GBool q;
1226
1227   lockGlobalParams;
1228   q = errQuiet;
1229   unlockGlobalParams;
1230   return q;
1231 }
1232
1233 CharCodeToUnicode *GlobalParams::getCIDToUnicode(GString *collection) {
1234   GString *fileName;
1235   CharCodeToUnicode *ctu;
1236
1237   lockGlobalParams;
1238   if (!(ctu = cidToUnicodeCache->getCharCodeToUnicode(collection))) {
1239     if ((fileName = (GString *)cidToUnicodes->lookup(collection)) &&
1240         (ctu = CharCodeToUnicode::parseCIDToUnicode(fileName, collection))) {
1241       cidToUnicodeCache->add(ctu);
1242     }
1243   }
1244   unlockGlobalParams;
1245   return ctu;
1246 }
1247
1248 CharCodeToUnicode *GlobalParams::getUnicodeToUnicode(GString *fontName) {
1249   CharCodeToUnicode *ctu;
1250   GHashIter *iter;
1251   GString *fontPattern, *fileName;
1252
1253   lockGlobalParams;
1254   fileName = NULL;
1255   unicodeToUnicodes->startIter(&iter);
1256   while (unicodeToUnicodes->getNext(&iter, &fontPattern, (void **)&fileName)) {
1257     if (strstr(fontName->getCString(), fontPattern->getCString())) {
1258       unicodeToUnicodes->killIter(&iter);
1259       break;
1260     }
1261     fileName = NULL;
1262   }
1263   if (fileName) {
1264     if (!(ctu = unicodeToUnicodeCache->getCharCodeToUnicode(fileName))) {
1265       if ((ctu = CharCodeToUnicode::parseUnicodeToUnicode(fileName))) {
1266         unicodeToUnicodeCache->add(ctu);
1267       }
1268     }
1269   } else {
1270     ctu = NULL;
1271   }
1272   unlockGlobalParams;
1273   return ctu;
1274 }
1275
1276 UnicodeMap *GlobalParams::getUnicodeMap(GString *encodingName) {
1277   return getUnicodeMap2(encodingName);
1278 }
1279
1280 UnicodeMap *GlobalParams::getUnicodeMap2(GString *encodingName) {
1281   UnicodeMap *map;
1282
1283   if (!(map = getResidentUnicodeMap(encodingName))) {
1284     lockUnicodeMapCache;
1285     map = unicodeMapCache->getUnicodeMap(encodingName);
1286     unlockUnicodeMapCache;
1287   }
1288   return map;
1289 }
1290
1291 CMap *GlobalParams::getCMap(GString *collection, GString *cMapName) {
1292   CMap *cMap;
1293
1294   lockCMapCache;
1295   cMap = cMapCache->getCMap(collection, cMapName);
1296   unlockCMapCache;
1297   return cMap;
1298 }
1299
1300 UnicodeMap *GlobalParams::getTextEncoding() {
1301   return getUnicodeMap2(textEncoding);
1302 }
1303
1304 //------------------------------------------------------------------------
1305 // functions to set parameters
1306 //------------------------------------------------------------------------
1307
1308 void GlobalParams::addDisplayFont(DisplayFontParam *param) {
1309   DisplayFontParam *old;
1310
1311   lockGlobalParams;
1312   if ((old = (DisplayFontParam *)displayFonts->remove(param->name))) {
1313     delete old;
1314   }
1315   displayFonts->add(param->name, param);
1316   unlockGlobalParams;
1317 }
1318
1319 void GlobalParams::setPSFile(char *file) {
1320   lockGlobalParams;
1321   if (psFile) {
1322     delete psFile;
1323   }
1324   psFile = new GString(file);
1325   unlockGlobalParams;
1326 }
1327
1328 GBool GlobalParams::setPSPaperSize(char *size) {
1329   lockGlobalParams;
1330   if (!strcmp(size, "match")) {
1331     psPaperWidth = psPaperHeight = -1;
1332   } else if (!strcmp(size, "letter")) {
1333     psPaperWidth = 612;
1334     psPaperHeight = 792;
1335   } else if (!strcmp(size, "legal")) {
1336     psPaperWidth = 612;
1337     psPaperHeight = 1008;
1338   } else if (!strcmp(size, "A4")) {
1339     psPaperWidth = 595;
1340     psPaperHeight = 842;
1341   } else if (!strcmp(size, "A3")) {
1342     psPaperWidth = 842;
1343     psPaperHeight = 1190;
1344   } else {
1345     unlockGlobalParams;
1346     return gFalse;
1347   }
1348   unlockGlobalParams;
1349   return gTrue;
1350 }
1351
1352 void GlobalParams::setPSPaperWidth(int width) {
1353   lockGlobalParams;
1354   psPaperWidth = width;
1355   unlockGlobalParams;
1356 }
1357
1358 void GlobalParams::setPSPaperHeight(int height) {
1359   lockGlobalParams;
1360   psPaperHeight = height;
1361   unlockGlobalParams;
1362 }
1363
1364 void GlobalParams::setPSDuplex(GBool duplex) {
1365   lockGlobalParams;
1366   psDuplex = duplex;
1367   unlockGlobalParams;
1368 }
1369
1370 void GlobalParams::setPSLevel(PSLevel level) {
1371   lockGlobalParams;
1372   psLevel = level;
1373   unlockGlobalParams;
1374 }
1375
1376 void GlobalParams::setPSEmbedType1(GBool embed) {
1377   lockGlobalParams;
1378   psEmbedType1 = embed;
1379   unlockGlobalParams;
1380 }
1381
1382 void GlobalParams::setPSEmbedTrueType(GBool embed) {
1383   lockGlobalParams;
1384   psEmbedTrueType = embed;
1385   unlockGlobalParams;
1386 }
1387
1388 void GlobalParams::setPSEmbedCIDPostScript(GBool embed) {
1389   lockGlobalParams;
1390   psEmbedCIDPostScript = embed;
1391   unlockGlobalParams;
1392 }
1393
1394 void GlobalParams::setPSEmbedCIDTrueType(GBool embed) {
1395   lockGlobalParams;
1396   psEmbedCIDTrueType = embed;
1397   unlockGlobalParams;
1398 }
1399
1400 void GlobalParams::setPSOPI(GBool opi) {
1401   lockGlobalParams;
1402   psOPI = opi;
1403   unlockGlobalParams;
1404 }
1405
1406 void GlobalParams::setPSASCIIHex(GBool hex) {
1407   lockGlobalParams;
1408   psASCIIHex = hex;
1409   unlockGlobalParams;
1410 }
1411
1412 void GlobalParams::setTextEncoding(char *encodingName) {
1413   lockGlobalParams;
1414   delete textEncoding;
1415   textEncoding = new GString(encodingName);
1416   unlockGlobalParams;
1417 }
1418
1419 GBool GlobalParams::setTextEOL(char *s) {
1420   lockGlobalParams;
1421   if (!strcmp(s, "unix")) {
1422     textEOL = eolUnix;
1423   } else if (!strcmp(s, "dos")) {
1424     textEOL = eolDOS;
1425   } else if (!strcmp(s, "mac")) {
1426     textEOL = eolMac;
1427   } else {
1428     unlockGlobalParams;
1429     return gFalse;
1430   }
1431   unlockGlobalParams;
1432   return gTrue;
1433 }
1434
1435 void GlobalParams::setTextPageBreaks(GBool pageBreaks) {
1436   lockGlobalParams;
1437   textPageBreaks = pageBreaks;
1438   unlockGlobalParams;
1439 }
1440
1441 void GlobalParams::setTextKeepTinyChars(GBool keep) {
1442   lockGlobalParams;
1443   textKeepTinyChars = keep;
1444   unlockGlobalParams;
1445 }
1446
1447 void GlobalParams::setInitialZoom(char *s) {
1448   lockGlobalParams;
1449   delete initialZoom;
1450   initialZoom = new GString(s);
1451   unlockGlobalParams;
1452 }
1453
1454 GBool GlobalParams::setT1libControl(char *s) {
1455   GBool ok;
1456
1457   lockGlobalParams;
1458   ok = setFontRastControl(&t1libControl, s);
1459   unlockGlobalParams;
1460   return ok;
1461 }
1462
1463 GBool GlobalParams::setFreeTypeControl(char *s) {
1464   GBool ok;
1465
1466   lockGlobalParams;
1467   ok = setFontRastControl(&freetypeControl, s);
1468   unlockGlobalParams;
1469   return ok;
1470 }
1471
1472 GBool GlobalParams::setFontRastControl(FontRastControl *val, char *s) {
1473   lockGlobalParams;
1474   if (!strcmp(s, "none")) {
1475     *val = fontRastNone;
1476   } else if (!strcmp(s, "plain")) {
1477     *val = fontRastPlain;
1478   } else if (!strcmp(s, "low")) {
1479     *val = fontRastAALow;
1480   } else if (!strcmp(s, "high")) {
1481     *val = fontRastAAHigh;
1482   } else {
1483     unlockGlobalParams;
1484     return gFalse;
1485   }
1486   unlockGlobalParams;
1487   return gTrue;
1488 }
1489
1490 void GlobalParams::setMapNumericCharNames(GBool map) {
1491   lockGlobalParams;
1492   mapNumericCharNames = map;
1493   unlockGlobalParams;
1494 }
1495
1496 void GlobalParams::setPrintCommands(GBool printCommandsA) {
1497   lockGlobalParams;
1498   printCommands = printCommandsA;
1499   unlockGlobalParams;
1500 }
1501
1502 void GlobalParams::setErrQuiet(GBool errQuietA) {
1503   lockGlobalParams;
1504   errQuiet = errQuietA;
1505   unlockGlobalParams;
1506 }