1 //========================================================================
5 // Copyright 2001-2002 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("psFile")) {
357 parsePSFile(tokens, fileName, line);
358 } else if (!cmd->cmp("psFont")) {
359 parsePSFont(tokens, fileName, line);
360 } else if (!cmd->cmp("psNamedFont16")) {
361 parsePSFont16("psNamedFont16", psNamedFonts16,
362 tokens, fileName, line);
363 } else if (!cmd->cmp("psFont16")) {
364 parsePSFont16("psFont16", psFonts16, tokens, fileName, line);
365 } else if (!cmd->cmp("psPaperSize")) {
366 parsePSPaperSize(tokens, fileName, line);
367 } else if (!cmd->cmp("psDuplex")) {
368 parseYesNo("psDuplex", &psDuplex, tokens, fileName, line);
369 } else if (!cmd->cmp("psLevel")) {
370 parsePSLevel(tokens, fileName, line);
371 } else if (!cmd->cmp("psEmbedType1Fonts")) {
372 parseYesNo("psEmbedType1", &psEmbedType1, tokens, fileName, line);
373 } else if (!cmd->cmp("psEmbedTrueTypeFonts")) {
374 parseYesNo("psEmbedTrueType", &psEmbedTrueType,
375 tokens, fileName, line);
376 } else if (!cmd->cmp("psEmbedCIDPostScriptFonts")) {
377 parseYesNo("psEmbedCIDPostScript", &psEmbedCIDPostScript,
378 tokens, fileName, line);
379 } else if (!cmd->cmp("psEmbedCIDTrueTypeFonts")) {
380 parseYesNo("psEmbedCIDTrueType", &psEmbedCIDTrueType,
381 tokens, fileName, line);
382 } else if (!cmd->cmp("psOPI")) {
383 parseYesNo("psOPI", &psOPI, tokens, fileName, line);
384 } else if (!cmd->cmp("psASCIIHex")) {
385 parseYesNo("psASCIIHex", &psASCIIHex, tokens, fileName, line);
386 } else if (!cmd->cmp("textEncoding")) {
387 parseTextEncoding(tokens, fileName, line);
388 } else if (!cmd->cmp("textEOL")) {
389 parseTextEOL(tokens, fileName, line);
390 } else if (!cmd->cmp("textKeepTinyChars")) {
391 parseYesNo("textKeepTinyChars", &textKeepTinyChars,
392 tokens, fileName, line);
393 } else if (!cmd->cmp("fontDir")) {
394 parseFontDir(tokens, fileName, line);
395 } else if (!cmd->cmp("initialZoom")) {
396 parseInitialZoom(tokens, fileName, line);
397 } else if (!cmd->cmp("t1libControl")) {
398 parseFontRastControl("t1libControl", &t1libControl,
399 tokens, fileName, line);
400 } else if (!cmd->cmp("freetypeControl")) {
401 parseFontRastControl("freetypeControl", &freetypeControl,
402 tokens, fileName, line);
403 } else if (!cmd->cmp("urlCommand")) {
404 parseCommand("urlCommand", &urlCommand, tokens, fileName, line);
405 } else if (!cmd->cmp("movieCommand")) {
406 parseCommand("movieCommand", &movieCommand, tokens, fileName, line);
407 } else if (!cmd->cmp("mapNumericCharNames")) {
408 parseYesNo("mapNumericCharNames", &mapNumericCharNames,
409 tokens, fileName, line);
410 } else if (!cmd->cmp("printCommands")) {
411 parseYesNo("printCommands", &printCommands, tokens, fileName, line);
412 } else if (!cmd->cmp("errQuiet")) {
413 parseYesNo("errQuiet", &errQuiet, tokens, fileName, line);
414 } else if (!cmd->cmp("fontpath") || !cmd->cmp("fontmap")) {
415 error(-1, "Unknown config file command");
416 error(-1, "-- the config file format has changed since Xpdf 0.9x");
418 error(-1, "Unknown config file command '%s' (%s:%d)",
419 cmd->getCString(), fileName->getCString(), line);
423 deleteGList(tokens, GString);
428 void GlobalParams::parseNameToUnicode(GList *tokens, GString *fileName,
437 if (tokens->getLength() != 2) {
438 error(-1, "Bad 'nameToUnicode' config file command (%s:%d)",
439 fileName->getCString(), line);
442 name = (GString *)tokens->get(1);
443 if (!(f = fopen(name->getCString(), "r"))) {
444 error(-1, "Couldn't open 'nameToUnicode' file '%s'",
449 while (getLine(buf, sizeof(buf), f)) {
450 tok1 = strtok(buf, " \t\r\n");
451 tok2 = strtok(NULL, " \t\r\n");
453 sscanf(tok1, "%x", &u);
454 nameToUnicode->add(tok2, u);
456 error(-1, "Bad line in 'nameToUnicode' file (%s:%d)", name, line2);
463 void GlobalParams::parseCIDToUnicode(GList *tokens, GString *fileName,
465 GString *collection, *name, *old;
467 if (tokens->getLength() != 3) {
468 error(-1, "Bad 'cidToUnicode' config file command (%s:%d)",
469 fileName->getCString(), line);
472 collection = (GString *)tokens->get(1);
473 name = (GString *)tokens->get(2);
474 if ((old = (GString *)cidToUnicodes->remove(collection))) {
477 cidToUnicodes->add(collection->copy(), name->copy());
480 void GlobalParams::parseUnicodeMap(GList *tokens, GString *fileName,
482 GString *encodingName, *name, *old;
484 if (tokens->getLength() != 3) {
485 error(-1, "Bad 'unicodeMap' config file command (%s:%d)",
486 fileName->getCString(), line);
489 encodingName = (GString *)tokens->get(1);
490 name = (GString *)tokens->get(2);
491 if ((old = (GString *)unicodeMaps->remove(encodingName))) {
494 unicodeMaps->add(encodingName->copy(), name->copy());
497 void GlobalParams::parseCMapDir(GList *tokens, GString *fileName, int line) {
498 GString *collection, *dir;
501 if (tokens->getLength() != 3) {
502 error(-1, "Bad 'cMapDir' config file command (%s:%d)",
503 fileName->getCString(), line);
506 collection = (GString *)tokens->get(1);
507 dir = (GString *)tokens->get(2);
508 if (!(list = (GList *)cMapDirs->lookup(collection))) {
510 cMapDirs->add(collection->copy(), list);
512 list->append(dir->copy());
515 void GlobalParams::parseToUnicodeDir(GList *tokens, GString *fileName,
517 if (tokens->getLength() != 2) {
518 error(-1, "Bad 'toUnicodeDir' config file command (%s:%d)",
519 fileName->getCString(), line);
522 toUnicodeDirs->append(((GString *)tokens->get(1))->copy());
525 void GlobalParams::parseDisplayFont(GList *tokens, GHash *fontHash,
526 DisplayFontParamKind kind,
527 GString *fileName, int line) {
528 DisplayFontParam *param, *old;
530 if (tokens->getLength() < 2) {
533 param = new DisplayFontParam(((GString *)tokens->get(1))->copy(), kind);
537 if (tokens->getLength() != 4) {
540 param->x.xlfd = ((GString *)tokens->get(2))->copy();
541 param->x.encoding = ((GString *)tokens->get(3))->copy();
544 if (tokens->getLength() != 3) {
547 param->t1.fileName = ((GString *)tokens->get(2))->copy();
550 if (tokens->getLength() != 3) {
553 param->tt.fileName = ((GString *)tokens->get(2))->copy();
557 if ((old = (DisplayFontParam *)fontHash->remove(param->name))) {
560 fontHash->add(param->name, param);
566 error(-1, "Bad 'display*Font*' config file command (%s:%d)",
567 fileName->getCString(), line);
570 void GlobalParams::parsePSPaperSize(GList *tokens, GString *fileName,
574 if (tokens->getLength() == 2) {
575 tok = (GString *)tokens->get(1);
576 if (!setPSPaperSize(tok->getCString())) {
577 error(-1, "Bad 'psPaperSize' config file command (%s:%d)",
578 fileName->getCString(), line);
580 } else if (tokens->getLength() == 3) {
581 tok = (GString *)tokens->get(1);
582 psPaperWidth = atoi(tok->getCString());
583 tok = (GString *)tokens->get(2);
584 psPaperHeight = atoi(tok->getCString());
586 error(-1, "Bad 'psPaperSize' config file command (%s:%d)",
587 fileName->getCString(), line);
591 void GlobalParams::parsePSLevel(GList *tokens, GString *fileName, int line) {
594 if (tokens->getLength() != 2) {
595 error(-1, "Bad 'psLevel' config file command (%s:%d)",
596 fileName->getCString(), line);
599 tok = (GString *)tokens->get(1);
600 if (!tok->cmp("level1")) {
602 } else if (!tok->cmp("level1sep")) {
603 psLevel = psLevel1Sep;
604 } else if (!tok->cmp("level2")) {
606 } else if (!tok->cmp("level2sep")) {
607 psLevel = psLevel2Sep;
608 } else if (!tok->cmp("level3")) {
610 } else if (!tok->cmp("level3Sep")) {
611 psLevel = psLevel3Sep;
613 error(-1, "Bad 'psLevel' config file command (%s:%d)",
614 fileName->getCString(), line);
618 void GlobalParams::parsePSFile(GList *tokens, GString *fileName, int line) {
619 if (tokens->getLength() != 2) {
620 error(-1, "Bad 'psFile' config file command (%s:%d)",
621 fileName->getCString(), line);
627 psFile = ((GString *)tokens->get(1))->copy();
630 void GlobalParams::parsePSFont(GList *tokens, GString *fileName, int line) {
633 if (tokens->getLength() != 3) {
634 error(-1, "Bad 'psFont' config file command (%s:%d)",
635 fileName->getCString(), line);
638 param = new PSFontParam(((GString *)tokens->get(1))->copy(), 0,
639 ((GString *)tokens->get(2))->copy(), NULL);
640 psFonts->add(param->pdfFontName, param);
643 void GlobalParams::parsePSFont16(char *cmdName, GList *fontList,
644 GList *tokens, GString *fileName, int line) {
649 if (tokens->getLength() != 5) {
650 error(-1, "Bad '%s' config file command (%s:%d)",
651 cmdName, fileName->getCString(), line);
654 tok = (GString *)tokens->get(2);
655 if (!tok->cmp("H")) {
657 } else if (!tok->cmp("V")) {
660 error(-1, "Bad '%s' config file command (%s:%d)",
661 cmdName, fileName->getCString(), line);
664 param = new PSFontParam(((GString *)tokens->get(1))->copy(),
666 ((GString *)tokens->get(3))->copy(),
667 ((GString *)tokens->get(4))->copy());
668 fontList->append(param);
671 void GlobalParams::parseTextEncoding(GList *tokens, GString *fileName,
673 if (tokens->getLength() != 2) {
674 error(-1, "Bad 'textEncoding' config file command (%s:%d)",
675 fileName->getCString(), line);
679 textEncoding = ((GString *)tokens->get(1))->copy();
682 void GlobalParams::parseTextEOL(GList *tokens, GString *fileName, int line) {
685 if (tokens->getLength() != 2) {
686 error(-1, "Bad 'textEOL' config file command (%s:%d)",
687 fileName->getCString(), line);
690 tok = (GString *)tokens->get(1);
691 if (!tok->cmp("unix")) {
693 } else if (!tok->cmp("dos")) {
695 } else if (!tok->cmp("mac")) {
698 error(-1, "Bad 'textEOL' config file command (%s:%d)",
699 fileName->getCString(), line);
703 void GlobalParams::parseFontDir(GList *tokens, GString *fileName, int line) {
704 if (tokens->getLength() != 2) {
705 error(-1, "Bad 'fontDir' config file command (%s:%d)",
706 fileName->getCString(), line);
709 fontDirs->append(((GString *)tokens->get(1))->copy());
712 void GlobalParams::parseInitialZoom(GList *tokens,
713 GString *fileName, int line) {
714 if (tokens->getLength() != 2) {
715 error(-1, "Bad 'initialZoom' config file command (%s:%d)",
716 fileName->getCString(), line);
720 initialZoom = ((GString *)tokens->get(1))->copy();
723 void GlobalParams::parseFontRastControl(char *cmdName, FontRastControl *val,
724 GList *tokens, GString *fileName,
728 if (tokens->getLength() != 2) {
729 error(-1, "Bad '%s' config file command (%s:%d)",
730 cmdName, fileName->getCString(), line);
733 tok = (GString *)tokens->get(1);
734 if (!setFontRastControl(val, tok->getCString())) {
735 error(-1, "Bad '%s' config file command (%s:%d)",
736 cmdName, fileName->getCString(), line);
740 void GlobalParams::parseCommand(char *cmdName, GString **val,
741 GList *tokens, GString *fileName, int line) {
742 if (tokens->getLength() != 2) {
743 error(-1, "Bad '%s' config file command (%s:%d)",
744 cmdName, fileName->getCString(), line);
750 *val = ((GString *)tokens->get(1))->copy();
753 void GlobalParams::parseYesNo(char *cmdName, GBool *flag,
754 GList *tokens, GString *fileName, int line) {
757 if (tokens->getLength() != 2) {
758 error(-1, "Bad '%s' config file command (%s:%d)",
759 cmdName, fileName->getCString(), line);
762 tok = (GString *)tokens->get(1);
763 if (!tok->cmp("yes")) {
765 } else if (!tok->cmp("no")) {
768 error(-1, "Bad '%s' config file command (%s:%d)",
769 cmdName, fileName->getCString(), line);
773 GlobalParams::~GlobalParams() {
778 freeBuiltinFontTables();
780 delete macRomanReverseMap;
782 delete nameToUnicode;
783 deleteGHash(cidToUnicodes, GString);
784 deleteGHash(residentUnicodeMaps, UnicodeMap);
785 deleteGHash(unicodeMaps, GString);
786 deleteGList(toUnicodeDirs, GString);
787 deleteGHash(displayFonts, DisplayFontParam);
788 deleteGHash(displayCIDFonts, DisplayFontParam);
789 deleteGHash(displayNamedCIDFonts, DisplayFontParam);
793 deleteGHash(psFonts, PSFontParam);
794 deleteGList(psNamedFonts16, PSFontParam);
795 deleteGList(psFonts16, PSFontParam);
797 deleteGList(fontDirs, GString);
806 cMapDirs->startIter(&iter);
807 while (cMapDirs->getNext(&iter, &key, (void **)&list)) {
808 deleteGList(list, GString);
812 delete cidToUnicodeCache;
813 delete unicodeMapCache;
817 gDestroyMutex(&mutex);
821 //------------------------------------------------------------------------
823 //------------------------------------------------------------------------
825 CharCode GlobalParams::getMacRomanCharCode(char *charName) {
826 return macRomanReverseMap->lookup(charName);
829 Unicode GlobalParams::mapNameToUnicode(char *charName) {
830 return nameToUnicode->lookup(charName);
833 FILE *GlobalParams::getCIDToUnicodeFile(GString *collection) {
836 if (!(fileName = (GString *)cidToUnicodes->lookup(collection))) {
839 return fopen(fileName->getCString(), "r");
842 UnicodeMap *GlobalParams::getResidentUnicodeMap(GString *encodingName) {
843 return (UnicodeMap *)residentUnicodeMaps->lookup(encodingName);
846 FILE *GlobalParams::getUnicodeMapFile(GString *encodingName) {
849 if (!(fileName = (GString *)unicodeMaps->lookup(encodingName))) {
852 return fopen(fileName->getCString(), "r");
855 FILE *GlobalParams::findCMapFile(GString *collection, GString *cMapName) {
862 if (!(list = (GList *)cMapDirs->lookup(collection))) {
865 for (i = 0; i < list->getLength(); ++i) {
866 dir = (GString *)list->get(i);
867 fileName = appendToPath(dir->copy(), cMapName->getCString());
868 f = fopen(fileName->getCString(), "r");
877 FILE *GlobalParams::findToUnicodeFile(GString *name) {
878 GString *dir, *fileName;
882 for (i = 0; i < toUnicodeDirs->getLength(); ++i) {
883 dir = (GString *)toUnicodeDirs->get(i);
884 fileName = appendToPath(dir->copy(), name->getCString());
885 f = fopen(fileName->getCString(), "r");
894 DisplayFontParam *GlobalParams::getDisplayFont(GString *fontName) {
895 DisplayFontParam *dfp;
898 dfp = (DisplayFontParam *)displayFonts->lookup(fontName);
903 DisplayFontParam *GlobalParams::getDisplayCIDFont(GString *fontName,
904 GString *collection) {
905 DisplayFontParam *dfp;
908 !(dfp = (DisplayFontParam *)displayNamedCIDFonts->lookup(fontName))) {
909 dfp = (DisplayFontParam *)displayCIDFonts->lookup(collection);
914 GString *GlobalParams::getPSFile() {
918 s = psFile ? psFile->copy() : (GString *)NULL;
923 int GlobalParams::getPSPaperWidth() {
932 int GlobalParams::getPSPaperHeight() {
941 GBool GlobalParams::getPSDuplex() {
950 PSLevel GlobalParams::getPSLevel() {
959 PSFontParam *GlobalParams::getPSFont(GString *fontName) {
960 return (PSFontParam *)psFonts->lookup(fontName);
963 PSFontParam *GlobalParams::getPSFont16(GString *fontName,
964 GString *collection, int wMode) {
970 for (i = 0; i < psNamedFonts16->getLength(); ++i) {
971 p = (PSFontParam *)psNamedFonts16->get(i);
972 if (!p->pdfFontName->cmp(fontName) &&
979 if (!p && collection) {
980 for (i = 0; i < psFonts16->getLength(); ++i) {
981 p = (PSFontParam *)psFonts16->get(i);
982 if (!p->pdfFontName->cmp(collection) &&
992 GBool GlobalParams::getPSEmbedType1() {
1001 GBool GlobalParams::getPSEmbedTrueType() {
1005 e = psEmbedTrueType;
1010 GBool GlobalParams::getPSEmbedCIDPostScript() {
1014 e = psEmbedCIDPostScript;
1019 GBool GlobalParams::getPSEmbedCIDTrueType() {
1023 e = psEmbedCIDTrueType;
1028 GBool GlobalParams::getPSOPI() {
1037 GBool GlobalParams::getPSASCIIHex() {
1046 EndOfLineKind GlobalParams::getTextEOL() {
1055 GBool GlobalParams::getTextKeepTinyChars() {
1059 tiny = textKeepTinyChars;
1064 GString *GlobalParams::findFontFile(GString *fontName,
1065 char *ext1, char *ext2) {
1066 GString *dir, *fileName;
1070 for (i = 0; i < fontDirs->getLength(); ++i) {
1071 dir = (GString *)fontDirs->get(i);
1073 fileName = appendToPath(dir->copy(), fontName->getCString());
1074 fileName->append(ext1);
1075 if ((f = fopen(fileName->getCString(), "r"))) {
1082 fileName = appendToPath(dir->copy(), fontName->getCString());
1083 fileName->append(ext2);
1084 if ((f = fopen(fileName->getCString(), "r"))) {
1094 GString *GlobalParams::getInitialZoom() {
1098 s = initialZoom->copy();
1103 FontRastControl GlobalParams::getT1libControl() {
1112 FontRastControl GlobalParams::getFreeTypeControl() {
1116 c = freetypeControl;
1121 GBool GlobalParams::getMapNumericCharNames() {
1125 map = mapNumericCharNames;
1130 GBool GlobalParams::getPrintCommands() {
1139 GBool GlobalParams::getErrQuiet() {
1148 CharCodeToUnicode *GlobalParams::getCIDToUnicode(GString *collection) {
1149 CharCodeToUnicode *ctu;
1152 ctu = cidToUnicodeCache->getCIDToUnicode(collection);
1157 UnicodeMap *GlobalParams::getUnicodeMap(GString *encodingName) {
1161 map = getUnicodeMap2(encodingName);
1166 UnicodeMap *GlobalParams::getUnicodeMap2(GString *encodingName) {
1169 if ((map = getResidentUnicodeMap(encodingName))) {
1172 map = unicodeMapCache->getUnicodeMap(encodingName);
1177 CMap *GlobalParams::getCMap(GString *collection, GString *cMapName) {
1181 cMap = cMapCache->getCMap(collection, cMapName);
1186 UnicodeMap *GlobalParams::getTextEncoding() {
1190 map = getUnicodeMap2(textEncoding);
1195 //------------------------------------------------------------------------
1196 // functions to set parameters
1197 //------------------------------------------------------------------------
1199 void GlobalParams::addDisplayFont(DisplayFontParam *param) {
1200 DisplayFontParam *old;
1203 if ((old = (DisplayFontParam *)displayFonts->remove(param->name))) {
1206 displayFonts->add(param->name, param);
1210 void GlobalParams::setPSFile(char *file) {
1215 psFile = new GString(file);
1219 GBool GlobalParams::setPSPaperSize(char *size) {
1221 if (!strcmp(size, "letter")) {
1223 psPaperHeight = 792;
1224 } else if (!strcmp(size, "legal")) {
1226 psPaperHeight = 1008;
1227 } else if (!strcmp(size, "A4")) {
1229 psPaperHeight = 842;
1230 } else if (!strcmp(size, "A3")) {
1232 psPaperHeight = 1190;
1241 void GlobalParams::setPSPaperWidth(int width) {
1243 psPaperWidth = width;
1247 void GlobalParams::setPSPaperHeight(int height) {
1249 psPaperHeight = height;
1253 void GlobalParams::setPSDuplex(GBool duplex) {
1259 void GlobalParams::setPSLevel(PSLevel level) {
1265 void GlobalParams::setPSEmbedType1(GBool embed) {
1267 psEmbedType1 = embed;
1271 void GlobalParams::setPSEmbedTrueType(GBool embed) {
1273 psEmbedTrueType = embed;
1277 void GlobalParams::setPSEmbedCIDPostScript(GBool embed) {
1279 psEmbedCIDPostScript = embed;
1283 void GlobalParams::setPSEmbedCIDTrueType(GBool embed) {
1285 psEmbedCIDTrueType = embed;
1289 void GlobalParams::setPSOPI(GBool opi) {
1295 void GlobalParams::setPSASCIIHex(GBool hex) {
1301 void GlobalParams::setTextEncoding(char *encodingName) {
1303 delete textEncoding;
1304 textEncoding = new GString(encodingName);
1308 GBool GlobalParams::setTextEOL(char *s) {
1310 if (!strcmp(s, "unix")) {
1312 } else if (!strcmp(s, "dos")) {
1314 } else if (!strcmp(s, "mac")) {
1324 void GlobalParams::setTextKeepTinyChars(GBool keep) {
1326 textKeepTinyChars = keep;
1330 void GlobalParams::setInitialZoom(char *s) {
1333 initialZoom = new GString(s);
1337 GBool GlobalParams::setT1libControl(char *s) {
1341 ok = setFontRastControl(&t1libControl, s);
1346 GBool GlobalParams::setFreeTypeControl(char *s) {
1350 ok = setFontRastControl(&freetypeControl, s);
1355 GBool GlobalParams::setFontRastControl(FontRastControl *val, char *s) {
1356 if (!strcmp(s, "none")) {
1357 *val = fontRastNone;
1358 } else if (!strcmp(s, "plain")) {
1359 *val = fontRastPlain;
1360 } else if (!strcmp(s, "low")) {
1361 *val = fontRastAALow;
1362 } else if (!strcmp(s, "high")) {
1363 *val = fontRastAAHigh;
1370 void GlobalParams::setMapNumericCharNames(GBool map) {
1372 mapNumericCharNames = map;
1376 void GlobalParams::setPrintCommands(GBool printCommandsA) {
1378 printCommands = printCommandsA;
1382 void GlobalParams::setErrQuiet(GBool errQuietA) {
1384 errQuiet = errQuietA;