1 //========================================================================
5 // Copyright 2001-2003 Glyph & Cog, LLC
7 //========================================================================
11 #ifdef USE_GCC_PRAGMAS
12 #pragma implementation
26 #include "NameToCharCode.h"
27 #include "CharCodeToUnicode.h"
28 #include "UnicodeMap.h"
30 #include "BuiltinFontTables.h"
31 #include "FontEncodingTables.h"
32 #include "GlobalParams.h"
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)
42 # define lockGlobalParams
43 # define lockUnicodeMapCache
44 # define lockCMapCache
45 # define unlockGlobalParams
46 # define unlockUnicodeMapCache
47 # define unlockCMapCache
50 #include "NameToUnicodeTable.h"
51 #include "UnicodeMapTables.h"
52 #include "DisplayFontTable.h"
55 //------------------------------------------------------------------------
57 #define cidToUnicodeCacheSize 4
58 #define unicodeToUnicodeCacheSize 4
60 //------------------------------------------------------------------------
62 GlobalParams *globalParams = NULL;
64 //------------------------------------------------------------------------
66 //------------------------------------------------------------------------
68 DisplayFontParam::DisplayFontParam(GString *nameA,
69 DisplayFontParamKind kindA) {
86 DisplayFontParam::DisplayFontParam(char *nameA, char *xlfdA, char *encodingA) {
87 name = new GString(nameA);
89 x.xlfd = new GString(xlfdA);
90 x.encoding = new GString(encodingA);
93 DisplayFontParam::~DisplayFontParam() {
117 //------------------------------------------------------------------------
119 //------------------------------------------------------------------------
121 PSFontParam::PSFontParam(GString *pdfFontNameA, int wModeA,
122 GString *psFontNameA, GString *encodingA) {
123 pdfFontName = pdfFontNameA;
125 psFontName = psFontNameA;
126 encoding = encodingA;
129 PSFontParam::~PSFontParam() {
137 //------------------------------------------------------------------------
139 //------------------------------------------------------------------------
141 GlobalParams::GlobalParams(char *cfgFileName) {
143 DisplayFontParam *dfp;
150 gInitMutex(&unicodeMapCacheMutex);
151 gInitMutex(&cMapCacheMutex);
154 initBuiltinFontTables();
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);
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();
177 const struct paper *paperType;
179 if ((paperName = systempapername())) {
180 paperType = paperinfo(paperName);
181 psPaperWidth = (int)paperpswidth(paperType);
182 psPaperHeight = (int)paperpsheight(paperType);
184 error(-1, "No paper information available - using defaults");
185 psPaperWidth = defPaperWidth;
186 psPaperHeight = defPaperHeight;
190 psPaperWidth = defPaperWidth;
191 psPaperHeight = defPaperHeight;
196 psFonts = new GHash();
197 psNamedFonts16 = new GList();
198 psFonts16 = new GList();
199 psEmbedType1 = gTrue;
200 psEmbedTrueType = gTrue;
201 psEmbedCIDPostScript = gTrue;
202 psEmbedCIDTrueType = gTrue;
205 textEncoding = new GString("Latin1");
213 textPageBreaks = gTrue;
214 textKeepTinyChars = gFalse;
215 fontDirs = new GList();
216 initialZoom = new GString("125");
217 t1libControl = fontRastAALow;
218 freetypeControl = fontRastAALow;
221 mapNumericCharNames = gTrue;
222 printCommands = gFalse;
225 cidToUnicodeCache = new CharCodeToUnicodeCache(cidToUnicodeCacheSize);
226 unicodeToUnicodeCache =
227 new CharCodeToUnicodeCache(unicodeToUnicodeCacheSize);
228 unicodeMapCache = new UnicodeMapCache();
229 cMapCache = new CMapCache();
231 // set up the initial nameToUnicode table
232 for (i = 0; nameToUnicodeTab[i].name; ++i) {
233 nameToUnicode->add(nameToUnicodeTab[i].name, nameToUnicodeTab[i].u);
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);
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);
262 // look for a user config file, then a system-wide config file
265 if (cfgFileName && cfgFileName[0]) {
266 fileName = new GString(cfgFileName);
267 if (!(f = fopen(fileName->getCString(), "r"))) {
272 fileName = appendToPath(getHomeDir(), xpdfUserConfigFile);
273 if (!(f = fopen(fileName->getCString(), "r"))) {
278 #if defined(WIN32) && !defined(__CYGWIN32__)
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
285 fileName = grabPath(buf);
286 appendToPath(fileName, xpdfSysConfigFile);
288 fileName = new GString(xpdfSysConfigFile);
290 if (!(f = fopen(fileName->getCString(), "r"))) {
295 parseFile(fileName, f);
301 void GlobalParams::parseFile(GString *fileName, FILE *f) {
304 GString *cmd, *incFile;
310 while (getLine(buf, sizeof(buf) - 1, f)) {
312 // break the line into tokens
313 tokens = new GList();
316 for (; *p1 && isspace(*p1); ++p1) ;
320 if (*p1 == '"' || *p1 == '\'') {
321 for (p2 = p1 + 1; *p2 && *p2 != *p1; ++p2) ;
324 for (p2 = p1 + 1; *p2 && !isspace(*p2); ++p2) ;
326 tokens->append(new GString(p1, p2 - p1));
327 p1 = *p2 ? p2 + 1 : p2;
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);
340 error(-1, "Couldn't find included config file: '%s' (%s:%d)",
341 incFile->getCString(), fileName->getCString(), line);
344 error(-1, "Bad 'include' config file command (%s:%d)",
345 fileName->getCString(), line);
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");
448 error(-1, "Unknown config file command '%s' (%s:%d)",
449 cmd->getCString(), fileName->getCString(), line);
453 deleteGList(tokens, GString);
458 void GlobalParams::parseNameToUnicode(GList *tokens, GString *fileName,
467 if (tokens->getLength() != 2) {
468 error(-1, "Bad 'nameToUnicode' config file command (%s:%d)",
469 fileName->getCString(), line);
472 name = (GString *)tokens->get(1);
473 if (!(f = fopen(name->getCString(), "r"))) {
474 error(-1, "Couldn't open 'nameToUnicode' file '%s'",
479 while (getLine(buf, sizeof(buf), f)) {
480 tok1 = strtok(buf, " \t\r\n");
481 tok2 = strtok(NULL, " \t\r\n");
483 sscanf(tok1, "%x", &u);
484 nameToUnicode->add(tok2, u);
486 error(-1, "Bad line in 'nameToUnicode' file (%s:%d)", name, line2);
493 void GlobalParams::parseCIDToUnicode(GList *tokens, GString *fileName,
495 GString *collection, *name, *old;
497 if (tokens->getLength() != 3) {
498 error(-1, "Bad 'cidToUnicode' config file command (%s:%d)",
499 fileName->getCString(), line);
502 collection = (GString *)tokens->get(1);
503 name = (GString *)tokens->get(2);
504 if ((old = (GString *)cidToUnicodes->remove(collection))) {
507 cidToUnicodes->add(collection->copy(), name->copy());
510 void GlobalParams::parseUnicodeToUnicode(GList *tokens, GString *fileName,
512 GString *font, *file, *old;
514 if (tokens->getLength() != 3) {
515 error(-1, "Bad 'unicodeToUnicode' config file command (%s:%d)",
516 fileName->getCString(), line);
519 font = (GString *)tokens->get(1);
520 file = (GString *)tokens->get(2);
521 if ((old = (GString *)unicodeToUnicodes->remove(font))) {
524 unicodeToUnicodes->add(font->copy(), file->copy());
527 void GlobalParams::parseUnicodeMap(GList *tokens, GString *fileName,
529 GString *encodingName, *name, *old;
531 if (tokens->getLength() != 3) {
532 error(-1, "Bad 'unicodeMap' config file command (%s:%d)",
533 fileName->getCString(), line);
536 encodingName = (GString *)tokens->get(1);
537 name = (GString *)tokens->get(2);
538 if ((old = (GString *)unicodeMaps->remove(encodingName))) {
541 unicodeMaps->add(encodingName->copy(), name->copy());
544 void GlobalParams::parseCMapDir(GList *tokens, GString *fileName, int line) {
545 GString *collection, *dir;
548 if (tokens->getLength() != 3) {
549 error(-1, "Bad 'cMapDir' config file command (%s:%d)",
550 fileName->getCString(), line);
553 collection = (GString *)tokens->get(1);
554 dir = (GString *)tokens->get(2);
555 if (!(list = (GList *)cMapDirs->lookup(collection))) {
557 cMapDirs->add(collection->copy(), list);
559 list->append(dir->copy());
562 void GlobalParams::parseToUnicodeDir(GList *tokens, GString *fileName,
564 if (tokens->getLength() != 2) {
565 error(-1, "Bad 'toUnicodeDir' config file command (%s:%d)",
566 fileName->getCString(), line);
569 toUnicodeDirs->append(((GString *)tokens->get(1))->copy());
572 void GlobalParams::parseDisplayFont(GList *tokens, GHash *fontHash,
573 DisplayFontParamKind kind,
574 GString *fileName, int line) {
575 DisplayFontParam *param, *old;
577 if (tokens->getLength() < 2) {
580 param = new DisplayFontParam(((GString *)tokens->get(1))->copy(), kind);
584 if (tokens->getLength() != 4) {
587 param->x.xlfd = ((GString *)tokens->get(2))->copy();
588 param->x.encoding = ((GString *)tokens->get(3))->copy();
591 if (tokens->getLength() != 3) {
594 param->t1.fileName = ((GString *)tokens->get(2))->copy();
597 if (tokens->getLength() != 3) {
600 param->tt.fileName = ((GString *)tokens->get(2))->copy();
604 if ((old = (DisplayFontParam *)fontHash->remove(param->name))) {
607 fontHash->add(param->name, param);
613 error(-1, "Bad 'display*Font*' config file command (%s:%d)",
614 fileName->getCString(), line);
617 void GlobalParams::parsePSPaperSize(GList *tokens, GString *fileName,
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);
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());
633 error(-1, "Bad 'psPaperSize' config file command (%s:%d)",
634 fileName->getCString(), line);
638 void GlobalParams::parsePSLevel(GList *tokens, GString *fileName, int line) {
641 if (tokens->getLength() != 2) {
642 error(-1, "Bad 'psLevel' config file command (%s:%d)",
643 fileName->getCString(), line);
646 tok = (GString *)tokens->get(1);
647 if (!tok->cmp("level1")) {
649 } else if (!tok->cmp("level1sep")) {
650 psLevel = psLevel1Sep;
651 } else if (!tok->cmp("level2")) {
653 } else if (!tok->cmp("level2sep")) {
654 psLevel = psLevel2Sep;
655 } else if (!tok->cmp("level3")) {
657 } else if (!tok->cmp("level3Sep")) {
658 psLevel = psLevel3Sep;
660 error(-1, "Bad 'psLevel' config file command (%s:%d)",
661 fileName->getCString(), line);
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);
674 psFile = ((GString *)tokens->get(1))->copy();
677 void GlobalParams::parsePSFont(GList *tokens, GString *fileName, int line) {
680 if (tokens->getLength() != 3) {
681 error(-1, "Bad 'psFont' config file command (%s:%d)",
682 fileName->getCString(), line);
685 param = new PSFontParam(((GString *)tokens->get(1))->copy(), 0,
686 ((GString *)tokens->get(2))->copy(), NULL);
687 psFonts->add(param->pdfFontName, param);
690 void GlobalParams::parsePSFont16(char *cmdName, GList *fontList,
691 GList *tokens, GString *fileName, int line) {
696 if (tokens->getLength() != 5) {
697 error(-1, "Bad '%s' config file command (%s:%d)",
698 cmdName, fileName->getCString(), line);
701 tok = (GString *)tokens->get(2);
702 if (!tok->cmp("H")) {
704 } else if (!tok->cmp("V")) {
707 error(-1, "Bad '%s' config file command (%s:%d)",
708 cmdName, fileName->getCString(), line);
711 param = new PSFontParam(((GString *)tokens->get(1))->copy(),
713 ((GString *)tokens->get(3))->copy(),
714 ((GString *)tokens->get(4))->copy());
715 fontList->append(param);
718 void GlobalParams::parseTextEncoding(GList *tokens, GString *fileName,
720 if (tokens->getLength() != 2) {
721 error(-1, "Bad 'textEncoding' config file command (%s:%d)",
722 fileName->getCString(), line);
726 textEncoding = ((GString *)tokens->get(1))->copy();
729 void GlobalParams::parseTextEOL(GList *tokens, GString *fileName, int line) {
732 if (tokens->getLength() != 2) {
733 error(-1, "Bad 'textEOL' config file command (%s:%d)",
734 fileName->getCString(), line);
737 tok = (GString *)tokens->get(1);
738 if (!tok->cmp("unix")) {
740 } else if (!tok->cmp("dos")) {
742 } else if (!tok->cmp("mac")) {
745 error(-1, "Bad 'textEOL' config file command (%s:%d)",
746 fileName->getCString(), line);
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);
756 fontDirs->append(((GString *)tokens->get(1))->copy());
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);
767 initialZoom = ((GString *)tokens->get(1))->copy();
770 void GlobalParams::parseFontRastControl(char *cmdName, FontRastControl *val,
771 GList *tokens, GString *fileName,
775 if (tokens->getLength() != 2) {
776 error(-1, "Bad '%s' config file command (%s:%d)",
777 cmdName, fileName->getCString(), line);
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);
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);
797 *val = ((GString *)tokens->get(1))->copy();
800 void GlobalParams::parseYesNo(char *cmdName, GBool *flag,
801 GList *tokens, GString *fileName, int line) {
804 if (tokens->getLength() != 2) {
805 error(-1, "Bad '%s' config file command (%s:%d)",
806 cmdName, fileName->getCString(), line);
809 tok = (GString *)tokens->get(1);
810 if (!tok->cmp("yes")) {
812 } else if (!tok->cmp("no")) {
815 error(-1, "Bad '%s' config file command (%s:%d)",
816 cmdName, fileName->getCString(), line);
820 GlobalParams::~GlobalParams() {
825 freeBuiltinFontTables();
827 delete macRomanReverseMap;
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);
841 deleteGHash(psFonts, PSFontParam);
842 deleteGList(psNamedFonts16, PSFontParam);
843 deleteGList(psFonts16, PSFontParam);
845 deleteGList(fontDirs, GString);
854 cMapDirs->startIter(&iter);
855 while (cMapDirs->getNext(&iter, &key, (void **)&list)) {
856 deleteGList(list, GString);
860 delete cidToUnicodeCache;
861 delete unicodeToUnicodeCache;
862 delete unicodeMapCache;
866 gDestroyMutex(&mutex);
867 gDestroyMutex(&unicodeMapCacheMutex);
868 gDestroyMutex(&cMapCacheMutex);
872 //------------------------------------------------------------------------
874 //------------------------------------------------------------------------
876 CharCode GlobalParams::getMacRomanCharCode(char *charName) {
877 // no need to lock - macRomanReverseMap is constant
878 return macRomanReverseMap->lookup(charName);
881 Unicode GlobalParams::mapNameToUnicode(char *charName) {
882 // no need to lock - nameToUnicode is constant
883 return nameToUnicode->lookup(charName);
886 UnicodeMap *GlobalParams::getResidentUnicodeMap(GString *encodingName) {
890 map = (UnicodeMap *)residentUnicodeMaps->lookup(encodingName);
898 FILE *GlobalParams::getUnicodeMapFile(GString *encodingName) {
903 if ((fileName = (GString *)unicodeMaps->lookup(encodingName))) {
904 f = fopen(fileName->getCString(), "r");
912 FILE *GlobalParams::findCMapFile(GString *collection, GString *cMapName) {
920 if (!(list = (GList *)cMapDirs->lookup(collection))) {
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");
938 FILE *GlobalParams::findToUnicodeFile(GString *name) {
939 GString *dir, *fileName;
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");
958 DisplayFontParam *GlobalParams::getDisplayFont(GString *fontName) {
959 DisplayFontParam *dfp;
962 dfp = (DisplayFontParam *)displayFonts->lookup(fontName);
967 DisplayFontParam *GlobalParams::getDisplayCIDFont(GString *fontName,
968 GString *collection) {
969 DisplayFontParam *dfp;
973 !(dfp = (DisplayFontParam *)displayNamedCIDFonts->lookup(fontName))) {
974 dfp = (DisplayFontParam *)displayCIDFonts->lookup(collection);
980 GString *GlobalParams::getPSFile() {
984 s = psFile ? psFile->copy() : (GString *)NULL;
989 int GlobalParams::getPSPaperWidth() {
998 int GlobalParams::getPSPaperHeight() {
1007 GBool GlobalParams::getPSDuplex() {
1016 PSLevel GlobalParams::getPSLevel() {
1025 PSFontParam *GlobalParams::getPSFont(GString *fontName) {
1029 p = (PSFontParam *)psFonts->lookup(fontName);
1034 PSFontParam *GlobalParams::getPSFont16(GString *fontName,
1035 GString *collection, int wMode) {
1042 for (i = 0; i < psNamedFonts16->getLength(); ++i) {
1043 p = (PSFontParam *)psNamedFonts16->get(i);
1044 if (!p->pdfFontName->cmp(fontName) &&
1045 p->wMode == wMode) {
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) {
1065 GBool GlobalParams::getPSEmbedType1() {
1074 GBool GlobalParams::getPSEmbedTrueType() {
1078 e = psEmbedTrueType;
1083 GBool GlobalParams::getPSEmbedCIDPostScript() {
1087 e = psEmbedCIDPostScript;
1092 GBool GlobalParams::getPSEmbedCIDTrueType() {
1096 e = psEmbedCIDTrueType;
1101 GBool GlobalParams::getPSOPI() {
1110 GBool GlobalParams::getPSASCIIHex() {
1119 GString *GlobalParams::getTextEncodingName() {
1123 s = textEncoding->copy();
1128 EndOfLineKind GlobalParams::getTextEOL() {
1137 GBool GlobalParams::getTextPageBreaks() {
1141 pageBreaks = textPageBreaks;
1146 GBool GlobalParams::getTextKeepTinyChars() {
1150 tiny = textKeepTinyChars;
1155 GString *GlobalParams::findFontFile(GString *fontName, char **exts) {
1156 GString *dir, *fileName;
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"))) {
1179 GString *GlobalParams::getInitialZoom() {
1183 s = initialZoom->copy();
1188 FontRastControl GlobalParams::getT1libControl() {
1197 FontRastControl GlobalParams::getFreeTypeControl() {
1201 c = freetypeControl;
1206 GBool GlobalParams::getMapNumericCharNames() {
1210 map = mapNumericCharNames;
1215 GBool GlobalParams::getPrintCommands() {
1224 GBool GlobalParams::getErrQuiet() {
1233 CharCodeToUnicode *GlobalParams::getCIDToUnicode(GString *collection) {
1235 CharCodeToUnicode *ctu;
1238 if (!(ctu = cidToUnicodeCache->getCharCodeToUnicode(collection))) {
1239 if ((fileName = (GString *)cidToUnicodes->lookup(collection)) &&
1240 (ctu = CharCodeToUnicode::parseCIDToUnicode(fileName, collection))) {
1241 cidToUnicodeCache->add(ctu);
1248 CharCodeToUnicode *GlobalParams::getUnicodeToUnicode(GString *fontName) {
1249 CharCodeToUnicode *ctu;
1251 GString *fontPattern, *fileName;
1255 unicodeToUnicodes->startIter(&iter);
1256 while (unicodeToUnicodes->getNext(&iter, &fontPattern, (void **)&fileName)) {
1257 if (strstr(fontName->getCString(), fontPattern->getCString())) {
1258 unicodeToUnicodes->killIter(&iter);
1264 if (!(ctu = unicodeToUnicodeCache->getCharCodeToUnicode(fileName))) {
1265 if ((ctu = CharCodeToUnicode::parseUnicodeToUnicode(fileName))) {
1266 unicodeToUnicodeCache->add(ctu);
1276 UnicodeMap *GlobalParams::getUnicodeMap(GString *encodingName) {
1277 return getUnicodeMap2(encodingName);
1280 UnicodeMap *GlobalParams::getUnicodeMap2(GString *encodingName) {
1283 if (!(map = getResidentUnicodeMap(encodingName))) {
1284 lockUnicodeMapCache;
1285 map = unicodeMapCache->getUnicodeMap(encodingName);
1286 unlockUnicodeMapCache;
1291 CMap *GlobalParams::getCMap(GString *collection, GString *cMapName) {
1295 cMap = cMapCache->getCMap(collection, cMapName);
1300 UnicodeMap *GlobalParams::getTextEncoding() {
1301 return getUnicodeMap2(textEncoding);
1304 //------------------------------------------------------------------------
1305 // functions to set parameters
1306 //------------------------------------------------------------------------
1308 void GlobalParams::addDisplayFont(DisplayFontParam *param) {
1309 DisplayFontParam *old;
1312 if ((old = (DisplayFontParam *)displayFonts->remove(param->name))) {
1315 displayFonts->add(param->name, param);
1319 void GlobalParams::setPSFile(char *file) {
1324 psFile = new GString(file);
1328 GBool GlobalParams::setPSPaperSize(char *size) {
1330 if (!strcmp(size, "match")) {
1331 psPaperWidth = psPaperHeight = -1;
1332 } else if (!strcmp(size, "letter")) {
1334 psPaperHeight = 792;
1335 } else if (!strcmp(size, "legal")) {
1337 psPaperHeight = 1008;
1338 } else if (!strcmp(size, "A4")) {
1340 psPaperHeight = 842;
1341 } else if (!strcmp(size, "A3")) {
1343 psPaperHeight = 1190;
1352 void GlobalParams::setPSPaperWidth(int width) {
1354 psPaperWidth = width;
1358 void GlobalParams::setPSPaperHeight(int height) {
1360 psPaperHeight = height;
1364 void GlobalParams::setPSDuplex(GBool duplex) {
1370 void GlobalParams::setPSLevel(PSLevel level) {
1376 void GlobalParams::setPSEmbedType1(GBool embed) {
1378 psEmbedType1 = embed;
1382 void GlobalParams::setPSEmbedTrueType(GBool embed) {
1384 psEmbedTrueType = embed;
1388 void GlobalParams::setPSEmbedCIDPostScript(GBool embed) {
1390 psEmbedCIDPostScript = embed;
1394 void GlobalParams::setPSEmbedCIDTrueType(GBool embed) {
1396 psEmbedCIDTrueType = embed;
1400 void GlobalParams::setPSOPI(GBool opi) {
1406 void GlobalParams::setPSASCIIHex(GBool hex) {
1412 void GlobalParams::setTextEncoding(char *encodingName) {
1414 delete textEncoding;
1415 textEncoding = new GString(encodingName);
1419 GBool GlobalParams::setTextEOL(char *s) {
1421 if (!strcmp(s, "unix")) {
1423 } else if (!strcmp(s, "dos")) {
1425 } else if (!strcmp(s, "mac")) {
1435 void GlobalParams::setTextPageBreaks(GBool pageBreaks) {
1437 textPageBreaks = pageBreaks;
1441 void GlobalParams::setTextKeepTinyChars(GBool keep) {
1443 textKeepTinyChars = keep;
1447 void GlobalParams::setInitialZoom(char *s) {
1450 initialZoom = new GString(s);
1454 GBool GlobalParams::setT1libControl(char *s) {
1458 ok = setFontRastControl(&t1libControl, s);
1463 GBool GlobalParams::setFreeTypeControl(char *s) {
1467 ok = setFontRastControl(&freetypeControl, s);
1472 GBool GlobalParams::setFontRastControl(FontRastControl *val, char *s) {
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;
1490 void GlobalParams::setMapNumericCharNames(GBool map) {
1492 mapNumericCharNames = map;
1496 void GlobalParams::setPrintCommands(GBool printCommandsA) {
1498 printCommands = printCommandsA;
1502 void GlobalParams::setErrQuiet(GBool errQuietA) {
1504 errQuiet = errQuietA;