00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifdef __GNUC__
00010 #pragma implementation
00011 #endif
00012
00013 #include <aconf.h>
00014 #include <string.h>
00015 #include <ctype.h>
00016 #if HAVE_PAPER_H
00017 #include <paper.h>
00018 #endif
00019 #include "gmem.h"
00020 #include "GString.h"
00021 #include "GList.h"
00022 #include "GHash.h"
00023 #include "gfile.h"
00024 #include "Error.h"
00025 #include "NameToCharCode.h"
00026 #include "CharCodeToUnicode.h"
00027 #include "UnicodeMap.h"
00028 #include "CMap.h"
00029 #include "BuiltinFontTables.h"
00030 #include "FontEncodingTables.h"
00031 #include "GlobalParams.h"
00032
00033 #include "NameToUnicodeTable.h"
00034 #include "UnicodeMapTables.h"
00035 #include "DisplayFontTable.h"
00036 #include "UTF8.h"
00037
00038
00039
00040 GlobalParams *globalParams = NULL;
00041
00042
00043
00044
00045
00046 DisplayFontParam::DisplayFontParam(GString *nameA,
00047 DisplayFontParamKind kindA) {
00048 name = nameA;
00049 kind = kindA;
00050 switch (kind) {
00051 case displayFontX:
00052 x.xlfd = NULL;
00053 x.encoding = NULL;
00054 break;
00055 case displayFontT1:
00056 t1.fileName = NULL;
00057 break;
00058 case displayFontTT:
00059 tt.fileName = NULL;
00060 break;
00061 }
00062 }
00063
00064 DisplayFontParam::DisplayFontParam(char *nameA, char *xlfdA, char *encodingA) {
00065 name = new GString(nameA);
00066 kind = displayFontX;
00067 x.xlfd = new GString(xlfdA);
00068 x.encoding = new GString(encodingA);
00069 }
00070
00071 DisplayFontParam::~DisplayFontParam() {
00072 delete name;
00073 switch (kind) {
00074 case displayFontX:
00075 if (x.xlfd) {
00076 delete x.xlfd;
00077 }
00078 if (x.encoding) {
00079 delete x.encoding;
00080 }
00081 break;
00082 case displayFontT1:
00083 if (t1.fileName) {
00084 delete t1.fileName;
00085 }
00086 break;
00087 case displayFontTT:
00088 if (tt.fileName) {
00089 delete tt.fileName;
00090 }
00091 break;
00092 }
00093 }
00094
00095
00096
00097
00098
00099 PSFontParam::PSFontParam(GString *pdfFontNameA, int wModeA,
00100 GString *psFontNameA, GString *encodingA) {
00101 pdfFontName = pdfFontNameA;
00102 wMode = wModeA;
00103 psFontName = psFontNameA;
00104 encoding = encodingA;
00105 }
00106
00107 PSFontParam::~PSFontParam() {
00108 delete pdfFontName;
00109 delete psFontName;
00110 if (encoding) {
00111 delete encoding;
00112 }
00113 }
00114
00115
00116
00117
00118
00119 GlobalParams::GlobalParams(char *cfgFileName) {
00120 UnicodeMap *map;
00121 DisplayFontParam *dfp;
00122 GString *fileName;
00123 FILE *f;
00124 int i;
00125
00126 initBuiltinFontTables();
00127
00128
00129
00130 macRomanReverseMap = new NameToCharCode();
00131 for (i = 255; i >= 0; --i) {
00132 if (macRomanEncoding[i]) {
00133 macRomanReverseMap->add(macRomanEncoding[i], (CharCode)i);
00134 }
00135 }
00136
00137 nameToUnicode = new NameToCharCode();
00138 cidToUnicodes = new GHash(gTrue);
00139 residentUnicodeMaps = new GHash();
00140 unicodeMaps = new GHash(gTrue);
00141 cMapDirs = new GHash(gTrue);
00142 toUnicodeDirs = new GList();
00143 displayFonts = new GHash();
00144 displayCIDFonts = new GHash();
00145 displayNamedCIDFonts = new GHash();
00146 #if HAVE_PAPER_H
00147 const struct paper *paperType;
00148 paperinit();
00149 paperType = paperinfo(systempapername());
00150 psPaperWidth = (int)paperpswidth(paperType);
00151 psPaperHeight = (int)paperpsheight(paperType);
00152 paperdone();
00153 #else
00154 psPaperWidth = defPaperWidth;
00155 psPaperHeight = defPaperHeight;
00156 #endif
00157 psDuplex = gFalse;
00158 psLevel = psLevel2;
00159 psFile = NULL;
00160 psFonts = new GHash();
00161 psNamedFonts16 = new GList();
00162 psFonts16 = new GList();
00163 psEmbedType1 = gTrue;
00164 psEmbedTrueType = gTrue;
00165 psEmbedCIDPostScript = gTrue;
00166 psEmbedCIDTrueType = gTrue;
00167 psOPI = gFalse;
00168 psASCIIHex = gFalse;
00169 textEncoding = new GString("Latin1");
00170 #if defined(WIN32)
00171 textEOL = eolDOS;
00172 #elif defined(MACOS)
00173 textEOL = eolMac;
00174 #else
00175 textEOL = eolUnix;
00176 #endif
00177 fontDirs = new GList();
00178 initialZoom = new GString("1");
00179 t1libControl = fontRastAALow;
00180 freetypeControl = fontRastAALow;
00181 urlCommand = NULL;
00182 mapNumericCharNames = gTrue;
00183 errQuiet = gFalse;
00184
00185 cidToUnicodeCache = new CIDToUnicodeCache();
00186 unicodeMapCache = new UnicodeMapCache();
00187 cMapCache = new CMapCache();
00188
00189
00190 for (i = 0; nameToUnicodeTab[i].name; ++i) {
00191 nameToUnicode->add(nameToUnicodeTab[i].name, nameToUnicodeTab[i].u);
00192 }
00193
00194
00195 map = new UnicodeMap("Latin1", latin1UnicodeMapRanges, latin1UnicodeMapLen);
00196 residentUnicodeMaps->add(map->getEncodingName(), map);
00197 map = new UnicodeMap("ASCII7", ascii7UnicodeMapRanges, ascii7UnicodeMapLen);
00198 residentUnicodeMaps->add(map->getEncodingName(), map);
00199 map = new UnicodeMap("Symbol", symbolUnicodeMapRanges, symbolUnicodeMapLen);
00200 residentUnicodeMaps->add(map->getEncodingName(), map);
00201 map = new UnicodeMap("ZapfDingbats", zapfDingbatsUnicodeMapRanges,
00202 zapfDingbatsUnicodeMapLen);
00203 residentUnicodeMaps->add(map->getEncodingName(), map);
00204 map = new UnicodeMap("UTF-8", &mapUTF8);
00205 residentUnicodeMaps->add(map->getEncodingName(), map);
00206 map = new UnicodeMap("UCS-2", &mapUCS2);
00207 residentUnicodeMaps->add(map->getEncodingName(), map);
00208
00209
00210 for (i = 0; displayFontTab[i].name; ++i) {
00211 dfp = new DisplayFontParam(displayFontTab[i].name,
00212 displayFontTab[i].xlfd,
00213 displayFontTab[i].encoding);
00214 displayFonts->add(dfp->name, dfp);
00215 }
00216
00217
00218 f = NULL;
00219 fileName = NULL;
00220 if (cfgFileName && cfgFileName[0]) {
00221 fileName = new GString(cfgFileName);
00222 if (!(f = fopen(fileName->getCString(), "r"))) {
00223 delete fileName;
00224 }
00225 }
00226 if (!f) {
00227 fileName = appendToPath(getHomeDir(), xpdfUserConfigFile);
00228 if (!(f = fopen(fileName->getCString(), "r"))) {
00229 delete fileName;
00230 }
00231 }
00232 if (!f) {
00233 #if defined(WIN32) && !defined(__CYGWIN32__)
00234 char buf[512];
00235 i = GetModuleFileName(NULL, buf, sizeof(buf));
00236 if (i <= 0 || i >= sizeof(buf)) {
00237
00238 buf[i] = '\0';
00239 }
00240 fileName = grabPath(buf);
00241 appendToPath(fileName, xpdfSysConfigFile);
00242 #else
00243 fileName = new GString(xpdfSysConfigFile);
00244 #endif
00245 if (!(f = fopen(fileName->getCString(), "r"))) {
00246 delete fileName;
00247 }
00248 }
00249 if (f) {
00250 parseFile(fileName, f);
00251 delete fileName;
00252 }
00253 }
00254
00255 void GlobalParams::parseFile(GString *fileName, FILE *f) {
00256 int line;
00257 GList *tokens;
00258 GString *cmd, *incFile;
00259 char *p1, *p2;
00260 char buf[512];
00261 FILE *f2;
00262
00263 line = 1;
00264 while (fgets(buf, sizeof(buf) - 1, f)) {
00265
00266
00267 tokens = new GList();
00268 p1 = buf;
00269 while (*p1) {
00270 for (; *p1 && isspace(*p1); ++p1) ;
00271 if (!*p1) {
00272 break;
00273 }
00274 if (*p1 == '"' || *p1 == '\'') {
00275 for (p2 = p1 + 1; *p2 && *p2 != *p1; ++p2) ;
00276 ++p1;
00277 } else {
00278 for (p2 = p1 + 1; *p2 && !isspace(*p2); ++p2) ;
00279 }
00280 tokens->append(new GString(p1, p2 - p1));
00281 p1 = p2 + 1;
00282 }
00283
00284 if (tokens->getLength() > 0 &&
00285 ((GString *)tokens->get(0))->getChar(0) != '#') {
00286 cmd = (GString *)tokens->get(0);
00287 if (!cmd->cmp("include")) {
00288 if (tokens->getLength() == 2) {
00289 incFile = (GString *)tokens->get(1);
00290 if ((f2 = fopen(incFile->getCString(), "r"))) {
00291 parseFile(incFile, f2);
00292 fclose(f2);
00293 } else {
00294 error(-1, "Couldn't find included config file: '%s' (%s:%d)",
00295 incFile->getCString(), fileName->getCString(), line);
00296 }
00297 } else {
00298 error(-1, "Bad 'include' config file command (%s:%d)",
00299 fileName->getCString(), line);
00300 }
00301 } else if (!cmd->cmp("nameToUnicode")) {
00302 parseNameToUnicode(tokens, fileName, line);
00303 } else if (!cmd->cmp("cidToUnicode")) {
00304 parseCIDToUnicode(tokens, fileName, line);
00305 } else if (!cmd->cmp("unicodeMap")) {
00306 parseUnicodeMap(tokens, fileName, line);
00307 } else if (!cmd->cmp("cMapDir")) {
00308 parseCMapDir(tokens, fileName, line);
00309 } else if (!cmd->cmp("toUnicodeDir")) {
00310 parseToUnicodeDir(tokens, fileName, line);
00311 } else if (!cmd->cmp("displayFontX")) {
00312 parseDisplayFont(tokens, displayFonts, displayFontX, fileName, line);
00313 } else if (!cmd->cmp("displayFontT1")) {
00314 parseDisplayFont(tokens, displayFonts, displayFontT1, fileName, line);
00315 } else if (!cmd->cmp("displayFontTT")) {
00316 parseDisplayFont(tokens, displayFonts, displayFontTT, fileName, line);
00317 } else if (!cmd->cmp("displayCIDFontX")) {
00318 parseDisplayFont(tokens, displayCIDFonts,
00319 displayFontX, fileName, line);
00320 } else if (!cmd->cmp("displayNamedCIDFontX")) {
00321 parseDisplayFont(tokens, displayNamedCIDFonts,
00322 displayFontX, fileName, line);
00323 } else if (!cmd->cmp("psFile")) {
00324 parsePSFile(tokens, fileName, line);
00325 } else if (!cmd->cmp("psFont")) {
00326 parsePSFont(tokens, fileName, line);
00327 } else if (!cmd->cmp("psNamedFont16")) {
00328 parsePSFont16("psNamedFont16", psNamedFonts16,
00329 tokens, fileName, line);
00330 } else if (!cmd->cmp("psFont16")) {
00331 parsePSFont16("psFont16", psFonts16, tokens, fileName, line);
00332 } else if (!cmd->cmp("psPaperSize")) {
00333 parsePSPaperSize(tokens, fileName, line);
00334 } else if (!cmd->cmp("psDuplex")) {
00335 parseYesNo("psDuplex", &psDuplex, tokens, fileName, line);
00336 } else if (!cmd->cmp("psLevel")) {
00337 parsePSLevel(tokens, fileName, line);
00338 } else if (!cmd->cmp("psEmbedType1Fonts")) {
00339 parseYesNo("psEmbedType1", &psEmbedType1, tokens, fileName, line);
00340 } else if (!cmd->cmp("psEmbedTrueTypeFonts")) {
00341 parseYesNo("psEmbedTrueType", &psEmbedTrueType,
00342 tokens, fileName, line);
00343 } else if (!cmd->cmp("psEmbedCIDPostScriptFonts")) {
00344 parseYesNo("psEmbedCIDPostScript", &psEmbedCIDPostScript,
00345 tokens, fileName, line);
00346 } else if (!cmd->cmp("psEmbedCIDTrueTypeFonts")) {
00347 parseYesNo("psEmbedCIDTrueType", &psEmbedCIDTrueType,
00348 tokens, fileName, line);
00349 } else if (!cmd->cmp("psOPI")) {
00350 parseYesNo("psOPI", &psOPI, tokens, fileName, line);
00351 } else if (!cmd->cmp("psASCIIHex")) {
00352 parseYesNo("psASCIIHex", &psASCIIHex, tokens, fileName, line);
00353 } else if (!cmd->cmp("textEncoding")) {
00354 parseTextEncoding(tokens, fileName, line);
00355 } else if (!cmd->cmp("textEOL")) {
00356 parseTextEOL(tokens, fileName, line);
00357 } else if (!cmd->cmp("fontDir")) {
00358 parseFontDir(tokens, fileName, line);
00359 } else if (!cmd->cmp("initialZoom")) {
00360 parseInitialZoom(tokens, fileName, line);
00361 } else if (!cmd->cmp("t1libControl")) {
00362 parseFontRastControl("t1libControl", &t1libControl,
00363 tokens, fileName, line);
00364 } else if (!cmd->cmp("freetypeControl")) {
00365 parseFontRastControl("freetypeControl", &freetypeControl,
00366 tokens, fileName, line);
00367 } else if (!cmd->cmp("urlCommand")) {
00368 parseURLCommand(tokens, fileName, line);
00369 } else if (!cmd->cmp("mapNumericCharNames")) {
00370 parseYesNo("mapNumericCharNames", &mapNumericCharNames,
00371 tokens, fileName, line);
00372 } else if (!cmd->cmp("errQuiet")) {
00373 parseYesNo("errQuiet", &errQuiet, tokens, fileName, line);
00374 } else if (!cmd->cmp("fontpath") || !cmd->cmp("fontmap")) {
00375 error(-1, "Unknown config file command");
00376 error(-1, "-- the config file format has changed since Xpdf 0.9x");
00377 } else {
00378 error(-1, "Unknown config file command '%s' (%s:%d)",
00379 cmd->getCString(), fileName->getCString(), line);
00380 }
00381 }
00382
00383 deleteGList(tokens, GString);
00384 ++line;
00385 }
00386 }
00387
00388 void GlobalParams::parseNameToUnicode(GList *tokens, GString *fileName,
00389 int line) {
00390 GString *name;
00391 char *tok1, *tok2;
00392 FILE *f;
00393 char buf[256];
00394 int line2;
00395 Unicode u;
00396
00397 if (tokens->getLength() != 2) {
00398 error(-1, "Bad 'nameToUnicode' config file command (%s:%d)",
00399 fileName->getCString(), line);
00400 return;
00401 }
00402 name = (GString *)tokens->get(1);
00403 if (!(f = fopen(name->getCString(), "r"))) {
00404 error(-1, "Couldn't open 'nameToUnicode' file '%s'",
00405 name->getCString());
00406 return;
00407 }
00408 line2 = 1;
00409 while (fgets(buf, sizeof(buf), f)) {
00410 tok1 = strtok(buf, " \t\r\n");
00411 tok2 = strtok(NULL, " \t\r\n");
00412 if (tok1 && tok2) {
00413 sscanf(tok1, "%x", &u);
00414 nameToUnicode->add(tok2, u);
00415 } else {
00416 error(-1, "Bad line in 'nameToUnicode' file (%s:%d)", name, line2);
00417 }
00418 ++line2;
00419 }
00420 fclose(f);
00421 }
00422
00423 void GlobalParams::parseCIDToUnicode(GList *tokens, GString *fileName,
00424 int line) {
00425 GString *collection, *name, *old;
00426
00427 if (tokens->getLength() != 3) {
00428 error(-1, "Bad 'cidToUnicode' config file command (%s:%d)",
00429 fileName->getCString(), line);
00430 return;
00431 }
00432 collection = (GString *)tokens->get(1);
00433 name = (GString *)tokens->get(2);
00434 if ((old = (GString *)cidToUnicodes->remove(collection))) {
00435 delete old;
00436 }
00437 cidToUnicodes->add(collection->copy(), name->copy());
00438 }
00439
00440 void GlobalParams::parseUnicodeMap(GList *tokens, GString *fileName,
00441 int line) {
00442 GString *encodingName, *name, *old;
00443
00444 if (tokens->getLength() != 3) {
00445 error(-1, "Bad 'unicodeMap' config file command (%s:%d)",
00446 fileName->getCString(), line);
00447 return;
00448 }
00449 encodingName = (GString *)tokens->get(1);
00450 name = (GString *)tokens->get(2);
00451 if ((old = (GString *)unicodeMaps->remove(encodingName))) {
00452 delete old;
00453 }
00454 unicodeMaps->add(encodingName->copy(), name->copy());
00455 }
00456
00457 void GlobalParams::parseCMapDir(GList *tokens, GString *fileName, int line) {
00458 GString *collection, *dir;
00459 GList *list;
00460
00461 if (tokens->getLength() != 3) {
00462 error(-1, "Bad 'cMapDir' config file command (%s:%d)",
00463 fileName->getCString(), line);
00464 return;
00465 }
00466 collection = (GString *)tokens->get(1);
00467 dir = (GString *)tokens->get(2);
00468 if (!(list = (GList *)cMapDirs->lookup(collection))) {
00469 list = new GList();
00470 cMapDirs->add(collection->copy(), list);
00471 }
00472 list->append(dir->copy());
00473 }
00474
00475 void GlobalParams::parseToUnicodeDir(GList *tokens, GString *fileName,
00476 int line) {
00477 if (tokens->getLength() != 2) {
00478 error(-1, "Bad 'toUnicodeDir' config file command (%s:%d)",
00479 fileName->getCString(), line);
00480 return;
00481 }
00482 toUnicodeDirs->append(((GString *)tokens->get(1))->copy());
00483 }
00484
00485 void GlobalParams::parseDisplayFont(GList *tokens, GHash *fontHash,
00486 DisplayFontParamKind kind,
00487 GString *fileName, int line) {
00488 DisplayFontParam *param, *old;
00489
00490 if (tokens->getLength() < 2) {
00491 goto err1;
00492 }
00493 param = new DisplayFontParam(((GString *)tokens->get(1))->copy(), kind);
00494
00495 switch (kind) {
00496 case displayFontX:
00497 if (tokens->getLength() != 4) {
00498 goto err2;
00499 }
00500 param->x.xlfd = ((GString *)tokens->get(2))->copy();
00501 param->x.encoding = ((GString *)tokens->get(3))->copy();
00502 break;
00503 case displayFontT1:
00504 if (tokens->getLength() != 3) {
00505 goto err2;
00506 }
00507 param->t1.fileName = ((GString *)tokens->get(2))->copy();
00508 break;
00509 case displayFontTT:
00510 if (tokens->getLength() != 3) {
00511 goto err2;
00512 }
00513 param->tt.fileName = ((GString *)tokens->get(2))->copy();
00514 break;
00515 }
00516
00517 if ((old = (DisplayFontParam *)fontHash->remove(param->name))) {
00518 delete old;
00519 }
00520 fontHash->add(param->name, param);
00521 return;
00522
00523 err2:
00524 delete param;
00525 err1:
00526 error(-1, "Bad 'display*Font*' config file command (%s:%d)",
00527 fileName->getCString(), line);
00528 }
00529
00530 void GlobalParams::parsePSPaperSize(GList *tokens, GString *fileName,
00531 int line) {
00532 GString *tok;
00533
00534 if (tokens->getLength() == 2) {
00535 tok = (GString *)tokens->get(1);
00536 if (!setPSPaperSize(tok->getCString())) {
00537 error(-1, "Bad 'psPaperSize' config file command (%s:%d)",
00538 fileName->getCString(), line);
00539 }
00540 } else if (tokens->getLength() == 3) {
00541 tok = (GString *)tokens->get(1);
00542 psPaperWidth = atoi(tok->getCString());
00543 tok = (GString *)tokens->get(2);
00544 psPaperHeight = atoi(tok->getCString());
00545 } else {
00546 error(-1, "Bad 'psPaperSize' config file command (%s:%d)",
00547 fileName->getCString(), line);
00548 }
00549 }
00550
00551 void GlobalParams::parsePSLevel(GList *tokens, GString *fileName, int line) {
00552 GString *tok;
00553
00554 if (tokens->getLength() != 2) {
00555 error(-1, "Bad 'psLevel' config file command (%s:%d)",
00556 fileName->getCString(), line);
00557 return;
00558 }
00559 tok = (GString *)tokens->get(1);
00560 if (!tok->cmp("level1")) {
00561 psLevel = psLevel1;
00562 } else if (!tok->cmp("level1sep")) {
00563 psLevel = psLevel1Sep;
00564 } else if (!tok->cmp("level2")) {
00565 psLevel = psLevel2;
00566 } else if (!tok->cmp("level2sep")) {
00567 psLevel = psLevel2Sep;
00568 } else if (!tok->cmp("level3")) {
00569 psLevel = psLevel3;
00570 } else if (!tok->cmp("level3Sep")) {
00571 psLevel = psLevel3Sep;
00572 } else {
00573 error(-1, "Bad 'psLevel' config file command (%s:%d)",
00574 fileName->getCString(), line);
00575 }
00576 }
00577
00578 void GlobalParams::parsePSFile(GList *tokens, GString *fileName, int line) {
00579 if (tokens->getLength() != 2) {
00580 error(-1, "Bad 'psFile' config file command (%s:%d)",
00581 fileName->getCString(), line);
00582 return;
00583 }
00584 if (psFile) {
00585 delete psFile;
00586 }
00587 psFile = ((GString *)tokens->get(1))->copy();
00588 }
00589
00590 void GlobalParams::parsePSFont(GList *tokens, GString *fileName, int line) {
00591 PSFontParam *param;
00592
00593 if (tokens->getLength() != 3) {
00594 error(-1, "Bad 'psFont' config file command (%s:%d)",
00595 fileName->getCString(), line);
00596 return;
00597 }
00598 param = new PSFontParam(((GString *)tokens->get(1))->copy(), 0,
00599 ((GString *)tokens->get(2))->copy(), NULL);
00600 psFonts->add(param->pdfFontName, param);
00601 }
00602
00603 void GlobalParams::parsePSFont16(char *cmdName, GList *fontList,
00604 GList *tokens, GString *fileName, int line) {
00605 PSFontParam *param;
00606 int wMode;
00607 GString *tok;
00608
00609 if (tokens->getLength() != 5) {
00610 error(-1, "Bad '%s' config file command (%s:%d)",
00611 cmdName, fileName->getCString(), line);
00612 return;
00613 }
00614 tok = (GString *)tokens->get(2);
00615 if (!tok->cmp("H")) {
00616 wMode = 0;
00617 } else if (!tok->cmp("V")) {
00618 wMode = 1;
00619 } else {
00620 error(-1, "Bad '%s' config file command (%s:%d)",
00621 cmdName, fileName->getCString(), line);
00622 return;
00623 }
00624 param = new PSFontParam(((GString *)tokens->get(1))->copy(),
00625 wMode,
00626 ((GString *)tokens->get(3))->copy(),
00627 ((GString *)tokens->get(4))->copy());
00628 fontList->append(param);
00629 }
00630
00631 void GlobalParams::parseTextEncoding(GList *tokens, GString *fileName,
00632 int line) {
00633 if (tokens->getLength() != 2) {
00634 error(-1, "Bad 'textEncoding' config file command (%s:%d)",
00635 fileName->getCString(), line);
00636 return;
00637 }
00638 delete textEncoding;
00639 textEncoding = ((GString *)tokens->get(1))->copy();
00640 }
00641
00642 void GlobalParams::parseTextEOL(GList *tokens, GString *fileName, int line) {
00643 GString *tok;
00644
00645 if (tokens->getLength() != 2) {
00646 error(-1, "Bad 'textEOL' config file command (%s:%d)",
00647 fileName->getCString(), line);
00648 return;
00649 }
00650 tok = (GString *)tokens->get(1);
00651 if (!tok->cmp("unix")) {
00652 textEOL = eolUnix;
00653 } else if (!tok->cmp("dos")) {
00654 textEOL = eolDOS;
00655 } else if (!tok->cmp("mac")) {
00656 textEOL = eolMac;
00657 } else {
00658 error(-1, "Bad 'textEOL' config file command (%s:%d)",
00659 fileName->getCString(), line);
00660 }
00661 }
00662
00663 void GlobalParams::parseFontDir(GList *tokens, GString *fileName, int line) {
00664 if (tokens->getLength() != 2) {
00665 error(-1, "Bad 'fontDir' config file command (%s:%d)",
00666 fileName->getCString(), line);
00667 return;
00668 }
00669 fontDirs->append(((GString *)tokens->get(1))->copy());
00670 }
00671
00672 void GlobalParams::parseInitialZoom(GList *tokens,
00673 GString *fileName, int line) {
00674 if (tokens->getLength() != 2) {
00675 error(-1, "Bad 'initialZoom' config file command (%s:%d)",
00676 fileName->getCString(), line);
00677 return;
00678 }
00679 delete initialZoom;
00680 initialZoom = ((GString *)tokens->get(1))->copy();
00681 }
00682
00683 void GlobalParams::parseFontRastControl(char *cmdName, FontRastControl *val,
00684 GList *tokens, GString *fileName,
00685 int line) {
00686 GString *tok;
00687
00688 if (tokens->getLength() != 2) {
00689 error(-1, "Bad '%s' config file command (%s:%d)",
00690 cmdName, fileName->getCString(), line);
00691 return;
00692 }
00693 tok = (GString *)tokens->get(1);
00694 if (!setFontRastControl(val, tok->getCString())) {
00695 error(-1, "Bad '%s' config file command (%s:%d)",
00696 cmdName, fileName->getCString(), line);
00697 }
00698 }
00699
00700 void GlobalParams::parseURLCommand(GList *tokens, GString *fileName,
00701 int line) {
00702 if (tokens->getLength() != 2) {
00703 error(-1, "Bad 'urlCommand' config file command (%s:%d)",
00704 fileName->getCString(), line);
00705 return;
00706 }
00707 if (urlCommand) {
00708 delete urlCommand;
00709 }
00710 urlCommand = ((GString *)tokens->get(1))->copy();
00711 }
00712
00713 void GlobalParams::parseYesNo(char *cmdName, GBool *flag,
00714 GList *tokens, GString *fileName, int line) {
00715 GString *tok;
00716
00717 if (tokens->getLength() != 2) {
00718 error(-1, "Bad '%s' config file command (%s:%d)",
00719 cmdName, fileName->getCString(), line);
00720 return;
00721 }
00722 tok = (GString *)tokens->get(1);
00723 if (!tok->cmp("yes")) {
00724 *flag = gTrue;
00725 } else if (!tok->cmp("no")) {
00726 *flag = gFalse;
00727 } else {
00728 error(-1, "Bad '%s' config file command (%s:%d)",
00729 cmdName, fileName->getCString(), line);
00730 }
00731 }
00732
00733 GlobalParams::~GlobalParams() {
00734 GHashIter *iter;
00735 GString *key;
00736 GList *list;
00737
00738 freeBuiltinFontTables();
00739
00740 delete macRomanReverseMap;
00741
00742 delete nameToUnicode;
00743 deleteGHash(cidToUnicodes, GString);
00744 deleteGHash(residentUnicodeMaps, UnicodeMap);
00745 deleteGHash(unicodeMaps, GString);
00746 deleteGList(toUnicodeDirs, GString);
00747 deleteGHash(displayFonts, DisplayFontParam);
00748 deleteGHash(displayCIDFonts, DisplayFontParam);
00749 deleteGHash(displayNamedCIDFonts, DisplayFontParam);
00750 if (psFile) {
00751 delete psFile;
00752 }
00753 deleteGHash(psFonts, PSFontParam);
00754 deleteGList(psNamedFonts16, PSFontParam);
00755 deleteGList(psFonts16, PSFontParam);
00756 delete textEncoding;
00757 deleteGList(fontDirs, GString);
00758 delete initialZoom;
00759 if (urlCommand) {
00760 delete urlCommand;
00761 }
00762
00763 cMapDirs->startIter(&iter);
00764 while (cMapDirs->getNext(&iter, &key, (void **)&list)) {
00765 deleteGList(list, GString);
00766 }
00767 delete cMapDirs;
00768
00769 delete cidToUnicodeCache;
00770 delete unicodeMapCache;
00771 delete cMapCache;
00772 }
00773
00774
00775
00776
00777
00778 CharCode GlobalParams::getMacRomanCharCode(char *charName) {
00779 return macRomanReverseMap->lookup(charName);
00780 }
00781
00782 Unicode GlobalParams::mapNameToUnicode(char *charName) {
00783 return nameToUnicode->lookup(charName);
00784 }
00785
00786 FILE *GlobalParams::getCIDToUnicodeFile(GString *collection) {
00787 GString *fileName;
00788
00789 if (!(fileName = (GString *)cidToUnicodes->lookup(collection))) {
00790 return NULL;
00791 }
00792 return fopen(fileName->getCString(), "r");
00793 }
00794
00795 UnicodeMap *GlobalParams::getResidentUnicodeMap(GString *encodingName) {
00796 return (UnicodeMap *)residentUnicodeMaps->lookup(encodingName);
00797 }
00798
00799 FILE *GlobalParams::getUnicodeMapFile(GString *encodingName) {
00800 GString *fileName;
00801
00802 if (!(fileName = (GString *)unicodeMaps->lookup(encodingName))) {
00803 return NULL;
00804 }
00805 return fopen(fileName->getCString(), "r");
00806 }
00807
00808 FILE *GlobalParams::findCMapFile(GString *collection, GString *cMapName) {
00809 GList *list;
00810 GString *dir;
00811 GString *fileName;
00812 FILE *f;
00813 int i;
00814
00815 if (!(list = (GList *)cMapDirs->lookup(collection))) {
00816 return NULL;
00817 }
00818 for (i = 0; i < list->getLength(); ++i) {
00819 dir = (GString *)list->get(i);
00820 fileName = appendToPath(dir->copy(), cMapName->getCString());
00821 f = fopen(fileName->getCString(), "r");
00822 delete fileName;
00823 if (f) {
00824 return f;
00825 }
00826 }
00827 return NULL;
00828 }
00829
00830 FILE *GlobalParams::findToUnicodeFile(GString *name) {
00831 GString *dir, *fileName;
00832 FILE *f;
00833 int i;
00834
00835 for (i = 0; i < toUnicodeDirs->getLength(); ++i) {
00836 dir = (GString *)toUnicodeDirs->get(i);
00837 fileName = appendToPath(dir->copy(), name->getCString());
00838 f = fopen(fileName->getCString(), "r");
00839 delete fileName;
00840 if (f) {
00841 return f;
00842 }
00843 }
00844 return NULL;
00845 }
00846
00847 DisplayFontParam *GlobalParams::getDisplayFont(GString *fontName) {
00848 return (DisplayFontParam *)displayFonts->lookup(fontName);
00849 }
00850
00851 DisplayFontParam *GlobalParams::getDisplayCIDFont(GString *fontName,
00852 GString *collection) {
00853 DisplayFontParam *dfp;
00854
00855 if (!fontName ||
00856 !(dfp = (DisplayFontParam *)displayNamedCIDFonts->lookup(fontName))) {
00857 dfp = (DisplayFontParam *)displayCIDFonts->lookup(collection);
00858 }
00859 return dfp;
00860 }
00861
00862 PSFontParam *GlobalParams::getPSFont(GString *fontName) {
00863 return (PSFontParam *)psFonts->lookup(fontName);
00864 }
00865
00866 PSFontParam *GlobalParams::getPSFont16(GString *fontName,
00867 GString *collection, int wMode) {
00868 PSFontParam *p;
00869 int i;
00870
00871 p = NULL;
00872 if (fontName) {
00873 for (i = 0; i < psNamedFonts16->getLength(); ++i) {
00874 p = (PSFontParam *)psNamedFonts16->get(i);
00875 if (!p->pdfFontName->cmp(fontName) &&
00876 p->wMode == wMode) {
00877 break;
00878 }
00879 p = NULL;
00880 }
00881 }
00882 if (!p && collection) {
00883 for (i = 0; i < psFonts16->getLength(); ++i) {
00884 p = (PSFontParam *)psFonts16->get(i);
00885 if (!p->pdfFontName->cmp(collection) &&
00886 p->wMode == wMode) {
00887 break;
00888 }
00889 p = NULL;
00890 }
00891 }
00892 return p;
00893 }
00894
00895 GString *GlobalParams::findFontFile(GString *fontName,
00896 char *ext1, char *ext2) {
00897 GString *dir, *fileName;
00898 FILE *f;
00899 int i;
00900
00901 for (i = 0; i < fontDirs->getLength(); ++i) {
00902 dir = (GString *)fontDirs->get(i);
00903 if (ext1) {
00904 fileName = appendToPath(dir->copy(), fontName->getCString());
00905 fileName->append(ext1);
00906 if ((f = fopen(fileName->getCString(), "r"))) {
00907 fclose(f);
00908 return fileName;
00909 }
00910 delete fileName;
00911 }
00912 if (ext2) {
00913 fileName = appendToPath(dir->copy(), fontName->getCString());
00914 fileName->append(ext2);
00915 if ((f = fopen(fileName->getCString(), "r"))) {
00916 fclose(f);
00917 return fileName;
00918 }
00919 delete fileName;
00920 }
00921 }
00922 return NULL;
00923 }
00924
00925 CharCodeToUnicode *GlobalParams::getCIDToUnicode(GString *collection) {
00926 return cidToUnicodeCache->getCIDToUnicode(collection);
00927 }
00928
00929 UnicodeMap *GlobalParams::getUnicodeMap(GString *encodingName) {
00930 UnicodeMap *map;
00931
00932 if ((map = getResidentUnicodeMap(encodingName))) {
00933 map->incRefCnt();
00934 return map;
00935 }
00936 return unicodeMapCache->getUnicodeMap(encodingName);
00937 }
00938
00939 CMap *GlobalParams::getCMap(GString *collection, GString *cMapName) {
00940 return cMapCache->getCMap(collection, cMapName);
00941 }
00942
00943 UnicodeMap *GlobalParams::getTextEncoding() {
00944 return getUnicodeMap(textEncoding);
00945 }
00946
00947
00948
00949
00950
00951 void GlobalParams::setPSFile(char *file) {
00952 if (psFile) {
00953 delete psFile;
00954 }
00955 psFile = new GString(file);
00956 }
00957
00958 GBool GlobalParams::setPSPaperSize(char *size) {
00959 if (!strcmp(size, "letter")) {
00960 psPaperWidth = 612;
00961 psPaperHeight = 792;
00962 } else if (!strcmp(size, "legal")) {
00963 psPaperWidth = 612;
00964 psPaperHeight = 1008;
00965 } else if (!strcmp(size, "A4")) {
00966 psPaperWidth = 595;
00967 psPaperHeight = 842;
00968 } else if (!strcmp(size, "A3")) {
00969 psPaperWidth = 842;
00970 psPaperHeight = 1190;
00971 } else {
00972 return gFalse;
00973 }
00974 return gTrue;
00975 }
00976
00977 void GlobalParams::setPSPaperWidth(int width) {
00978 psPaperWidth = width;
00979 }
00980
00981 void GlobalParams::setPSPaperHeight(int height) {
00982 psPaperHeight = height;
00983 }
00984
00985 void GlobalParams::setPSDuplex(GBool duplex) {
00986 psDuplex = duplex;
00987 }
00988
00989 void GlobalParams::setPSLevel(PSLevel level) {
00990 psLevel = level;
00991 }
00992
00993 void GlobalParams::setPSEmbedType1(GBool embed) {
00994 psEmbedType1 = embed;
00995 }
00996
00997 void GlobalParams::setPSEmbedTrueType(GBool embed) {
00998 psEmbedTrueType = embed;
00999 }
01000
01001 void GlobalParams::setPSEmbedCIDPostScript(GBool embed) {
01002 psEmbedCIDPostScript = embed;
01003 }
01004
01005 void GlobalParams::setPSEmbedCIDTrueType(GBool embed) {
01006 psEmbedCIDTrueType = embed;
01007 }
01008
01009 void GlobalParams::setPSOPI(GBool opi) {
01010 psOPI = opi;
01011 }
01012
01013 void GlobalParams::setPSASCIIHex(GBool hex) {
01014 psASCIIHex = hex;
01015 }
01016
01017 void GlobalParams::setTextEncoding(char *encodingName) {
01018 delete textEncoding;
01019 textEncoding = new GString(encodingName);
01020 }
01021
01022 GBool GlobalParams::setTextEOL(char *s) {
01023 if (!strcmp(s, "unix")) {
01024 textEOL = eolUnix;
01025 } else if (!strcmp(s, "dos")) {
01026 textEOL = eolDOS;
01027 } else if (!strcmp(s, "mac")) {
01028 textEOL = eolMac;
01029 } else {
01030 return gFalse;
01031 }
01032 return gTrue;
01033 }
01034
01035 void GlobalParams::setInitialZoom(char *s) {
01036 delete initialZoom;
01037 initialZoom = new GString(s);
01038 }
01039
01040 GBool GlobalParams::setT1libControl(char *s) {
01041 return setFontRastControl(&t1libControl, s);
01042 }
01043
01044 GBool GlobalParams::setFreeTypeControl(char *s) {
01045 return setFontRastControl(&freetypeControl, s);
01046 }
01047
01048 GBool GlobalParams::setFontRastControl(FontRastControl *val, char *s) {
01049 if (!strcmp(s, "none")) {
01050 *val = fontRastNone;
01051 } else if (!strcmp(s, "plain")) {
01052 *val = fontRastPlain;
01053 } else if (!strcmp(s, "low")) {
01054 *val = fontRastAALow;
01055 } else if (!strcmp(s, "high")) {
01056 *val = fontRastAAHigh;
01057 } else {
01058 return gFalse;
01059 }
01060 return gTrue;
01061 }
01062
01063 void GlobalParams::setErrQuiet(GBool errQuietA) {
01064 errQuiet = errQuietA;
01065 }