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 globalParamsLock gLockMutex(&mutex)
36 # define globalParamsUnlock gUnlockMutex(&mutex)
38 # define globalParamsLock
39 # define globalParamsUnlock
42 #include "NameToUnicodeTable.h"
43 #include "UnicodeMapTables.h"
44 #include "DisplayFontTable.h"
47 //------------------------------------------------------------------------
49 GlobalParams *globalParams = NULL;
51 //------------------------------------------------------------------------
53 //------------------------------------------------------------------------
55 DisplayFontParam::DisplayFontParam(GString *nameA,
56 DisplayFontParamKind kindA) {
73 DisplayFontParam::DisplayFontParam(char *nameA, char *xlfdA, char *encodingA) {
74 name = new GString(nameA);
76 x.xlfd = new GString(xlfdA);
77 x.encoding = new GString(encodingA);
80 DisplayFontParam::~DisplayFontParam() {
104 //------------------------------------------------------------------------
106 //------------------------------------------------------------------------
108 PSFontParam::PSFontParam(GString *pdfFontNameA, int wModeA,
109 GString *psFontNameA, GString *encodingA) {
110 pdfFontName = pdfFontNameA;
112 psFontName = psFontNameA;
113 encoding = encodingA;
116 PSFontParam::~PSFontParam() {
124 //------------------------------------------------------------------------
126 //------------------------------------------------------------------------
128 GlobalParams::GlobalParams(char *cfgFileName) {
130 DisplayFontParam *dfp;
139 initBuiltinFontTables();
141 // scan the encoding in reverse because we want the lowest-numbered
142 // index for each char name ('space' is encoded twice)
143 macRomanReverseMap = new NameToCharCode();
144 for (i = 255; i >= 0; --i) {
145 if (macRomanEncoding[i]) {
146 macRomanReverseMap->add(macRomanEncoding[i], (CharCode)i);
150 nameToUnicode = new NameToCharCode();
151 cidToUnicodes = new GHash(gTrue);
152 residentUnicodeMaps = new GHash();
153 unicodeMaps = new GHash(gTrue);
154 cMapDirs = new GHash(gTrue);
155 toUnicodeDirs = new GList();
156 displayFonts = new GHash();
157 displayCIDFonts = new GHash();
158 displayNamedCIDFonts = new GHash();
161 const struct paper *paperType;
163 if ((paperName = systempapername())) {
164 paperType = paperinfo(paperName);
165 psPaperWidth = (int)paperpswidth(paperType);
166 psPaperHeight = (int)paperpsheight(paperType);
168 error(-1, "No paper information available - using defaults");
169 psPaperWidth = defPaperWidth;
170 psPaperHeight = defPaperHeight;
174 psPaperWidth = defPaperWidth;
175 psPaperHeight = defPaperHeight;
180 psFonts = new GHash();
181 psNamedFonts16 = new GList();
182 psFonts16 = new GList();
183 psEmbedType1 = gTrue;
184 psEmbedTrueType = gTrue;
185 psEmbedCIDPostScript = gTrue;
186 psEmbedCIDTrueType = gTrue;
189 textEncoding = new GString("Latin1");
197 textKeepTinyChars = gFalse;
198 fontDirs = new GList();
199 initialZoom = new GString("1");
200 t1libControl = fontRastAALow;
201 freetypeControl = fontRastAALow;
204 mapNumericCharNames = gTrue;
205 printCommands = gFalse;
208 cidToUnicodeCache = new CIDToUnicodeCache();
209 unicodeMapCache = new UnicodeMapCache();
210 cMapCache = new CMapCache();
212 // set up the initial nameToUnicode table
213 for (i = 0; nameToUnicodeTab[i].name; ++i) {
214 nameToUnicode->add(nameToUnicodeTab[i].name, nameToUnicodeTab[i].u);
217 // set up the residentUnicodeMaps table
218 map = new UnicodeMap("Latin1", gFalse,
219 latin1UnicodeMapRanges, latin1UnicodeMapLen);
220 residentUnicodeMaps->add(map->getEncodingName(), map);
221 map = new UnicodeMap("ASCII7", gFalse,
222 ascii7UnicodeMapRanges, ascii7UnicodeMapLen);
223 residentUnicodeMaps->add(map->getEncodingName(), map);
224 map = new UnicodeMap("Symbol", gFalse,
225 symbolUnicodeMapRanges, symbolUnicodeMapLen);
226 residentUnicodeMaps->add(map->getEncodingName(), map);
227 map = new UnicodeMap("ZapfDingbats", gFalse, zapfDingbatsUnicodeMapRanges,
228 zapfDingbatsUnicodeMapLen);
229 residentUnicodeMaps->add(map->getEncodingName(), map);
230 map = new UnicodeMap("UTF-8", gTrue, &mapUTF8);
231 residentUnicodeMaps->add(map->getEncodingName(), map);
232 map = new UnicodeMap("UCS-2", gTrue, &mapUCS2);
233 residentUnicodeMaps->add(map->getEncodingName(), map);
235 // default displayFonts table
236 for (i = 0; displayFontTab[i].name; ++i) {
237 dfp = new DisplayFontParam(displayFontTab[i].name,
238 displayFontTab[i].xlfd,
239 displayFontTab[i].encoding);
240 displayFonts->add(dfp->name, dfp);
243 // look for a user config file, then a system-wide config file
246 if (cfgFileName && cfgFileName[0]) {
247 fileName = new GString(cfgFileName);
248 if (!(f = fopen(fileName->getCString(), "r"))) {
253 fileName = appendToPath(getHomeDir(), xpdfUserConfigFile);
254 if (!(f = fopen(fileName->getCString(), "r"))) {
259 #if defined(WIN32) && !defined(__CYGWIN32__)
261 i = GetModuleFileName(NULL, buf, sizeof(buf));
262 if (i <= 0 || i >= sizeof(buf)) {
263 // error or path too long for buffer - just use the current dir
266 fileName = grabPath(buf);
267 appendToPath(fileName, xpdfSysConfigFile);
269 fileName = new GString(xpdfSysConfigFile);
271 if (!(f = fopen(fileName->getCString(), "r"))) {
276 parseFile(fileName, f);
282 void GlobalParams::parseFile(GString *fileName, FILE *f) {
285 GString *cmd, *incFile;
291 while (getLine(buf, sizeof(buf) - 1, f)) {
293 // break the line into tokens
294 tokens = new GList();
297 for (; *p1 && isspace(*p1); ++p1) ;
301 if (*p1 == '"' || *p1 == '\'') {
302 for (p2 = p1 + 1; *p2 && *p2 != *p1; ++p2) ;
305 for (p2 = p1 + 1; *p2 && !isspace(*p2); ++p2) ;
307 tokens->append(new GString(p1, p2 - p1));
308 p1 = *p2 ? p2 + 1 : p2;
311 if (tokens->getLength() > 0 &&
312 ((GString *)tokens->get(0))->getChar(0) != '#') {
313 cmd = (GString *)tokens->get(0);
314 if (!cmd->cmp("include")) {
315 if (tokens->getLength() == 2) {
316 incFile = (GString *)tokens->get(1);
317 if ((f2 = fopen(incFile->getCString(), "r"))) {
318 parseFile(incFile, f2);
321 error(-1, "Couldn't find included config file: '%s' (%s:%d)",
322 incFile->getCString(), fileName->getCString(), line);
325 error(-1, "Bad 'include' config file command (%s:%d)",
326 fileName->getCString(), line);
328 } else if (!cmd->cmp("nameToUnicode")) {
329 parseNameToUnicode(tokens, fileName, line);
330 } else if (!cmd->cmp("cidToUnicode")) {
331 parseCIDToUnicode(tokens, fileName, line);
332 } else if (!cmd->cmp("unicodeMap")) {
333 parseUnicodeMap(tokens, fileName, line);
334 } else if (!cmd->cmp("cMapDir")) {
335 parseCMapDir(tokens, fileName, line);
336 } else if (!cmd->cmp("toUnicodeDir")) {
337 parseToUnicodeDir(tokens, fileName, line);
338 } else if (!cmd->cmp("displayFontX")) {
339 parseDisplayFont(tokens, displayFonts, displayFontX, fileName, line);
340 } else if (!cmd->cmp("displayFontT1")) {
341 parseDisplayFont(tokens, displayFonts, displayFontT1, fileName, line);
342 } else if (!cmd->cmp("displayFontTT")) {
343 parseDisplayFont(tokens, displayFonts, displayFontTT, fileName, line);
344 } else if (!cmd->cmp("displayNamedCIDFontX")) {
345 parseDisplayFont(tokens, displayNamedCIDFonts,
346 displayFontX, fileName, line);
347 } else if (!cmd->cmp("displayCIDFontX")) {
348 parseDisplayFont(tokens, displayCIDFonts,
349 displayFontX, fileName, line);
350 } else if (!cmd->cmp("displayNamedCIDFontT1")) {
351 parseDisplayFont(tokens, displayNamedCIDFonts,
352 displayFontT1, fileName, line);
353 } else if (!cmd->cmp("displayCIDFontT1")) {
354 parseDisplayFont(tokens, displayCIDFonts,
355 displayFontT1, fileName, line);
356 } else if (!cmd->cmp("displayNamedCIDFontTT")) {
357 parseDisplayFont(tokens, displayNamedCIDFonts,
358 displayFontTT, fileName, line);
359 } else if (!cmd->cmp("displayCIDFontTT")) {
360 parseDisplayFont(tokens, displayCIDFonts,
361 displayFontTT, fileName, line);
362 } else if (!cmd->cmp("psFile")) {
363 parsePSFile(tokens, fileName, line);
364 } else if (!cmd->cmp("psFont")) {
365 parsePSFont(tokens, fileName, line);
366 } else if (!cmd->cmp("psNamedFont16")) {
367 parsePSFont16("psNamedFont16", psNamedFonts16,
368 tokens, fileName, line);
369 } else if (!cmd->cmp("psFont16")) {
370 parsePSFont16("psFont16", psFonts16, tokens, fileName, line);
371 } else if (!cmd->cmp("psPaperSize")) {
372 parsePSPaperSize(tokens, fileName, line);
373 } else if (!cmd->cmp("psDuplex")) {
374 parseYesNo("psDuplex", &psDuplex, tokens, fileName, line);
375 } else if (!cmd->cmp("psLevel")) {
376 parsePSLevel(tokens, fileName, line);
377 } else if (!cmd->cmp("psEmbedType1Fonts")) {
378 parseYesNo("psEmbedType1", &psEmbedType1, tokens, fileName, line);
379 } else if (!cmd->cmp("psEmbedTrueTypeFonts")) {
380 parseYesNo("psEmbedTrueType", &psEmbedTrueType,
381 tokens, fileName, line);
382 } else if (!cmd->cmp("psEmbedCIDPostScriptFonts")) {
383 parseYesNo("psEmbedCIDPostScript", &psEmbedCIDPostScript,
384 tokens, fileName, line);
385 } else if (!cmd->cmp("psEmbedCIDTrueTypeFonts")) {
386 parseYesNo("psEmbedCIDTrueType", &psEmbedCIDTrueType,
387 tokens, fileName, line);
388 } else if (!cmd->cmp("psOPI")) {
389 parseYesNo("psOPI", &psOPI, tokens, fileName, line);
390 } else if (!cmd->cmp("psASCIIHex")) {
391 parseYesNo("psASCIIHex", &psASCIIHex, tokens, fileName, line);
392 } else if (!cmd->cmp("textEncoding")) {
393 parseTextEncoding(tokens, fileName, line);
394 } else if (!cmd->cmp("textEOL")) {
395 parseTextEOL(tokens, fileName, line);
396 } else if (!cmd->cmp("textKeepTinyChars")) {
397 parseYesNo("textKeepTinyChars", &textKeepTinyChars,
398 tokens, fileName, line);
399 } else if (!cmd->cmp("fontDir")) {
400 parseFontDir(tokens, fileName, line);
401 } else if (!cmd->cmp("initialZoom")) {
402 parseInitialZoom(tokens, fileName, line);
403 } else if (!cmd->cmp("t1libControl")) {
404 parseFontRastControl("t1libControl", &t1libControl,
405 tokens, fileName, line);
406 } else if (!cmd->cmp("freetypeControl")) {
407 parseFontRastControl("freetypeControl", &freetypeControl,
408 tokens, fileName, line);
409 } else if (!cmd->cmp("urlCommand")) {
410 parseCommand("urlCommand", &urlCommand, tokens, fileName, line);
411 } else if (!cmd->cmp("movieCommand")) {
412 parseCommand("movieCommand", &movieCommand, tokens, fileName, line);
413 } else if (!cmd->cmp("mapNumericCharNames")) {
414 parseYesNo("mapNumericCharNames", &mapNumericCharNames,
415 tokens, fileName, line);
416 } else if (!cmd->cmp("printCommands")) {
417 parseYesNo("printCommands", &printCommands, tokens, fileName, line);
418 } else if (!cmd->cmp("errQuiet")) {
419 parseYesNo("errQuiet", &errQuiet, tokens, fileName, line);
420 } else if (!cmd->cmp("fontpath") || !cmd->cmp("fontmap")) {
421 error(-1, "Unknown config file command");
422 error(-1, "-- the config file format has changed since Xpdf 0.9x");
424 error(-1, "Unknown config file command '%s' (%s:%d)",
425 cmd->getCString(), fileName->getCString(), line);
429 deleteGList(tokens, GString);
434 void GlobalParams::parseNameToUnicode(GList *tokens, GString *fileName,
443 if (tokens->getLength() != 2) {
444 error(-1, "Bad 'nameToUnicode' config file command (%s:%d)",
445 fileName->getCString(), line);
448 name = (GString *)tokens->get(1);
449 if (!(f = fopen(name->getCString(), "r"))) {
450 error(-1, "Couldn't open 'nameToUnicode' file '%s'",
455 while (getLine(buf, sizeof(buf), f)) {
456 tok1 = strtok(buf, " \t\r\n");
457 tok2 = strtok(NULL, " \t\r\n");
459 sscanf(tok1, "%x", &u);
460 nameToUnicode->add(tok2, u);
462 error(-1, "Bad line in 'nameToUnicode' file (%s:%d)", name, line2);
469 void GlobalParams::parseCIDToUnicode(GList *tokens, GString *fileName,
471 GString *collection, *name, *old;
473 if (tokens->getLength() != 3) {
474 error(-1, "Bad 'cidToUnicode' config file command (%s:%d)",
475 fileName->getCString(), line);
478 collection = (GString *)tokens->get(1);
479 name = (GString *)tokens->get(2);
480 if ((old = (GString *)cidToUnicodes->remove(collection))) {
483 cidToUnicodes->add(collection->copy(), name->copy());
486 void GlobalParams::parseUnicodeMap(GList *tokens, GString *fileName,
488 GString *encodingName, *name, *old;
490 if (tokens->getLength() != 3) {
491 error(-1, "Bad 'unicodeMap' config file command (%s:%d)",
492 fileName->getCString(), line);
495 encodingName = (GString *)tokens->get(1);
496 name = (GString *)tokens->get(2);
497 if ((old = (GString *)unicodeMaps->remove(encodingName))) {
500 unicodeMaps->add(encodingName->copy(), name->copy());
503 void GlobalParams::parseCMapDir(GList *tokens, GString *fileName, int line) {
504 GString *collection, *dir;
507 if (tokens->getLength() != 3) {
508 error(-1, "Bad 'cMapDir' config file command (%s:%d)",
509 fileName->getCString(), line);
512 collection = (GString *)tokens->get(1);
513 dir = (GString *)tokens->get(2);
514 if (!(list = (GList *)cMapDirs->lookup(collection))) {
516 cMapDirs->add(collection->copy(), list);
518 list->append(dir->copy());
521 void GlobalParams::parseToUnicodeDir(GList *tokens, GString *fileName,
523 if (tokens->getLength() != 2) {
524 error(-1, "Bad 'toUnicodeDir' config file command (%s:%d)",
525 fileName->getCString(), line);
528 toUnicodeDirs->append(((GString *)tokens->get(1))->copy());
531 void GlobalParams::parseDisplayFont(GList *tokens, GHash *fontHash,
532 DisplayFontParamKind kind,
533 GString *fileName, int line) {
534 DisplayFontParam *param, *old;
536 if (tokens->getLength() < 2) {
539 param = new DisplayFontParam(((GString *)tokens->get(1))->copy(), kind);
543 if (tokens->getLength() != 4) {
546 param->x.xlfd = ((GString *)tokens->get(2))->copy();
547 param->x.encoding = ((GString *)tokens->get(3))->copy();
550 if (tokens->getLength() != 3) {
553 param->t1.fileName = ((GString *)tokens->get(2))->copy();
556 if (tokens->getLength() != 3) {
559 param->tt.fileName = ((GString *)tokens->get(2))->copy();
563 if ((old = (DisplayFontParam *)fontHash->remove(param->name))) {
566 fontHash->add(param->name, param);
572 error(-1, "Bad 'display*Font*' config file command (%s:%d)",
573 fileName->getCString(), line);
576 void GlobalParams::parsePSPaperSize(GList *tokens, GString *fileName,
580 if (tokens->getLength() == 2) {
581 tok = (GString *)tokens->get(1);
582 if (!setPSPaperSize(tok->getCString())) {
583 error(-1, "Bad 'psPaperSize' config file command (%s:%d)",
584 fileName->getCString(), line);
586 } else if (tokens->getLength() == 3) {
587 tok = (GString *)tokens->get(1);
588 psPaperWidth = atoi(tok->getCString());
589 tok = (GString *)tokens->get(2);
590 psPaperHeight = atoi(tok->getCString());
592 error(-1, "Bad 'psPaperSize' config file command (%s:%d)",
593 fileName->getCString(), line);
597 void GlobalParams::parsePSLevel(GList *tokens, GString *fileName, int line) {
600 if (tokens->getLength() != 2) {
601 error(-1, "Bad 'psLevel' config file command (%s:%d)",
602 fileName->getCString(), line);
605 tok = (GString *)tokens->get(1);
606 if (!tok->cmp("level1")) {
608 } else if (!tok->cmp("level1sep")) {
609 psLevel = psLevel1Sep;
610 } else if (!tok->cmp("level2")) {
612 } else if (!tok->cmp("level2sep")) {
613 psLevel = psLevel2Sep;
614 } else if (!tok->cmp("level3")) {
616 } else if (!tok->cmp("level3Sep")) {
617 psLevel = psLevel3Sep;
619 error(-1, "Bad 'psLevel' config file command (%s:%d)",
620 fileName->getCString(), line);
624 void GlobalParams::parsePSFile(GList *tokens, GString *fileName, int line) {
625 if (tokens->getLength() != 2) {
626 error(-1, "Bad 'psFile' config file command (%s:%d)",
627 fileName->getCString(), line);
633 psFile = ((GString *)tokens->get(1))->copy();
636 void GlobalParams::parsePSFont(GList *tokens, GString *fileName, int line) {
639 if (tokens->getLength() != 3) {
640 error(-1, "Bad 'psFont' config file command (%s:%d)",
641 fileName->getCString(), line);
644 param = new PSFontParam(((GString *)tokens->get(1))->copy(), 0,
645 ((GString *)tokens->get(2))->copy(), NULL);
646 psFonts->add(param->pdfFontName, param);
649 void GlobalParams::parsePSFont16(char *cmdName, GList *fontList,
650 GList *tokens, GString *fileName, int line) {
655 if (tokens->getLength() != 5) {
656 error(-1, "Bad '%s' config file command (%s:%d)",
657 cmdName, fileName->getCString(), line);
660 tok = (GString *)tokens->get(2);
661 if (!tok->cmp("H")) {
663 } else if (!tok->cmp("V")) {
666 error(-1, "Bad '%s' config file command (%s:%d)",
667 cmdName, fileName->getCString(), line);
670 param = new PSFontParam(((GString *)tokens->get(1))->copy(),
672 ((GString *)tokens->get(3))->copy(),
673 ((GString *)tokens->get(4))->copy());
674 fontList->append(param);
677 void GlobalParams::parseTextEncoding(GList *tokens, GString *fileName,
679 if (tokens->getLength() != 2) {
680 error(-1, "Bad 'textEncoding' config file command (%s:%d)",
681 fileName->getCString(), line);
685 textEncoding = ((GString *)tokens->get(1))->copy();
688 void GlobalParams::parseTextEOL(GList *tokens, GString *fileName, int line) {
691 if (tokens->getLength() != 2) {
692 error(-1, "Bad 'textEOL' config file command (%s:%d)",
693 fileName->getCString(), line);
696 tok = (GString *)tokens->get(1);
697 if (!tok->cmp("unix")) {
699 } else if (!tok->cmp("dos")) {
701 } else if (!tok->cmp("mac")) {
704 error(-1, "Bad 'textEOL' config file command (%s:%d)",
705 fileName->getCString(), line);
709 void GlobalParams::parseFontDir(GList *tokens, GString *fileName, int line) {
710 if (tokens->getLength() != 2) {
711 error(-1, "Bad 'fontDir' config file command (%s:%d)",
712 fileName->getCString(), line);
715 fontDirs->append(((GString *)tokens->get(1))->copy());
718 void GlobalParams::parseInitialZoom(GList *tokens,
719 GString *fileName, int line) {
720 if (tokens->getLength() != 2) {
721 error(-1, "Bad 'initialZoom' config file command (%s:%d)",
722 fileName->getCString(), line);
726 initialZoom = ((GString *)tokens->get(1))->copy();
729 void GlobalParams::parseFontRastControl(char *cmdName, FontRastControl *val,
730 GList *tokens, GString *fileName,
734 if (tokens->getLength() != 2) {
735 error(-1, "Bad '%s' config file command (%s:%d)",
736 cmdName, fileName->getCString(), line);
739 tok = (GString *)tokens->get(1);
740 if (!setFontRastControl(val, tok->getCString())) {
741 error(-1, "Bad '%s' config file command (%s:%d)",
742 cmdName, fileName->getCString(), line);
746 void GlobalParams::parseCommand(char *cmdName, GString **val,
747 GList *tokens, GString *fileName, int line) {
748 if (tokens->getLength() != 2) {
749 error(-1, "Bad '%s' config file command (%s:%d)",
750 cmdName, fileName->getCString(), line);
756 *val = ((GString *)tokens->get(1))->copy();
759 void GlobalParams::parseYesNo(char *cmdName, GBool *flag,
760 GList *tokens, GString *fileName, int line) {
763 if (tokens->getLength() != 2) {
764 error(-1, "Bad '%s' config file command (%s:%d)",
765 cmdName, fileName->getCString(), line);
768 tok = (GString *)tokens->get(1);
769 if (!tok->cmp("yes")) {
771 } else if (!tok->cmp("no")) {
774 error(-1, "Bad '%s' config file command (%s:%d)",
775 cmdName, fileName->getCString(), line);
779 GlobalParams::~GlobalParams() {
784 freeBuiltinFontTables();
786 delete macRomanReverseMap;
788 delete nameToUnicode;
789 deleteGHash(cidToUnicodes, GString);
790 deleteGHash(residentUnicodeMaps, UnicodeMap);
791 deleteGHash(unicodeMaps, GString);
792 deleteGList(toUnicodeDirs, GString);
793 deleteGHash(displayFonts, DisplayFontParam);
794 deleteGHash(displayCIDFonts, DisplayFontParam);
795 deleteGHash(displayNamedCIDFonts, DisplayFontParam);
799 deleteGHash(psFonts, PSFontParam);
800 deleteGList(psNamedFonts16, PSFontParam);
801 deleteGList(psFonts16, PSFontParam);
803 deleteGList(fontDirs, GString);
812 cMapDirs->startIter(&iter);
813 while (cMapDirs->getNext(&iter, &key, (void **)&list)) {
814 deleteGList(list, GString);
818 delete cidToUnicodeCache;
819 delete unicodeMapCache;
823 gDestroyMutex(&mutex);
827 //------------------------------------------------------------------------
829 //------------------------------------------------------------------------
831 CharCode GlobalParams::getMacRomanCharCode(char *charName) {
832 return macRomanReverseMap->lookup(charName);
835 Unicode GlobalParams::mapNameToUnicode(char *charName) {
836 return nameToUnicode->lookup(charName);
839 FILE *GlobalParams::getCIDToUnicodeFile(GString *collection) {
842 if (!(fileName = (GString *)cidToUnicodes->lookup(collection))) {
845 return fopen(fileName->getCString(), "r");
848 UnicodeMap *GlobalParams::getResidentUnicodeMap(GString *encodingName) {
849 return (UnicodeMap *)residentUnicodeMaps->lookup(encodingName);
852 FILE *GlobalParams::getUnicodeMapFile(GString *encodingName) {
855 if (!(fileName = (GString *)unicodeMaps->lookup(encodingName))) {
858 return fopen(fileName->getCString(), "r");
861 FILE *GlobalParams::findCMapFile(GString *collection, GString *cMapName) {
868 if (!(list = (GList *)cMapDirs->lookup(collection))) {
871 for (i = 0; i < list->getLength(); ++i) {
872 dir = (GString *)list->get(i);
873 fileName = appendToPath(dir->copy(), cMapName->getCString());
874 f = fopen(fileName->getCString(), "r");
883 FILE *GlobalParams::findToUnicodeFile(GString *name) {
884 GString *dir, *fileName;
888 for (i = 0; i < toUnicodeDirs->getLength(); ++i) {
889 dir = (GString *)toUnicodeDirs->get(i);
890 fileName = appendToPath(dir->copy(), name->getCString());
891 f = fopen(fileName->getCString(), "r");
900 DisplayFontParam *GlobalParams::getDisplayFont(GString *fontName) {
901 DisplayFontParam *dfp;
904 dfp = (DisplayFontParam *)displayFonts->lookup(fontName);
909 DisplayFontParam *GlobalParams::getDisplayCIDFont(GString *fontName,
910 GString *collection) {
911 DisplayFontParam *dfp;
914 !(dfp = (DisplayFontParam *)displayNamedCIDFonts->lookup(fontName))) {
915 dfp = (DisplayFontParam *)displayCIDFonts->lookup(collection);
920 GString *GlobalParams::getPSFile() {
924 s = psFile ? psFile->copy() : (GString *)NULL;
929 int GlobalParams::getPSPaperWidth() {
938 int GlobalParams::getPSPaperHeight() {
947 GBool GlobalParams::getPSDuplex() {
956 PSLevel GlobalParams::getPSLevel() {
965 PSFontParam *GlobalParams::getPSFont(GString *fontName) {
966 return (PSFontParam *)psFonts->lookup(fontName);
969 PSFontParam *GlobalParams::getPSFont16(GString *fontName,
970 GString *collection, int wMode) {
976 for (i = 0; i < psNamedFonts16->getLength(); ++i) {
977 p = (PSFontParam *)psNamedFonts16->get(i);
978 if (!p->pdfFontName->cmp(fontName) &&
985 if (!p && collection) {
986 for (i = 0; i < psFonts16->getLength(); ++i) {
987 p = (PSFontParam *)psFonts16->get(i);
988 if (!p->pdfFontName->cmp(collection) &&
998 GBool GlobalParams::getPSEmbedType1() {
1007 GBool GlobalParams::getPSEmbedTrueType() {
1011 e = psEmbedTrueType;
1016 GBool GlobalParams::getPSEmbedCIDPostScript() {
1020 e = psEmbedCIDPostScript;
1025 GBool GlobalParams::getPSEmbedCIDTrueType() {
1029 e = psEmbedCIDTrueType;
1034 GBool GlobalParams::getPSOPI() {
1043 GBool GlobalParams::getPSASCIIHex() {
1052 EndOfLineKind GlobalParams::getTextEOL() {
1061 GBool GlobalParams::getTextKeepTinyChars() {
1065 tiny = textKeepTinyChars;
1070 GString *GlobalParams::findFontFile(GString *fontName, char **exts) {
1071 GString *dir, *fileName;
1076 for (i = 0; i < fontDirs->getLength(); ++i) {
1077 dir = (GString *)fontDirs->get(i);
1078 for (ext = exts; *ext; ++ext) {
1079 fileName = appendToPath(dir->copy(), fontName->getCString());
1080 fileName->append(*ext);
1081 if ((f = fopen(fileName->getCString(), "r"))) {
1091 GString *GlobalParams::getInitialZoom() {
1095 s = initialZoom->copy();
1100 FontRastControl GlobalParams::getT1libControl() {
1109 FontRastControl GlobalParams::getFreeTypeControl() {
1113 c = freetypeControl;
1118 GBool GlobalParams::getMapNumericCharNames() {
1122 map = mapNumericCharNames;
1127 GBool GlobalParams::getPrintCommands() {
1136 GBool GlobalParams::getErrQuiet() {
1145 CharCodeToUnicode *GlobalParams::getCIDToUnicode(GString *collection) {
1146 CharCodeToUnicode *ctu;
1149 ctu = cidToUnicodeCache->getCIDToUnicode(collection);
1154 UnicodeMap *GlobalParams::getUnicodeMap(GString *encodingName) {
1158 map = getUnicodeMap2(encodingName);
1163 UnicodeMap *GlobalParams::getUnicodeMap2(GString *encodingName) {
1166 if ((map = getResidentUnicodeMap(encodingName))) {
1169 map = unicodeMapCache->getUnicodeMap(encodingName);
1174 CMap *GlobalParams::getCMap(GString *collection, GString *cMapName) {
1178 cMap = cMapCache->getCMap(collection, cMapName);
1183 UnicodeMap *GlobalParams::getTextEncoding() {
1187 map = getUnicodeMap2(textEncoding);
1192 //------------------------------------------------------------------------
1193 // functions to set parameters
1194 //------------------------------------------------------------------------
1196 void GlobalParams::addDisplayFont(DisplayFontParam *param) {
1197 DisplayFontParam *old;
1200 if ((old = (DisplayFontParam *)displayFonts->remove(param->name))) {
1203 displayFonts->add(param->name, param);
1207 void GlobalParams::setPSFile(char *file) {
1212 psFile = new GString(file);
1216 GBool GlobalParams::setPSPaperSize(char *size) {
1218 if (!strcmp(size, "match")) {
1219 psPaperWidth = psPaperHeight = -1;
1220 } else if (!strcmp(size, "letter")) {
1222 psPaperHeight = 792;
1223 } else if (!strcmp(size, "legal")) {
1225 psPaperHeight = 1008;
1226 } else if (!strcmp(size, "A4")) {
1228 psPaperHeight = 842;
1229 } else if (!strcmp(size, "A3")) {
1231 psPaperHeight = 1190;
1240 void GlobalParams::setPSPaperWidth(int width) {
1242 psPaperWidth = width;
1246 void GlobalParams::setPSPaperHeight(int height) {
1248 psPaperHeight = height;
1252 void GlobalParams::setPSDuplex(GBool duplex) {
1258 void GlobalParams::setPSLevel(PSLevel level) {
1264 void GlobalParams::setPSEmbedType1(GBool embed) {
1266 psEmbedType1 = embed;
1270 void GlobalParams::setPSEmbedTrueType(GBool embed) {
1272 psEmbedTrueType = embed;
1276 void GlobalParams::setPSEmbedCIDPostScript(GBool embed) {
1278 psEmbedCIDPostScript = embed;
1282 void GlobalParams::setPSEmbedCIDTrueType(GBool embed) {
1284 psEmbedCIDTrueType = embed;
1288 void GlobalParams::setPSOPI(GBool opi) {
1294 void GlobalParams::setPSASCIIHex(GBool hex) {
1300 void GlobalParams::setTextEncoding(char *encodingName) {
1302 delete textEncoding;
1303 textEncoding = new GString(encodingName);
1307 GBool GlobalParams::setTextEOL(char *s) {
1309 if (!strcmp(s, "unix")) {
1311 } else if (!strcmp(s, "dos")) {
1313 } else if (!strcmp(s, "mac")) {
1323 void GlobalParams::setTextKeepTinyChars(GBool keep) {
1325 textKeepTinyChars = keep;
1329 void GlobalParams::setInitialZoom(char *s) {
1332 initialZoom = new GString(s);
1336 GBool GlobalParams::setT1libControl(char *s) {
1340 ok = setFontRastControl(&t1libControl, s);
1345 GBool GlobalParams::setFreeTypeControl(char *s) {
1349 ok = setFontRastControl(&freetypeControl, s);
1354 GBool GlobalParams::setFontRastControl(FontRastControl *val, char *s) {
1355 if (!strcmp(s, "none")) {
1356 *val = fontRastNone;
1357 } else if (!strcmp(s, "plain")) {
1358 *val = fontRastPlain;
1359 } else if (!strcmp(s, "low")) {
1360 *val = fontRastAALow;
1361 } else if (!strcmp(s, "high")) {
1362 *val = fontRastAAHigh;
1369 void GlobalParams::setMapNumericCharNames(GBool map) {
1371 mapNumericCharNames = map;
1375 void GlobalParams::setPrintCommands(GBool printCommandsA) {
1377 printCommands = printCommandsA;
1381 void GlobalParams::setErrQuiet(GBool errQuietA) {
1383 errQuiet = errQuietA;