1 //========================================================================
5 // Copyright 2001-2002 Glyph & Cog, LLC
7 //========================================================================
10 #pragma implementation
25 #include "NameToCharCode.h"
26 #include "CharCodeToUnicode.h"
27 #include "UnicodeMap.h"
29 #include "BuiltinFontTables.h"
30 #include "FontEncodingTables.h"
31 #include "GlobalParams.h"
33 #include "NameToUnicodeTable.h"
34 #include "UnicodeMapTables.h"
35 #include "DisplayFontTable.h"
38 //------------------------------------------------------------------------
40 GlobalParams *globalParams = NULL;
42 //------------------------------------------------------------------------
44 //------------------------------------------------------------------------
46 DisplayFontParam::DisplayFontParam(GString *nameA,
47 DisplayFontParamKind kindA) {
64 DisplayFontParam::DisplayFontParam(char *nameA, char *xlfdA, char *encodingA) {
65 name = new GString(nameA);
67 x.xlfd = new GString(xlfdA);
68 x.encoding = new GString(encodingA);
71 DisplayFontParam::~DisplayFontParam() {
95 //------------------------------------------------------------------------
97 //------------------------------------------------------------------------
99 PSFontParam::PSFontParam(GString *pdfFontNameA, int wModeA,
100 GString *psFontNameA, GString *encodingA) {
101 pdfFontName = pdfFontNameA;
103 psFontName = psFontNameA;
104 encoding = encodingA;
107 PSFontParam::~PSFontParam() {
115 //------------------------------------------------------------------------
117 //------------------------------------------------------------------------
119 GlobalParams::GlobalParams(char *cfgFileName) {
121 DisplayFontParam *dfp;
126 initBuiltinFontTables();
128 // scan the encoding in reverse because we want the lowest-numbered
129 // index for each char name ('space' is encoded twice)
130 macRomanReverseMap = new NameToCharCode();
131 for (i = 255; i >= 0; --i) {
132 if (macRomanEncoding[i]) {
133 macRomanReverseMap->add(macRomanEncoding[i], (CharCode)i);
137 nameToUnicode = new NameToCharCode();
138 cidToUnicodes = new GHash(gTrue);
139 residentUnicodeMaps = new GHash();
140 unicodeMaps = new GHash(gTrue);
141 cMapDirs = new GHash(gTrue);
142 toUnicodeDirs = new GList();
143 displayFonts = new GHash();
144 displayCIDFonts = new GHash();
145 displayNamedCIDFonts = new GHash();
147 const struct paper *paperType;
149 paperType = paperinfo(systempapername());
150 psPaperWidth = (int)paperpswidth(paperType);
151 psPaperHeight = (int)paperpsheight(paperType);
154 psPaperWidth = defPaperWidth;
155 psPaperHeight = defPaperHeight;
160 psFonts = new GHash();
161 psNamedFonts16 = new GList();
162 psFonts16 = new GList();
163 psEmbedType1 = gTrue;
164 psEmbedTrueType = gTrue;
165 psEmbedCIDPostScript = gTrue;
166 psEmbedCIDTrueType = gTrue;
169 textEncoding = new GString("Latin1");
177 fontDirs = new GList();
178 initialZoom = new GString("1");
179 t1libControl = fontRastAALow;
180 freetypeControl = fontRastAALow;
182 mapNumericCharNames = gTrue;
185 cidToUnicodeCache = new CIDToUnicodeCache();
186 unicodeMapCache = new UnicodeMapCache();
187 cMapCache = new CMapCache();
189 // set up the initial nameToUnicode table
190 for (i = 0; nameToUnicodeTab[i].name; ++i) {
191 nameToUnicode->add(nameToUnicodeTab[i].name, nameToUnicodeTab[i].u);
194 // set up the residentUnicodeMaps table
195 map = new UnicodeMap("Latin1", latin1UnicodeMapRanges, latin1UnicodeMapLen);
196 residentUnicodeMaps->add(map->getEncodingName(), map);
197 map = new UnicodeMap("ASCII7", ascii7UnicodeMapRanges, ascii7UnicodeMapLen);
198 residentUnicodeMaps->add(map->getEncodingName(), map);
199 map = new UnicodeMap("Symbol", symbolUnicodeMapRanges, symbolUnicodeMapLen);
200 residentUnicodeMaps->add(map->getEncodingName(), map);
201 map = new UnicodeMap("ZapfDingbats", zapfDingbatsUnicodeMapRanges,
202 zapfDingbatsUnicodeMapLen);
203 residentUnicodeMaps->add(map->getEncodingName(), map);
204 map = new UnicodeMap("UTF-8", &mapUTF8);
205 residentUnicodeMaps->add(map->getEncodingName(), map);
206 map = new UnicodeMap("UCS-2", &mapUCS2);
207 residentUnicodeMaps->add(map->getEncodingName(), map);
209 // default displayFonts table
210 for (i = 0; displayFontTab[i].name; ++i) {
211 dfp = new DisplayFontParam(displayFontTab[i].name,
212 displayFontTab[i].xlfd,
213 displayFontTab[i].encoding);
214 displayFonts->add(dfp->name, dfp);
217 // look for a user config file, then a system-wide config file
220 if (cfgFileName && cfgFileName[0]) {
221 fileName = new GString(cfgFileName);
222 if (!(f = fopen(fileName->getCString(), "r"))) {
227 fileName = appendToPath(getHomeDir(), xpdfUserConfigFile);
228 if (!(f = fopen(fileName->getCString(), "r"))) {
233 #if defined(WIN32) && !defined(__CYGWIN32__)
235 i = GetModuleFileName(NULL, buf, sizeof(buf));
236 if (i <= 0 || i >= sizeof(buf)) {
237 // error or path too long for buffer - just use the current dir
240 fileName = grabPath(buf);
241 appendToPath(fileName, xpdfSysConfigFile);
243 fileName = new GString(xpdfSysConfigFile);
245 if (!(f = fopen(fileName->getCString(), "r"))) {
250 parseFile(fileName, f);
255 void GlobalParams::parseFile(GString *fileName, FILE *f) {
258 GString *cmd, *incFile;
264 while (fgets(buf, sizeof(buf) - 1, f)) {
266 // break the line into tokens
267 tokens = new GList();
270 for (; *p1 && isspace(*p1); ++p1) ;
274 if (*p1 == '"' || *p1 == '\'') {
275 for (p2 = p1 + 1; *p2 && *p2 != *p1; ++p2) ;
278 for (p2 = p1 + 1; *p2 && !isspace(*p2); ++p2) ;
280 tokens->append(new GString(p1, p2 - p1));
284 if (tokens->getLength() > 0 &&
285 ((GString *)tokens->get(0))->getChar(0) != '#') {
286 cmd = (GString *)tokens->get(0);
287 if (!cmd->cmp("include")) {
288 if (tokens->getLength() == 2) {
289 incFile = (GString *)tokens->get(1);
290 if ((f2 = fopen(incFile->getCString(), "r"))) {
291 parseFile(incFile, f2);
294 error(-1, "Couldn't find included config file: '%s' (%s:%d)",
295 incFile->getCString(), fileName->getCString(), line);
298 error(-1, "Bad 'include' config file command (%s:%d)",
299 fileName->getCString(), line);
301 } else if (!cmd->cmp("nameToUnicode")) {
302 parseNameToUnicode(tokens, fileName, line);
303 } else if (!cmd->cmp("cidToUnicode")) {
304 parseCIDToUnicode(tokens, fileName, line);
305 } else if (!cmd->cmp("unicodeMap")) {
306 parseUnicodeMap(tokens, fileName, line);
307 } else if (!cmd->cmp("cMapDir")) {
308 parseCMapDir(tokens, fileName, line);
309 } else if (!cmd->cmp("toUnicodeDir")) {
310 parseToUnicodeDir(tokens, fileName, line);
311 } else if (!cmd->cmp("displayFontX")) {
312 parseDisplayFont(tokens, displayFonts, displayFontX, fileName, line);
313 } else if (!cmd->cmp("displayFontT1")) {
314 parseDisplayFont(tokens, displayFonts, displayFontT1, fileName, line);
315 } else if (!cmd->cmp("displayFontTT")) {
316 parseDisplayFont(tokens, displayFonts, displayFontTT, fileName, line);
317 } else if (!cmd->cmp("displayCIDFontX")) {
318 parseDisplayFont(tokens, displayCIDFonts,
319 displayFontX, fileName, line);
320 } else if (!cmd->cmp("displayNamedCIDFontX")) {
321 parseDisplayFont(tokens, displayNamedCIDFonts,
322 displayFontX, fileName, line);
323 } else if (!cmd->cmp("psFile")) {
324 parsePSFile(tokens, fileName, line);
325 } else if (!cmd->cmp("psFont")) {
326 parsePSFont(tokens, fileName, line);
327 } else if (!cmd->cmp("psNamedFont16")) {
328 parsePSFont16("psNamedFont16", psNamedFonts16,
329 tokens, fileName, line);
330 } else if (!cmd->cmp("psFont16")) {
331 parsePSFont16("psFont16", psFonts16, tokens, fileName, line);
332 } else if (!cmd->cmp("psPaperSize")) {
333 parsePSPaperSize(tokens, fileName, line);
334 } else if (!cmd->cmp("psDuplex")) {
335 parseYesNo("psDuplex", &psDuplex, tokens, fileName, line);
336 } else if (!cmd->cmp("psLevel")) {
337 parsePSLevel(tokens, fileName, line);
338 } else if (!cmd->cmp("psEmbedType1Fonts")) {
339 parseYesNo("psEmbedType1", &psEmbedType1, tokens, fileName, line);
340 } else if (!cmd->cmp("psEmbedTrueTypeFonts")) {
341 parseYesNo("psEmbedTrueType", &psEmbedTrueType,
342 tokens, fileName, line);
343 } else if (!cmd->cmp("psEmbedCIDPostScriptFonts")) {
344 parseYesNo("psEmbedCIDPostScript", &psEmbedCIDPostScript,
345 tokens, fileName, line);
346 } else if (!cmd->cmp("psEmbedCIDTrueTypeFonts")) {
347 parseYesNo("psEmbedCIDTrueType", &psEmbedCIDTrueType,
348 tokens, fileName, line);
349 } else if (!cmd->cmp("psOPI")) {
350 parseYesNo("psOPI", &psOPI, tokens, fileName, line);
351 } else if (!cmd->cmp("psASCIIHex")) {
352 parseYesNo("psASCIIHex", &psASCIIHex, tokens, fileName, line);
353 } else if (!cmd->cmp("textEncoding")) {
354 parseTextEncoding(tokens, fileName, line);
355 } else if (!cmd->cmp("textEOL")) {
356 parseTextEOL(tokens, fileName, line);
357 } else if (!cmd->cmp("fontDir")) {
358 parseFontDir(tokens, fileName, line);
359 } else if (!cmd->cmp("initialZoom")) {
360 parseInitialZoom(tokens, fileName, line);
361 } else if (!cmd->cmp("t1libControl")) {
362 parseFontRastControl("t1libControl", &t1libControl,
363 tokens, fileName, line);
364 } else if (!cmd->cmp("freetypeControl")) {
365 parseFontRastControl("freetypeControl", &freetypeControl,
366 tokens, fileName, line);
367 } else if (!cmd->cmp("urlCommand")) {
368 parseURLCommand(tokens, fileName, line);
369 } else if (!cmd->cmp("mapNumericCharNames")) {
370 parseYesNo("mapNumericCharNames", &mapNumericCharNames,
371 tokens, fileName, line);
372 } else if (!cmd->cmp("errQuiet")) {
373 parseYesNo("errQuiet", &errQuiet, tokens, fileName, line);
374 } else if (!cmd->cmp("fontpath") || !cmd->cmp("fontmap")) {
375 error(-1, "Unknown config file command");
376 error(-1, "-- the config file format has changed since Xpdf 0.9x");
378 error(-1, "Unknown config file command '%s' (%s:%d)",
379 cmd->getCString(), fileName->getCString(), line);
383 deleteGList(tokens, GString);
388 void GlobalParams::parseNameToUnicode(GList *tokens, GString *fileName,
397 if (tokens->getLength() != 2) {
398 error(-1, "Bad 'nameToUnicode' config file command (%s:%d)",
399 fileName->getCString(), line);
402 name = (GString *)tokens->get(1);
403 if (!(f = fopen(name->getCString(), "r"))) {
404 error(-1, "Couldn't open 'nameToUnicode' file '%s'",
409 while (fgets(buf, sizeof(buf), f)) {
410 tok1 = strtok(buf, " \t\r\n");
411 tok2 = strtok(NULL, " \t\r\n");
413 sscanf(tok1, "%x", &u);
414 nameToUnicode->add(tok2, u);
416 error(-1, "Bad line in 'nameToUnicode' file (%s:%d)", name, line2);
423 void GlobalParams::parseCIDToUnicode(GList *tokens, GString *fileName,
425 GString *collection, *name, *old;
427 if (tokens->getLength() != 3) {
428 error(-1, "Bad 'cidToUnicode' config file command (%s:%d)",
429 fileName->getCString(), line);
432 collection = (GString *)tokens->get(1);
433 name = (GString *)tokens->get(2);
434 if ((old = (GString *)cidToUnicodes->remove(collection))) {
437 cidToUnicodes->add(collection->copy(), name->copy());
440 void GlobalParams::parseUnicodeMap(GList *tokens, GString *fileName,
442 GString *encodingName, *name, *old;
444 if (tokens->getLength() != 3) {
445 error(-1, "Bad 'unicodeMap' config file command (%s:%d)",
446 fileName->getCString(), line);
449 encodingName = (GString *)tokens->get(1);
450 name = (GString *)tokens->get(2);
451 if ((old = (GString *)unicodeMaps->remove(encodingName))) {
454 unicodeMaps->add(encodingName->copy(), name->copy());
457 void GlobalParams::parseCMapDir(GList *tokens, GString *fileName, int line) {
458 GString *collection, *dir;
461 if (tokens->getLength() != 3) {
462 error(-1, "Bad 'cMapDir' config file command (%s:%d)",
463 fileName->getCString(), line);
466 collection = (GString *)tokens->get(1);
467 dir = (GString *)tokens->get(2);
468 if (!(list = (GList *)cMapDirs->lookup(collection))) {
470 cMapDirs->add(collection->copy(), list);
472 list->append(dir->copy());
475 void GlobalParams::parseToUnicodeDir(GList *tokens, GString *fileName,
477 if (tokens->getLength() != 2) {
478 error(-1, "Bad 'toUnicodeDir' config file command (%s:%d)",
479 fileName->getCString(), line);
482 toUnicodeDirs->append(((GString *)tokens->get(1))->copy());
485 void GlobalParams::parseDisplayFont(GList *tokens, GHash *fontHash,
486 DisplayFontParamKind kind,
487 GString *fileName, int line) {
488 DisplayFontParam *param, *old;
490 if (tokens->getLength() < 2) {
493 param = new DisplayFontParam(((GString *)tokens->get(1))->copy(), kind);
497 if (tokens->getLength() != 4) {
500 param->x.xlfd = ((GString *)tokens->get(2))->copy();
501 param->x.encoding = ((GString *)tokens->get(3))->copy();
504 if (tokens->getLength() != 3) {
507 param->t1.fileName = ((GString *)tokens->get(2))->copy();
510 if (tokens->getLength() != 3) {
513 param->tt.fileName = ((GString *)tokens->get(2))->copy();
517 if ((old = (DisplayFontParam *)fontHash->remove(param->name))) {
520 fontHash->add(param->name, param);
526 error(-1, "Bad 'display*Font*' config file command (%s:%d)",
527 fileName->getCString(), line);
530 void GlobalParams::parsePSPaperSize(GList *tokens, GString *fileName,
534 if (tokens->getLength() == 2) {
535 tok = (GString *)tokens->get(1);
536 if (!setPSPaperSize(tok->getCString())) {
537 error(-1, "Bad 'psPaperSize' config file command (%s:%d)",
538 fileName->getCString(), line);
540 } else if (tokens->getLength() == 3) {
541 tok = (GString *)tokens->get(1);
542 psPaperWidth = atoi(tok->getCString());
543 tok = (GString *)tokens->get(2);
544 psPaperHeight = atoi(tok->getCString());
546 error(-1, "Bad 'psPaperSize' config file command (%s:%d)",
547 fileName->getCString(), line);
551 void GlobalParams::parsePSLevel(GList *tokens, GString *fileName, int line) {
554 if (tokens->getLength() != 2) {
555 error(-1, "Bad 'psLevel' config file command (%s:%d)",
556 fileName->getCString(), line);
559 tok = (GString *)tokens->get(1);
560 if (!tok->cmp("level1")) {
562 } else if (!tok->cmp("level1sep")) {
563 psLevel = psLevel1Sep;
564 } else if (!tok->cmp("level2")) {
566 } else if (!tok->cmp("level2sep")) {
567 psLevel = psLevel2Sep;
568 } else if (!tok->cmp("level3")) {
570 } else if (!tok->cmp("level3Sep")) {
571 psLevel = psLevel3Sep;
573 error(-1, "Bad 'psLevel' config file command (%s:%d)",
574 fileName->getCString(), line);
578 void GlobalParams::parsePSFile(GList *tokens, GString *fileName, int line) {
579 if (tokens->getLength() != 2) {
580 error(-1, "Bad 'psFile' config file command (%s:%d)",
581 fileName->getCString(), line);
587 psFile = ((GString *)tokens->get(1))->copy();
590 void GlobalParams::parsePSFont(GList *tokens, GString *fileName, int line) {
593 if (tokens->getLength() != 3) {
594 error(-1, "Bad 'psFont' config file command (%s:%d)",
595 fileName->getCString(), line);
598 param = new PSFontParam(((GString *)tokens->get(1))->copy(), 0,
599 ((GString *)tokens->get(2))->copy(), NULL);
600 psFonts->add(param->pdfFontName, param);
603 void GlobalParams::parsePSFont16(char *cmdName, GList *fontList,
604 GList *tokens, GString *fileName, int line) {
609 if (tokens->getLength() != 5) {
610 error(-1, "Bad '%s' config file command (%s:%d)",
611 cmdName, fileName->getCString(), line);
614 tok = (GString *)tokens->get(2);
615 if (!tok->cmp("H")) {
617 } else if (!tok->cmp("V")) {
620 error(-1, "Bad '%s' config file command (%s:%d)",
621 cmdName, fileName->getCString(), line);
624 param = new PSFontParam(((GString *)tokens->get(1))->copy(),
626 ((GString *)tokens->get(3))->copy(),
627 ((GString *)tokens->get(4))->copy());
628 fontList->append(param);
631 void GlobalParams::parseTextEncoding(GList *tokens, GString *fileName,
633 if (tokens->getLength() != 2) {
634 error(-1, "Bad 'textEncoding' config file command (%s:%d)",
635 fileName->getCString(), line);
639 textEncoding = ((GString *)tokens->get(1))->copy();
642 void GlobalParams::parseTextEOL(GList *tokens, GString *fileName, int line) {
645 if (tokens->getLength() != 2) {
646 error(-1, "Bad 'textEOL' config file command (%s:%d)",
647 fileName->getCString(), line);
650 tok = (GString *)tokens->get(1);
651 if (!tok->cmp("unix")) {
653 } else if (!tok->cmp("dos")) {
655 } else if (!tok->cmp("mac")) {
658 error(-1, "Bad 'textEOL' config file command (%s:%d)",
659 fileName->getCString(), line);
663 void GlobalParams::parseFontDir(GList *tokens, GString *fileName, int line) {
664 if (tokens->getLength() != 2) {
665 error(-1, "Bad 'fontDir' config file command (%s:%d)",
666 fileName->getCString(), line);
669 fontDirs->append(((GString *)tokens->get(1))->copy());
672 void GlobalParams::parseInitialZoom(GList *tokens,
673 GString *fileName, int line) {
674 if (tokens->getLength() != 2) {
675 error(-1, "Bad 'initialZoom' config file command (%s:%d)",
676 fileName->getCString(), line);
680 initialZoom = ((GString *)tokens->get(1))->copy();
683 void GlobalParams::parseFontRastControl(char *cmdName, FontRastControl *val,
684 GList *tokens, GString *fileName,
688 if (tokens->getLength() != 2) {
689 error(-1, "Bad '%s' config file command (%s:%d)",
690 cmdName, fileName->getCString(), line);
693 tok = (GString *)tokens->get(1);
694 if (!setFontRastControl(val, tok->getCString())) {
695 error(-1, "Bad '%s' config file command (%s:%d)",
696 cmdName, fileName->getCString(), line);
700 void GlobalParams::parseURLCommand(GList *tokens, GString *fileName,
702 if (tokens->getLength() != 2) {
703 error(-1, "Bad 'urlCommand' config file command (%s:%d)",
704 fileName->getCString(), line);
710 urlCommand = ((GString *)tokens->get(1))->copy();
713 void GlobalParams::parseYesNo(char *cmdName, GBool *flag,
714 GList *tokens, GString *fileName, int line) {
717 if (tokens->getLength() != 2) {
718 error(-1, "Bad '%s' config file command (%s:%d)",
719 cmdName, fileName->getCString(), line);
722 tok = (GString *)tokens->get(1);
723 if (!tok->cmp("yes")) {
725 } else if (!tok->cmp("no")) {
728 error(-1, "Bad '%s' config file command (%s:%d)",
729 cmdName, fileName->getCString(), line);
733 GlobalParams::~GlobalParams() {
738 freeBuiltinFontTables();
740 delete macRomanReverseMap;
742 delete nameToUnicode;
743 deleteGHash(cidToUnicodes, GString);
744 deleteGHash(residentUnicodeMaps, UnicodeMap);
745 deleteGHash(unicodeMaps, GString);
746 deleteGList(toUnicodeDirs, GString);
747 deleteGHash(displayFonts, DisplayFontParam);
748 deleteGHash(displayCIDFonts, DisplayFontParam);
749 deleteGHash(displayNamedCIDFonts, DisplayFontParam);
753 deleteGHash(psFonts, PSFontParam);
754 deleteGList(psNamedFonts16, PSFontParam);
755 deleteGList(psFonts16, PSFontParam);
757 deleteGList(fontDirs, GString);
763 cMapDirs->startIter(&iter);
764 while (cMapDirs->getNext(&iter, &key, (void **)&list)) {
765 deleteGList(list, GString);
769 delete cidToUnicodeCache;
770 delete unicodeMapCache;
774 //------------------------------------------------------------------------
776 //------------------------------------------------------------------------
778 CharCode GlobalParams::getMacRomanCharCode(char *charName) {
779 return macRomanReverseMap->lookup(charName);
782 Unicode GlobalParams::mapNameToUnicode(char *charName) {
783 return nameToUnicode->lookup(charName);
786 FILE *GlobalParams::getCIDToUnicodeFile(GString *collection) {
789 if (!(fileName = (GString *)cidToUnicodes->lookup(collection))) {
792 return fopen(fileName->getCString(), "r");
795 UnicodeMap *GlobalParams::getResidentUnicodeMap(GString *encodingName) {
796 return (UnicodeMap *)residentUnicodeMaps->lookup(encodingName);
799 FILE *GlobalParams::getUnicodeMapFile(GString *encodingName) {
802 if (!(fileName = (GString *)unicodeMaps->lookup(encodingName))) {
805 return fopen(fileName->getCString(), "r");
808 FILE *GlobalParams::findCMapFile(GString *collection, GString *cMapName) {
815 if (!(list = (GList *)cMapDirs->lookup(collection))) {
818 for (i = 0; i < list->getLength(); ++i) {
819 dir = (GString *)list->get(i);
820 fileName = appendToPath(dir->copy(), cMapName->getCString());
821 f = fopen(fileName->getCString(), "r");
830 FILE *GlobalParams::findToUnicodeFile(GString *name) {
831 GString *dir, *fileName;
835 for (i = 0; i < toUnicodeDirs->getLength(); ++i) {
836 dir = (GString *)toUnicodeDirs->get(i);
837 fileName = appendToPath(dir->copy(), name->getCString());
838 f = fopen(fileName->getCString(), "r");
847 DisplayFontParam *GlobalParams::getDisplayFont(GString *fontName) {
848 return (DisplayFontParam *)displayFonts->lookup(fontName);
851 DisplayFontParam *GlobalParams::getDisplayCIDFont(GString *fontName,
852 GString *collection) {
853 DisplayFontParam *dfp;
856 !(dfp = (DisplayFontParam *)displayNamedCIDFonts->lookup(fontName))) {
857 dfp = (DisplayFontParam *)displayCIDFonts->lookup(collection);
862 PSFontParam *GlobalParams::getPSFont(GString *fontName) {
863 return (PSFontParam *)psFonts->lookup(fontName);
866 PSFontParam *GlobalParams::getPSFont16(GString *fontName,
867 GString *collection, int wMode) {
873 for (i = 0; i < psNamedFonts16->getLength(); ++i) {
874 p = (PSFontParam *)psNamedFonts16->get(i);
875 if (!p->pdfFontName->cmp(fontName) &&
882 if (!p && collection) {
883 for (i = 0; i < psFonts16->getLength(); ++i) {
884 p = (PSFontParam *)psFonts16->get(i);
885 if (!p->pdfFontName->cmp(collection) &&
895 GString *GlobalParams::findFontFile(GString *fontName,
896 char *ext1, char *ext2) {
897 GString *dir, *fileName;
901 for (i = 0; i < fontDirs->getLength(); ++i) {
902 dir = (GString *)fontDirs->get(i);
904 fileName = appendToPath(dir->copy(), fontName->getCString());
905 fileName->append(ext1);
906 if ((f = fopen(fileName->getCString(), "r"))) {
913 fileName = appendToPath(dir->copy(), fontName->getCString());
914 fileName->append(ext2);
915 if ((f = fopen(fileName->getCString(), "r"))) {
925 CharCodeToUnicode *GlobalParams::getCIDToUnicode(GString *collection) {
926 return cidToUnicodeCache->getCIDToUnicode(collection);
929 UnicodeMap *GlobalParams::getUnicodeMap(GString *encodingName) {
932 if ((map = getResidentUnicodeMap(encodingName))) {
936 return unicodeMapCache->getUnicodeMap(encodingName);
939 CMap *GlobalParams::getCMap(GString *collection, GString *cMapName) {
940 return cMapCache->getCMap(collection, cMapName);
943 UnicodeMap *GlobalParams::getTextEncoding() {
944 return getUnicodeMap(textEncoding);
947 //------------------------------------------------------------------------
948 // functions to set parameters
949 //------------------------------------------------------------------------
951 void GlobalParams::setPSFile(char *file) {
955 psFile = new GString(file);
958 GBool GlobalParams::setPSPaperSize(char *size) {
959 if (!strcmp(size, "letter")) {
962 } else if (!strcmp(size, "legal")) {
964 psPaperHeight = 1008;
965 } else if (!strcmp(size, "A4")) {
968 } else if (!strcmp(size, "A3")) {
970 psPaperHeight = 1190;
977 void GlobalParams::setPSPaperWidth(int width) {
978 psPaperWidth = width;
981 void GlobalParams::setPSPaperHeight(int height) {
982 psPaperHeight = height;
985 void GlobalParams::setPSDuplex(GBool duplex) {
989 void GlobalParams::setPSLevel(PSLevel level) {
993 void GlobalParams::setPSEmbedType1(GBool embed) {
994 psEmbedType1 = embed;
997 void GlobalParams::setPSEmbedTrueType(GBool embed) {
998 psEmbedTrueType = embed;
1001 void GlobalParams::setPSEmbedCIDPostScript(GBool embed) {
1002 psEmbedCIDPostScript = embed;
1005 void GlobalParams::setPSEmbedCIDTrueType(GBool embed) {
1006 psEmbedCIDTrueType = embed;
1009 void GlobalParams::setPSOPI(GBool opi) {
1013 void GlobalParams::setPSASCIIHex(GBool hex) {
1017 void GlobalParams::setTextEncoding(char *encodingName) {
1018 delete textEncoding;
1019 textEncoding = new GString(encodingName);
1022 GBool GlobalParams::setTextEOL(char *s) {
1023 if (!strcmp(s, "unix")) {
1025 } else if (!strcmp(s, "dos")) {
1027 } else if (!strcmp(s, "mac")) {
1035 void GlobalParams::setInitialZoom(char *s) {
1037 initialZoom = new GString(s);
1040 GBool GlobalParams::setT1libControl(char *s) {
1041 return setFontRastControl(&t1libControl, s);
1044 GBool GlobalParams::setFreeTypeControl(char *s) {
1045 return setFontRastControl(&freetypeControl, s);
1048 GBool GlobalParams::setFontRastControl(FontRastControl *val, char *s) {
1049 if (!strcmp(s, "none")) {
1050 *val = fontRastNone;
1051 } else if (!strcmp(s, "plain")) {
1052 *val = fontRastPlain;
1053 } else if (!strcmp(s, "low")) {
1054 *val = fontRastAALow;
1055 } else if (!strcmp(s, "high")) {
1056 *val = fontRastAAHigh;
1063 void GlobalParams::setErrQuiet(GBool errQuietA) {
1064 errQuiet = errQuietA;