Back to index

tetex-bin  3.0
GlobalParams.cc
Go to the documentation of this file.
00001 //========================================================================
00002 //
00003 // GlobalParams.cc
00004 //
00005 // Copyright 2001-2003 Glyph & Cog, LLC
00006 //
00007 //========================================================================
00008 
00009 #include <aconf.h>
00010 
00011 #ifdef USE_GCC_PRAGMAS
00012 #pragma implementation
00013 #endif
00014 
00015 #include <string.h>
00016 #include <stdio.h>
00017 #include <ctype.h>
00018 #if HAVE_PAPER_H
00019 #include <paper.h>
00020 #endif
00021 #include "gmem.h"
00022 #include "GString.h"
00023 #include "GList.h"
00024 #include "GHash.h"
00025 #include "gfile.h"
00026 #include "Error.h"
00027 #include "NameToCharCode.h"
00028 #include "CharCodeToUnicode.h"
00029 #include "UnicodeMap.h"
00030 #include "CMap.h"
00031 #include "BuiltinFontTables.h"
00032 #include "FontEncodingTables.h"
00033 #include "GlobalParams.h"
00034 
00035 #if MULTITHREADED
00036 #  define lockGlobalParams            gLockMutex(&mutex)
00037 #  define lockUnicodeMapCache         gLockMutex(&unicodeMapCacheMutex)
00038 #  define lockCMapCache               gLockMutex(&cMapCacheMutex)
00039 #  define unlockGlobalParams          gUnlockMutex(&mutex)
00040 #  define unlockUnicodeMapCache       gUnlockMutex(&unicodeMapCacheMutex)
00041 #  define unlockCMapCache             gUnlockMutex(&cMapCacheMutex)
00042 #else
00043 #  define lockGlobalParams
00044 #  define lockUnicodeMapCache
00045 #  define lockCMapCache
00046 #  define unlockGlobalParams
00047 #  define unlockUnicodeMapCache
00048 #  define unlockCMapCache
00049 #endif
00050 
00051 #include "NameToUnicodeTable.h"
00052 #include "UnicodeMapTables.h"
00053 #include "UTF8.h"
00054 
00055 //------------------------------------------------------------------------
00056 
00057 #define cidToUnicodeCacheSize     4
00058 #define unicodeToUnicodeCacheSize 4
00059 
00060 //------------------------------------------------------------------------
00061 
00062 static struct {
00063   char *name;
00064   char *fileName;
00065 } displayFontTab[] = {
00066   {"Courier",               "n022003l.pfb"},
00067   {"Courier-Bold",          "n022004l.pfb"},
00068   {"Courier-BoldOblique",   "n022024l.pfb"},
00069   {"Courier-Oblique",       "n022023l.pfb"},
00070   {"Helvetica",             "n019003l.pfb"},
00071   {"Helvetica-Bold",        "n019004l.pfb"},
00072   {"Helvetica-BoldOblique", "n019024l.pfb"},
00073   {"Helvetica-Oblique",     "n019023l.pfb"},
00074   {"Symbol",                "s050000l.pfb"},
00075   {"Times-Bold",            "n021004l.pfb"},
00076   {"Times-BoldItalic",      "n021024l.pfb"},
00077   {"Times-Italic",          "n021023l.pfb"},
00078   {"Times-Roman",           "n021003l.pfb"},
00079   {"ZapfDingbats",          "d050000l.pfb"},
00080   {NULL}
00081 };
00082 
00083 static char *displayFontDirs[] = {
00084   "/usr/share/ghostscript/fonts",
00085   "/usr/local/share/ghostscript/fonts",
00086   "/usr/share/fonts/default/Type1",
00087   NULL
00088 };
00089 
00090 //------------------------------------------------------------------------
00091 
00092 GlobalParams *globalParams = NULL;
00093 
00094 //------------------------------------------------------------------------
00095 // DisplayFontParam
00096 //------------------------------------------------------------------------
00097 
00098 DisplayFontParam::DisplayFontParam(GString *nameA,
00099                                DisplayFontParamKind kindA) {
00100   name = nameA;
00101   kind = kindA;
00102   switch (kind) {
00103   case displayFontT1:
00104     t1.fileName = NULL;
00105     break;
00106   case displayFontTT:
00107     tt.fileName = NULL;
00108     break;
00109   }
00110 }
00111 
00112 DisplayFontParam::~DisplayFontParam() {
00113   delete name;
00114   switch (kind) {
00115   case displayFontT1:
00116     if (t1.fileName) {
00117       delete t1.fileName;
00118     }
00119     break;
00120   case displayFontTT:
00121     if (tt.fileName) {
00122       delete tt.fileName;
00123     }
00124     break;
00125   }
00126 }
00127 
00128 //------------------------------------------------------------------------
00129 // PSFontParam
00130 //------------------------------------------------------------------------
00131 
00132 PSFontParam::PSFontParam(GString *pdfFontNameA, int wModeA,
00133                       GString *psFontNameA, GString *encodingA) {
00134   pdfFontName = pdfFontNameA;
00135   wMode = wModeA;
00136   psFontName = psFontNameA;
00137   encoding = encodingA;
00138 }
00139 
00140 PSFontParam::~PSFontParam() {
00141   delete pdfFontName;
00142   delete psFontName;
00143   if (encoding) {
00144     delete encoding;
00145   }
00146 }
00147 
00148 //------------------------------------------------------------------------
00149 // parsing
00150 //------------------------------------------------------------------------
00151 
00152 GlobalParams::GlobalParams() {
00153   UnicodeMap *map;
00154   int i;
00155 
00156 #if MULTITHREADED
00157   gInitMutex(&mutex);
00158   gInitMutex(&unicodeMapCacheMutex);
00159   gInitMutex(&cMapCacheMutex);
00160 #endif
00161 
00162   initBuiltinFontTables();
00163 
00164   // scan the encoding in reverse because we want the lowest-numbered
00165   // index for each char name ('space' is encoded twice)
00166   macRomanReverseMap = new NameToCharCode();
00167   for (i = 255; i >= 0; --i) {
00168     if (macRomanEncoding[i]) {
00169       macRomanReverseMap->add(macRomanEncoding[i], (CharCode)i);
00170     }
00171   }
00172 
00173   nameToUnicode = new NameToCharCode();
00174   cidToUnicodes = new GHash(gTrue);
00175   unicodeToUnicodes = new GHash(gTrue);
00176   residentUnicodeMaps = new GHash();
00177   unicodeMaps = new GHash(gTrue);
00178   cMapDirs = new GHash(gTrue);
00179   toUnicodeDirs = new GList();
00180   displayFonts = new GHash();
00181   displayCIDFonts = new GHash();
00182   displayNamedCIDFonts = new GHash();
00183 #if HAVE_PAPER_H
00184   char *paperName;
00185   const struct paper *paperType;
00186   paperinit();
00187   if ((paperName = systempapername())) {
00188     paperType = paperinfo(paperName);
00189     psPaperWidth = (int)paperpswidth(paperType);
00190     psPaperHeight = (int)paperpsheight(paperType);
00191   } else {
00192     error(-1, "No paper information available - using defaults");
00193     psPaperWidth = defPaperWidth;
00194     psPaperHeight = defPaperHeight;
00195   }
00196   paperdone();
00197 #else
00198   psPaperWidth = defPaperWidth;
00199   psPaperHeight = defPaperHeight;
00200 #endif
00201   psImageableLLX = psImageableLLY = 0;
00202   psImageableURX = psPaperWidth;
00203   psImageableURY = psPaperHeight;
00204   psCrop = gTrue;
00205   psExpandSmaller = gFalse;
00206   psShrinkLarger = gTrue;
00207   psCenter = gTrue;
00208   psDuplex = gFalse;
00209   psLevel = psLevel2;
00210   psFile = NULL;
00211   psFonts = new GHash();
00212   psNamedFonts16 = new GList();
00213   psFonts16 = new GList();
00214   psEmbedType1 = gTrue;
00215   psEmbedTrueType = gTrue;
00216   psEmbedCIDPostScript = gTrue;
00217   psEmbedCIDTrueType = gTrue;
00218   psOPI = gFalse;
00219   psASCIIHex = gFalse;
00220   textEncoding = new GString("Latin1");
00221 #if defined(WIN32)
00222   textEOL = eolDOS;
00223 #elif defined(MACOS)
00224   textEOL = eolMac;
00225 #else
00226   textEOL = eolUnix;
00227 #endif
00228   textPageBreaks = gTrue;
00229   textKeepTinyChars = gFalse;
00230   fontDirs = new GList();
00231   initialZoom = new GString("125");
00232   enableT1lib = gTrue;
00233   enableFreeType = gTrue;
00234   antialias = gTrue;
00235   urlCommand = NULL;
00236   movieCommand = NULL;
00237   mapNumericCharNames = gTrue;
00238   printCommands = gFalse;
00239   errQuiet = gFalse;
00240 
00241   cidToUnicodeCache = new CharCodeToUnicodeCache(cidToUnicodeCacheSize);
00242   unicodeToUnicodeCache =
00243       new CharCodeToUnicodeCache(unicodeToUnicodeCacheSize);
00244   unicodeMapCache = new UnicodeMapCache();
00245   cMapCache = new CMapCache();
00246 
00247   // set up the initial nameToUnicode table
00248   for (i = 0; nameToUnicodeTab[i].name; ++i) {
00249     nameToUnicode->add(nameToUnicodeTab[i].name, nameToUnicodeTab[i].u);
00250   }
00251 
00252   // set up the residentUnicodeMaps table
00253   map = new UnicodeMap("Latin1", gFalse,
00254                      latin1UnicodeMapRanges, latin1UnicodeMapLen);
00255   residentUnicodeMaps->add(map->getEncodingName(), map);
00256   map = new UnicodeMap("ASCII7", gFalse,
00257                      ascii7UnicodeMapRanges, ascii7UnicodeMapLen);
00258   residentUnicodeMaps->add(map->getEncodingName(), map);
00259   map = new UnicodeMap("Symbol", gFalse,
00260                      symbolUnicodeMapRanges, symbolUnicodeMapLen);
00261   residentUnicodeMaps->add(map->getEncodingName(), map);
00262   map = new UnicodeMap("ZapfDingbats", gFalse, zapfDingbatsUnicodeMapRanges,
00263                      zapfDingbatsUnicodeMapLen);
00264   residentUnicodeMaps->add(map->getEncodingName(), map);
00265   map = new UnicodeMap("UTF-8", gTrue, &mapUTF8);
00266   residentUnicodeMaps->add(map->getEncodingName(), map);
00267   map = new UnicodeMap("UCS-2", gTrue, &mapUCS2);
00268   residentUnicodeMaps->add(map->getEncodingName(), map);
00269 }
00270 
00271 GlobalParams::GlobalParams(char *cfgFileName) {
00272   UnicodeMap *map;
00273   GString *fileName;
00274   FILE *f;
00275   int i;
00276 
00277 #if MULTITHREADED
00278   gInitMutex(&mutex);
00279   gInitMutex(&unicodeMapCacheMutex);
00280   gInitMutex(&cMapCacheMutex);
00281 #endif
00282 
00283   initBuiltinFontTables();
00284 
00285   // scan the encoding in reverse because we want the lowest-numbered
00286   // index for each char name ('space' is encoded twice)
00287   macRomanReverseMap = new NameToCharCode();
00288   for (i = 255; i >= 0; --i) {
00289     if (macRomanEncoding[i]) {
00290       macRomanReverseMap->add(macRomanEncoding[i], (CharCode)i);
00291     }
00292   }
00293 
00294   nameToUnicode = new NameToCharCode();
00295   cidToUnicodes = new GHash(gTrue);
00296   unicodeToUnicodes = new GHash(gTrue);
00297   residentUnicodeMaps = new GHash();
00298   unicodeMaps = new GHash(gTrue);
00299   cMapDirs = new GHash(gTrue);
00300   toUnicodeDirs = new GList();
00301   displayFonts = new GHash();
00302   displayCIDFonts = new GHash();
00303   displayNamedCIDFonts = new GHash();
00304 #if HAVE_PAPER_H
00305   char *paperName;
00306   const struct paper *paperType;
00307   paperinit();
00308   if ((paperName = systempapername())) {
00309     paperType = paperinfo(paperName);
00310     psPaperWidth = (int)paperpswidth(paperType);
00311     psPaperHeight = (int)paperpsheight(paperType);
00312   } else {
00313     error(-1, "No paper information available - using defaults");
00314     psPaperWidth = defPaperWidth;
00315     psPaperHeight = defPaperHeight;
00316   }
00317   paperdone();
00318 #else
00319   psPaperWidth = defPaperWidth;
00320   psPaperHeight = defPaperHeight;
00321 #endif
00322   psImageableLLX = psImageableLLY = 0;
00323   psImageableURX = psPaperWidth;
00324   psImageableURY = psPaperHeight;
00325   psCrop = gTrue;
00326   psExpandSmaller = gFalse;
00327   psShrinkLarger = gTrue;
00328   psCenter = gTrue;
00329   psDuplex = gFalse;
00330   psLevel = psLevel2;
00331   psFile = NULL;
00332   psFonts = new GHash();
00333   psNamedFonts16 = new GList();
00334   psFonts16 = new GList();
00335   psEmbedType1 = gTrue;
00336   psEmbedTrueType = gTrue;
00337   psEmbedCIDPostScript = gTrue;
00338   psEmbedCIDTrueType = gTrue;
00339   psOPI = gFalse;
00340   psASCIIHex = gFalse;
00341   textEncoding = new GString("Latin1");
00342 #if defined(WIN32)
00343   textEOL = eolDOS;
00344 #elif defined(MACOS)
00345   textEOL = eolMac;
00346 #else
00347   textEOL = eolUnix;
00348 #endif
00349   textPageBreaks = gTrue;
00350   textKeepTinyChars = gFalse;
00351   fontDirs = new GList();
00352   initialZoom = new GString("125");
00353   enableT1lib = gTrue;
00354   enableFreeType = gTrue;
00355   antialias = gTrue;
00356   urlCommand = NULL;
00357   movieCommand = NULL;
00358   mapNumericCharNames = gTrue;
00359   printCommands = gFalse;
00360   errQuiet = gFalse;
00361 
00362   cidToUnicodeCache = new CharCodeToUnicodeCache(cidToUnicodeCacheSize);
00363   unicodeToUnicodeCache =
00364       new CharCodeToUnicodeCache(unicodeToUnicodeCacheSize);
00365   unicodeMapCache = new UnicodeMapCache();
00366   cMapCache = new CMapCache();
00367 
00368   // set up the initial nameToUnicode table
00369   for (i = 0; nameToUnicodeTab[i].name; ++i) {
00370     nameToUnicode->add(nameToUnicodeTab[i].name, nameToUnicodeTab[i].u);
00371   }
00372 
00373   // set up the residentUnicodeMaps table
00374   map = new UnicodeMap("Latin1", gFalse,
00375                      latin1UnicodeMapRanges, latin1UnicodeMapLen);
00376   residentUnicodeMaps->add(map->getEncodingName(), map);
00377   map = new UnicodeMap("ASCII7", gFalse,
00378                      ascii7UnicodeMapRanges, ascii7UnicodeMapLen);
00379   residentUnicodeMaps->add(map->getEncodingName(), map);
00380   map = new UnicodeMap("Symbol", gFalse,
00381                      symbolUnicodeMapRanges, symbolUnicodeMapLen);
00382   residentUnicodeMaps->add(map->getEncodingName(), map);
00383   map = new UnicodeMap("ZapfDingbats", gFalse, zapfDingbatsUnicodeMapRanges,
00384                      zapfDingbatsUnicodeMapLen);
00385   residentUnicodeMaps->add(map->getEncodingName(), map);
00386   map = new UnicodeMap("UTF-8", gTrue, &mapUTF8);
00387   residentUnicodeMaps->add(map->getEncodingName(), map);
00388   map = new UnicodeMap("UCS-2", gTrue, &mapUCS2);
00389   residentUnicodeMaps->add(map->getEncodingName(), map);
00390 
00391   // look for a user config file, then a system-wide config file
00392   f = NULL;
00393   fileName = NULL;
00394   if (cfgFileName && cfgFileName[0]) {
00395     fileName = new GString(cfgFileName);
00396     if (!(f = fopen(fileName->getCString(), "r"))) {
00397       delete fileName;
00398     }
00399   }
00400   if (!f) {
00401     fileName = appendToPath(getHomeDir(), xpdfUserConfigFile);
00402     if (!(f = fopen(fileName->getCString(), "r"))) {
00403       delete fileName;
00404     }
00405   }
00406   if (!f) {
00407 #if defined(WIN32) && !defined(__CYGWIN32__)
00408     char buf[512];
00409     i = GetModuleFileName(NULL, buf, sizeof(buf));
00410     if (i <= 0 || i >= sizeof(buf)) {
00411       // error or path too long for buffer - just use the current dir
00412       buf[0] = '\0';
00413     }
00414     fileName = grabPath(buf);
00415     appendToPath(fileName, xpdfSysConfigFile);
00416 #else
00417     fileName = new GString(xpdfSysConfigFile);
00418 #endif
00419     if (!(f = fopen(fileName->getCString(), "r"))) {
00420       delete fileName;
00421     }
00422   }
00423   if (f) {
00424     parseFile(fileName, f);
00425     delete fileName;
00426     fclose(f);
00427   }
00428 }
00429 
00430 void GlobalParams::parseFile(GString *fileName, FILE *f) {
00431   int line;
00432   GList *tokens;
00433   GString *cmd, *incFile;
00434   char *p1, *p2;
00435   char buf[512];
00436   FILE *f2;
00437 
00438   line = 1;
00439   while (getLine(buf, sizeof(buf) - 1, f)) {
00440 
00441     // break the line into tokens
00442     tokens = new GList();
00443     p1 = buf;
00444     while (*p1) {
00445       for (; *p1 && isspace(*p1); ++p1) ;
00446       if (!*p1) {
00447        break;
00448       }
00449       if (*p1 == '"' || *p1 == '\'') {
00450        for (p2 = p1 + 1; *p2 && *p2 != *p1; ++p2) ;
00451        ++p1;
00452       } else {
00453        for (p2 = p1 + 1; *p2 && !isspace(*p2); ++p2) ;
00454       }
00455       tokens->append(new GString(p1, p2 - p1));
00456       p1 = *p2 ? p2 + 1 : p2;
00457     }
00458 
00459     if (tokens->getLength() > 0 &&
00460        ((GString *)tokens->get(0))->getChar(0) != '#') {
00461       cmd = (GString *)tokens->get(0);
00462       if (!cmd->cmp("include")) {
00463        if (tokens->getLength() == 2) {
00464          incFile = (GString *)tokens->get(1);
00465          if ((f2 = fopen(incFile->getCString(), "r"))) {
00466            parseFile(incFile, f2);
00467            fclose(f2);
00468          } else {
00469            error(-1, "Couldn't find included config file: '%s' (%s:%d)",
00470                 incFile->getCString(), fileName->getCString(), line);
00471          }
00472        } else {
00473          error(-1, "Bad 'include' config file command (%s:%d)",
00474               fileName->getCString(), line);
00475        }
00476       } else if (!cmd->cmp("nameToUnicode")) {
00477        parseNameToUnicode(tokens, fileName, line);
00478       } else if (!cmd->cmp("cidToUnicode")) {
00479        parseCIDToUnicode(tokens, fileName, line);
00480       } else if (!cmd->cmp("unicodeToUnicode")) {
00481        parseUnicodeToUnicode(tokens, fileName, line);
00482       } else if (!cmd->cmp("unicodeMap")) {
00483        parseUnicodeMap(tokens, fileName, line);
00484       } else if (!cmd->cmp("cMapDir")) {
00485        parseCMapDir(tokens, fileName, line);
00486       } else if (!cmd->cmp("toUnicodeDir")) {
00487        parseToUnicodeDir(tokens, fileName, line);
00488       } else if (!cmd->cmp("displayFontT1")) {
00489        parseDisplayFont(tokens, displayFonts, displayFontT1, fileName, line);
00490       } else if (!cmd->cmp("displayFontTT")) {
00491        parseDisplayFont(tokens, displayFonts, displayFontTT, fileName, line);
00492       } else if (!cmd->cmp("displayNamedCIDFontT1")) {
00493        parseDisplayFont(tokens, displayNamedCIDFonts,
00494                       displayFontT1, fileName, line);
00495       } else if (!cmd->cmp("displayCIDFontT1")) {
00496        parseDisplayFont(tokens, displayCIDFonts,
00497                       displayFontT1, fileName, line);
00498       } else if (!cmd->cmp("displayNamedCIDFontTT")) {
00499        parseDisplayFont(tokens, displayNamedCIDFonts,
00500                       displayFontTT, fileName, line);
00501       } else if (!cmd->cmp("displayCIDFontTT")) {
00502        parseDisplayFont(tokens, displayCIDFonts,
00503                       displayFontTT, fileName, line);
00504       } else if (!cmd->cmp("psFile")) {
00505        parsePSFile(tokens, fileName, line);
00506       } else if (!cmd->cmp("psFont")) {
00507        parsePSFont(tokens, fileName, line);
00508       } else if (!cmd->cmp("psNamedFont16")) {
00509        parsePSFont16("psNamedFont16", psNamedFonts16,
00510                     tokens, fileName, line);
00511       } else if (!cmd->cmp("psFont16")) {
00512        parsePSFont16("psFont16", psFonts16, tokens, fileName, line);
00513       } else if (!cmd->cmp("psPaperSize")) {
00514        parsePSPaperSize(tokens, fileName, line);
00515       } else if (!cmd->cmp("psImageableArea")) {
00516        parsePSImageableArea(tokens, fileName, line);
00517       } else if (!cmd->cmp("psCrop")) {
00518        parseYesNo("psCrop", &psCrop, tokens, fileName, line);
00519       } else if (!cmd->cmp("psExpandSmaller")) {
00520        parseYesNo("psExpandSmaller", &psExpandSmaller,
00521                  tokens, fileName, line);
00522       } else if (!cmd->cmp("psShrinkLarger")) {
00523        parseYesNo("psShrinkLarger", &psShrinkLarger, tokens, fileName, line);
00524       } else if (!cmd->cmp("psCenter")) {
00525        parseYesNo("psCenter", &psCenter, tokens, fileName, line);
00526       } else if (!cmd->cmp("psDuplex")) {
00527        parseYesNo("psDuplex", &psDuplex, tokens, fileName, line);
00528       } else if (!cmd->cmp("psLevel")) {
00529        parsePSLevel(tokens, fileName, line);
00530       } else if (!cmd->cmp("psEmbedType1Fonts")) {
00531        parseYesNo("psEmbedType1", &psEmbedType1, tokens, fileName, line);
00532       } else if (!cmd->cmp("psEmbedTrueTypeFonts")) {
00533        parseYesNo("psEmbedTrueType", &psEmbedTrueType,
00534                  tokens, fileName, line);
00535       } else if (!cmd->cmp("psEmbedCIDPostScriptFonts")) {
00536        parseYesNo("psEmbedCIDPostScript", &psEmbedCIDPostScript,
00537                  tokens, fileName, line);
00538       } else if (!cmd->cmp("psEmbedCIDTrueTypeFonts")) {
00539        parseYesNo("psEmbedCIDTrueType", &psEmbedCIDTrueType,
00540                  tokens, fileName, line);
00541       } else if (!cmd->cmp("psOPI")) {
00542        parseYesNo("psOPI", &psOPI, tokens, fileName, line);
00543       } else if (!cmd->cmp("psASCIIHex")) {
00544        parseYesNo("psASCIIHex", &psASCIIHex, tokens, fileName, line);
00545       } else if (!cmd->cmp("textEncoding")) {
00546        parseTextEncoding(tokens, fileName, line);
00547       } else if (!cmd->cmp("textEOL")) {
00548        parseTextEOL(tokens, fileName, line);
00549       } else if (!cmd->cmp("textPageBreaks")) {
00550        parseYesNo("textPageBreaks", &textPageBreaks,
00551                  tokens, fileName, line);
00552       } else if (!cmd->cmp("textKeepTinyChars")) {
00553        parseYesNo("textKeepTinyChars", &textKeepTinyChars,
00554                  tokens, fileName, line);
00555       } else if (!cmd->cmp("fontDir")) {
00556        parseFontDir(tokens, fileName, line);
00557       } else if (!cmd->cmp("initialZoom")) {
00558        parseInitialZoom(tokens, fileName, line);
00559       } else if (!cmd->cmp("enableT1lib")) {
00560        parseYesNo("enableT1lib", &enableT1lib, tokens, fileName, line);
00561       } else if (!cmd->cmp("enableFreeType")) {
00562        parseYesNo("enableFreeType", &enableFreeType, tokens, fileName, line);
00563       } else if (!cmd->cmp("antialias")) {
00564        parseYesNo("antialias", &antialias, tokens, fileName, line);
00565       } else if (!cmd->cmp("urlCommand")) {
00566        parseCommand("urlCommand", &urlCommand, tokens, fileName, line);
00567       } else if (!cmd->cmp("movieCommand")) {
00568        parseCommand("movieCommand", &movieCommand, tokens, fileName, line);
00569       } else if (!cmd->cmp("mapNumericCharNames")) {
00570        parseYesNo("mapNumericCharNames", &mapNumericCharNames,
00571                  tokens, fileName, line);
00572       } else if (!cmd->cmp("printCommands")) {
00573        parseYesNo("printCommands", &printCommands, tokens, fileName, line);
00574       } else if (!cmd->cmp("errQuiet")) {
00575        parseYesNo("errQuiet", &errQuiet, tokens, fileName, line);
00576       } else {
00577        error(-1, "Unknown config file command '%s' (%s:%d)",
00578              cmd->getCString(), fileName->getCString(), line);
00579        if (!cmd->cmp("displayFontX") ||
00580            !cmd->cmp("displayNamedCIDFontX") ||
00581            !cmd->cmp("displayCIDFontX")) {
00582          error(-1, "-- Xpdf no longer supports X fonts");
00583        } else if (!cmd->cmp("t1libControl") || !cmd->cmp("freetypeControl")) {
00584          error(-1, "-- The t1libControl and freetypeControl options have been replaced");
00585          error(-1, "   by the enableT1lib, enableFreeType, and antialias options");
00586        } else if (!cmd->cmp("fontpath") || !cmd->cmp("fontmap")) {
00587          error(-1, "-- the config file format has changed since Xpdf 0.9x");
00588        }
00589       }
00590     }
00591 
00592     deleteGList(tokens, GString);
00593     ++line;
00594   }
00595 }
00596 
00597 void GlobalParams::parseNameToUnicode(GList *tokens, GString *fileName,
00598                                     int line) {
00599   GString *name;
00600   char *tok1, *tok2;
00601   FILE *f;
00602   char buf[256];
00603   int line2;
00604   Unicode u;
00605 
00606   if (tokens->getLength() != 2) {
00607     error(-1, "Bad 'nameToUnicode' config file command (%s:%d)",
00608          fileName->getCString(), line);
00609     return;
00610   }
00611   name = (GString *)tokens->get(1);
00612   if (!(f = fopen(name->getCString(), "r"))) {
00613     error(-1, "Couldn't open 'nameToUnicode' file '%s'",
00614          name->getCString());
00615     return;
00616   }
00617   line2 = 1;
00618   while (getLine(buf, sizeof(buf), f)) {
00619     tok1 = strtok(buf, " \t\r\n");
00620     tok2 = strtok(NULL, " \t\r\n");
00621     if (tok1 && tok2) {
00622       sscanf(tok1, "%x", &u);
00623       nameToUnicode->add(tok2, u);
00624     } else {
00625       error(-1, "Bad line in 'nameToUnicode' file (%s:%d)", name, line2);
00626     }
00627     ++line2;
00628   }
00629   fclose(f);
00630 }
00631 
00632 void GlobalParams::parseCIDToUnicode(GList *tokens, GString *fileName,
00633                                  int line) {
00634   GString *collection, *name, *old;
00635 
00636   if (tokens->getLength() != 3) {
00637     error(-1, "Bad 'cidToUnicode' config file command (%s:%d)",
00638          fileName->getCString(), line);
00639     return;
00640   }
00641   collection = (GString *)tokens->get(1);
00642   name = (GString *)tokens->get(2);
00643   if ((old = (GString *)cidToUnicodes->remove(collection))) {
00644     delete old;
00645   }
00646   cidToUnicodes->add(collection->copy(), name->copy());
00647 }
00648 
00649 void GlobalParams::parseUnicodeToUnicode(GList *tokens, GString *fileName,
00650                                     int line) {
00651   GString *font, *file, *old;
00652 
00653   if (tokens->getLength() != 3) {
00654     error(-1, "Bad 'unicodeToUnicode' config file command (%s:%d)",
00655          fileName->getCString(), line);
00656     return;
00657   }
00658   font = (GString *)tokens->get(1);
00659   file = (GString *)tokens->get(2);
00660   if ((old = (GString *)unicodeToUnicodes->remove(font))) {
00661     delete old;
00662   }
00663   unicodeToUnicodes->add(font->copy(), file->copy());
00664 }
00665 
00666 void GlobalParams::parseUnicodeMap(GList *tokens, GString *fileName,
00667                                int line) {
00668   GString *encodingName, *name, *old;
00669 
00670   if (tokens->getLength() != 3) {
00671     error(-1, "Bad 'unicodeMap' config file command (%s:%d)",
00672          fileName->getCString(), line);
00673     return;
00674   }
00675   encodingName = (GString *)tokens->get(1);
00676   name = (GString *)tokens->get(2);
00677   if ((old = (GString *)unicodeMaps->remove(encodingName))) {
00678     delete old;
00679   }
00680   unicodeMaps->add(encodingName->copy(), name->copy());
00681 }
00682 
00683 void GlobalParams::parseCMapDir(GList *tokens, GString *fileName, int line) {
00684   GString *collection, *dir;
00685   GList *list;
00686 
00687   if (tokens->getLength() != 3) {
00688     error(-1, "Bad 'cMapDir' config file command (%s:%d)",
00689          fileName->getCString(), line);
00690     return;
00691   }
00692   collection = (GString *)tokens->get(1);
00693   dir = (GString *)tokens->get(2);
00694   if (!(list = (GList *)cMapDirs->lookup(collection))) {
00695     list = new GList();
00696     cMapDirs->add(collection->copy(), list);
00697   }
00698   list->append(dir->copy());
00699 }
00700 
00701 void GlobalParams::parseToUnicodeDir(GList *tokens, GString *fileName,
00702                                  int line) {
00703   if (tokens->getLength() != 2) {
00704     error(-1, "Bad 'toUnicodeDir' config file command (%s:%d)",
00705          fileName->getCString(), line);
00706     return;
00707   }
00708   toUnicodeDirs->append(((GString *)tokens->get(1))->copy());
00709 }
00710 
00711 void GlobalParams::parseDisplayFont(GList *tokens, GHash *fontHash,
00712                                 DisplayFontParamKind kind,
00713                                 GString *fileName, int line) {
00714   DisplayFontParam *param, *old;
00715 
00716   if (tokens->getLength() < 2) {
00717     goto err1;
00718   }
00719   param = new DisplayFontParam(((GString *)tokens->get(1))->copy(), kind);
00720   
00721   switch (kind) {
00722   case displayFontT1:
00723     if (tokens->getLength() != 3) {
00724       goto err2;
00725     }
00726     param->t1.fileName = ((GString *)tokens->get(2))->copy();
00727     break;
00728   case displayFontTT:
00729     if (tokens->getLength() != 3) {
00730       goto err2;
00731     }
00732     param->tt.fileName = ((GString *)tokens->get(2))->copy();
00733     break;
00734   }
00735 
00736   if ((old = (DisplayFontParam *)fontHash->remove(param->name))) {
00737     delete old;
00738   }
00739   fontHash->add(param->name, param);
00740   return;
00741 
00742  err2:
00743   delete param;
00744  err1:
00745   error(-1, "Bad 'display*Font*' config file command (%s:%d)",
00746        fileName->getCString(), line);
00747 }
00748 
00749 void GlobalParams::parsePSPaperSize(GList *tokens, GString *fileName,
00750                                 int line) {
00751   GString *tok;
00752 
00753   if (tokens->getLength() == 2) {
00754     tok = (GString *)tokens->get(1);
00755     if (!setPSPaperSize(tok->getCString())) {
00756       error(-1, "Bad 'psPaperSize' config file command (%s:%d)",
00757            fileName->getCString(), line);
00758     }
00759   } else if (tokens->getLength() == 3) {
00760     tok = (GString *)tokens->get(1);
00761     psPaperWidth = atoi(tok->getCString());
00762     tok = (GString *)tokens->get(2);
00763     psPaperHeight = atoi(tok->getCString());
00764     psImageableLLX = psImageableLLY = 0;
00765     psImageableURX = psPaperWidth;
00766     psImageableURY = psPaperHeight;
00767   } else {
00768     error(-1, "Bad 'psPaperSize' config file command (%s:%d)",
00769          fileName->getCString(), line);
00770   }
00771 }
00772 
00773 void GlobalParams::parsePSImageableArea(GList *tokens, GString *fileName,
00774                                    int line) {
00775   if (tokens->getLength() != 5) {
00776     error(-1, "Bad 'psImageableArea' config file command (%s:%d)",
00777          fileName->getCString(), line);
00778     return;
00779   }
00780   psImageableLLX = atoi(((GString *)tokens->get(1))->getCString());
00781   psImageableLLY = atoi(((GString *)tokens->get(2))->getCString());
00782   psImageableURX = atoi(((GString *)tokens->get(3))->getCString());
00783   psImageableURY = atoi(((GString *)tokens->get(4))->getCString());
00784 }
00785 
00786 void GlobalParams::parsePSLevel(GList *tokens, GString *fileName, int line) {
00787   GString *tok;
00788 
00789   if (tokens->getLength() != 2) {
00790     error(-1, "Bad 'psLevel' config file command (%s:%d)",
00791          fileName->getCString(), line);
00792     return;
00793   }
00794   tok = (GString *)tokens->get(1);
00795   if (!tok->cmp("level1")) {
00796     psLevel = psLevel1;
00797   } else if (!tok->cmp("level1sep")) {
00798     psLevel = psLevel1Sep;
00799   } else if (!tok->cmp("level2")) {
00800     psLevel = psLevel2;
00801   } else if (!tok->cmp("level2sep")) {
00802     psLevel = psLevel2Sep;
00803   } else if (!tok->cmp("level3")) {
00804     psLevel = psLevel3;
00805   } else if (!tok->cmp("level3Sep")) {
00806     psLevel = psLevel3Sep;
00807   } else {
00808     error(-1, "Bad 'psLevel' config file command (%s:%d)",
00809          fileName->getCString(), line);
00810   }
00811 }
00812 
00813 void GlobalParams::parsePSFile(GList *tokens, GString *fileName, int line) {
00814   if (tokens->getLength() != 2) {
00815     error(-1, "Bad 'psFile' config file command (%s:%d)",
00816          fileName->getCString(), line);
00817     return;
00818   }
00819   if (psFile) {
00820     delete psFile;
00821   }
00822   psFile = ((GString *)tokens->get(1))->copy();
00823 }
00824 
00825 void GlobalParams::parsePSFont(GList *tokens, GString *fileName, int line) {
00826   PSFontParam *param;
00827 
00828   if (tokens->getLength() != 3) {
00829     error(-1, "Bad 'psFont' config file command (%s:%d)",
00830          fileName->getCString(), line);
00831     return;
00832   }
00833   param = new PSFontParam(((GString *)tokens->get(1))->copy(), 0,
00834                        ((GString *)tokens->get(2))->copy(), NULL);
00835   psFonts->add(param->pdfFontName, param);
00836 }
00837 
00838 void GlobalParams::parsePSFont16(char *cmdName, GList *fontList,
00839                              GList *tokens, GString *fileName, int line) {
00840   PSFontParam *param;
00841   int wMode;
00842   GString *tok;
00843 
00844   if (tokens->getLength() != 5) {
00845     error(-1, "Bad '%s' config file command (%s:%d)",
00846          cmdName, fileName->getCString(), line);
00847     return;
00848   }
00849   tok = (GString *)tokens->get(2);
00850   if (!tok->cmp("H")) {
00851     wMode = 0;
00852   } else if (!tok->cmp("V")) {
00853     wMode = 1;
00854   } else {
00855     error(-1, "Bad '%s' config file command (%s:%d)",
00856          cmdName, fileName->getCString(), line);
00857     return;
00858   }
00859   param = new PSFontParam(((GString *)tokens->get(1))->copy(),
00860                        wMode,
00861                        ((GString *)tokens->get(3))->copy(),
00862                        ((GString *)tokens->get(4))->copy());
00863   fontList->append(param);
00864 }
00865 
00866 void GlobalParams::parseTextEncoding(GList *tokens, GString *fileName,
00867                                  int line) {
00868   if (tokens->getLength() != 2) {
00869     error(-1, "Bad 'textEncoding' config file command (%s:%d)",
00870          fileName->getCString(), line);
00871     return;
00872   }
00873   delete textEncoding;
00874   textEncoding = ((GString *)tokens->get(1))->copy();
00875 }
00876 
00877 void GlobalParams::parseTextEOL(GList *tokens, GString *fileName, int line) {
00878   GString *tok;
00879 
00880   if (tokens->getLength() != 2) {
00881     error(-1, "Bad 'textEOL' config file command (%s:%d)",
00882          fileName->getCString(), line);
00883     return;
00884   }
00885   tok = (GString *)tokens->get(1);
00886   if (!tok->cmp("unix")) {
00887     textEOL = eolUnix;
00888   } else if (!tok->cmp("dos")) {
00889     textEOL = eolDOS;
00890   } else if (!tok->cmp("mac")) {
00891     textEOL = eolMac;
00892   } else {
00893     error(-1, "Bad 'textEOL' config file command (%s:%d)",
00894          fileName->getCString(), line);
00895   }
00896 }
00897 
00898 void GlobalParams::parseFontDir(GList *tokens, GString *fileName, int line) {
00899   if (tokens->getLength() != 2) {
00900     error(-1, "Bad 'fontDir' config file command (%s:%d)",
00901          fileName->getCString(), line);
00902     return;
00903   }
00904   fontDirs->append(((GString *)tokens->get(1))->copy());
00905 }
00906 
00907 void GlobalParams::parseInitialZoom(GList *tokens,
00908                                 GString *fileName, int line) {
00909   if (tokens->getLength() != 2) {
00910     error(-1, "Bad 'initialZoom' config file command (%s:%d)",
00911          fileName->getCString(), line);
00912     return;
00913   }
00914   delete initialZoom;
00915   initialZoom = ((GString *)tokens->get(1))->copy();
00916 }
00917 
00918 void GlobalParams::parseCommand(char *cmdName, GString **val,
00919                             GList *tokens, GString *fileName, int line) {
00920   if (tokens->getLength() != 2) {
00921     error(-1, "Bad '%s' config file command (%s:%d)",
00922          cmdName, fileName->getCString(), line);
00923     return;
00924   }
00925   if (*val) {
00926     delete *val;
00927   }
00928   *val = ((GString *)tokens->get(1))->copy();
00929 }
00930 
00931 void GlobalParams::parseYesNo(char *cmdName, GBool *flag,
00932                            GList *tokens, GString *fileName, int line) {
00933   GString *tok;
00934 
00935   if (tokens->getLength() != 2) {
00936     error(-1, "Bad '%s' config file command (%s:%d)",
00937          cmdName, fileName->getCString(), line);
00938     return;
00939   }
00940   tok = (GString *)tokens->get(1);
00941   if (!parseYesNo2(tok->getCString(), flag)) {
00942     error(-1, "Bad '%s' config file command (%s:%d)",
00943          cmdName, fileName->getCString(), line);
00944   }
00945 }
00946 
00947 GBool GlobalParams::parseYesNo2(char *token, GBool *flag) {
00948   if (!strcmp(token, "yes")) {
00949     *flag = gTrue;
00950   } else if (!strcmp(token, "no")) {
00951     *flag = gFalse;
00952   } else {
00953     return gFalse;
00954   }
00955   return gTrue;
00956 }
00957 
00958 GlobalParams::~GlobalParams() {
00959   GHashIter *iter;
00960   GString *key;
00961   GList *list;
00962 
00963   freeBuiltinFontTables();
00964 
00965   delete macRomanReverseMap;
00966 
00967   delete nameToUnicode;
00968   deleteGHash(cidToUnicodes, GString);
00969   deleteGHash(unicodeToUnicodes, GString);
00970   deleteGHash(residentUnicodeMaps, UnicodeMap);
00971   deleteGHash(unicodeMaps, GString);
00972   deleteGList(toUnicodeDirs, GString);
00973   deleteGHash(displayFonts, DisplayFontParam);
00974   deleteGHash(displayCIDFonts, DisplayFontParam);
00975   deleteGHash(displayNamedCIDFonts, DisplayFontParam);
00976   if (psFile) {
00977     delete psFile;
00978   }
00979   deleteGHash(psFonts, PSFontParam);
00980   deleteGList(psNamedFonts16, PSFontParam);
00981   deleteGList(psFonts16, PSFontParam);
00982   delete textEncoding;
00983   deleteGList(fontDirs, GString);
00984   delete initialZoom;
00985   if (urlCommand) {
00986     delete urlCommand;
00987   }
00988   if (movieCommand) {
00989     delete movieCommand;
00990   }
00991 
00992   cMapDirs->startIter(&iter);
00993   while (cMapDirs->getNext(&iter, &key, (void **)&list)) {
00994     deleteGList(list, GString);
00995   }
00996   delete cMapDirs;
00997 
00998   delete cidToUnicodeCache;
00999   delete unicodeToUnicodeCache;
01000   delete unicodeMapCache;
01001   delete cMapCache;
01002 
01003 #if MULTITHREADED
01004   gDestroyMutex(&mutex);
01005   gDestroyMutex(&unicodeMapCacheMutex);
01006   gDestroyMutex(&cMapCacheMutex);
01007 #endif
01008 }
01009 
01010 //------------------------------------------------------------------------
01011 
01012 void GlobalParams::setupBaseFonts(char *dir) {
01013   GString *fontName;
01014   GString *fileName;
01015   FILE *f;
01016   DisplayFontParam *dfp;
01017   int i, j;
01018 
01019   for (i = 0; displayFontTab[i].name; ++i) {
01020     fontName = new GString(displayFontTab[i].name);
01021     if (getDisplayFont(fontName)) {
01022       delete fontName;
01023       continue;
01024     }
01025     fileName = NULL;
01026     if (dir) {
01027       fileName = appendToPath(new GString(dir), displayFontTab[i].fileName);
01028       if ((f = fopen(fileName->getCString(), "rb"))) {
01029        fclose(f);
01030       } else {
01031        delete fileName;
01032        fileName = NULL;
01033       }
01034     }
01035 #ifndef WIN32
01036     for (j = 0; !fileName && displayFontDirs[j]; ++j) {
01037       fileName = appendToPath(new GString(displayFontDirs[j]),
01038                            displayFontTab[i].fileName);
01039       if ((f = fopen(fileName->getCString(), "rb"))) {
01040        fclose(f);
01041       } else {
01042        delete fileName;
01043        fileName = NULL;
01044       }
01045     }
01046 #endif
01047     if (!fileName) {
01048       error(-1, "No display font for '%s'", displayFontTab[i].name);
01049       delete fontName;
01050       continue;
01051     }
01052     dfp = new DisplayFontParam(fontName, displayFontT1);
01053     dfp->t1.fileName = fileName;
01054     globalParams->addDisplayFont(dfp);
01055   }
01056 }
01057 
01058 //------------------------------------------------------------------------
01059 // accessors
01060 //------------------------------------------------------------------------
01061 
01062 CharCode GlobalParams::getMacRomanCharCode(char *charName) {
01063   // no need to lock - macRomanReverseMap is constant
01064   return macRomanReverseMap->lookup(charName);
01065 }
01066 
01067 Unicode GlobalParams::mapNameToUnicode(char *charName) {
01068   // no need to lock - nameToUnicode is constant
01069   return nameToUnicode->lookup(charName);
01070 }
01071 
01072 UnicodeMap *GlobalParams::getResidentUnicodeMap(GString *encodingName) {
01073   UnicodeMap *map;
01074 
01075   lockGlobalParams;
01076   map = (UnicodeMap *)residentUnicodeMaps->lookup(encodingName);
01077   unlockGlobalParams;
01078   if (map) {
01079     map->incRefCnt();
01080   }
01081   return map;
01082 }
01083 
01084 FILE *GlobalParams::getUnicodeMapFile(GString *encodingName) {
01085   GString *fileName;
01086   FILE *f;
01087 
01088   lockGlobalParams;
01089   if ((fileName = (GString *)unicodeMaps->lookup(encodingName))) {
01090     f = fopen(fileName->getCString(), "r");
01091   } else {
01092     f = NULL;
01093   }
01094   unlockGlobalParams;
01095   return f;
01096 }
01097 
01098 FILE *GlobalParams::findCMapFile(GString *collection, GString *cMapName) {
01099   GList *list;
01100   GString *dir;
01101   GString *fileName;
01102   FILE *f;
01103   int i;
01104 
01105   lockGlobalParams;
01106   if (!(list = (GList *)cMapDirs->lookup(collection))) {
01107     unlockGlobalParams;
01108     return NULL;
01109   }
01110   for (i = 0; i < list->getLength(); ++i) {
01111     dir = (GString *)list->get(i);
01112     fileName = appendToPath(dir->copy(), cMapName->getCString());
01113     f = fopen(fileName->getCString(), "r");
01114     delete fileName;
01115     if (f) {
01116       unlockGlobalParams;
01117       return f;
01118     }
01119   }
01120   unlockGlobalParams;
01121   return NULL;
01122 }
01123 
01124 FILE *GlobalParams::findToUnicodeFile(GString *name) {
01125   GString *dir, *fileName;
01126   FILE *f;
01127   int i;
01128 
01129   lockGlobalParams;
01130   for (i = 0; i < toUnicodeDirs->getLength(); ++i) {
01131     dir = (GString *)toUnicodeDirs->get(i);
01132     fileName = appendToPath(dir->copy(), name->getCString());
01133     f = fopen(fileName->getCString(), "r");
01134     delete fileName;
01135     if (f) {
01136       unlockGlobalParams;
01137       return f;
01138     }
01139   }
01140   unlockGlobalParams;
01141   return NULL;
01142 }
01143 
01144 DisplayFontParam *GlobalParams::getDisplayFont(GString *fontName) {
01145   DisplayFontParam *dfp;
01146 
01147   lockGlobalParams;
01148   dfp = (DisplayFontParam *)displayFonts->lookup(fontName);
01149   unlockGlobalParams;
01150   return dfp;
01151 }
01152 
01153 DisplayFontParam *GlobalParams::getDisplayCIDFont(GString *fontName,
01154                                             GString *collection) {
01155   DisplayFontParam *dfp;
01156 
01157   lockGlobalParams;
01158   if (!fontName ||
01159       !(dfp = (DisplayFontParam *)displayNamedCIDFonts->lookup(fontName))) {
01160     dfp = (DisplayFontParam *)displayCIDFonts->lookup(collection);
01161   }
01162   unlockGlobalParams;
01163   return dfp;
01164 }
01165 
01166 GString *GlobalParams::getPSFile() {
01167   GString *s;
01168 
01169   lockGlobalParams;
01170   s = psFile ? psFile->copy() : (GString *)NULL;
01171   unlockGlobalParams;
01172   return s;
01173 }
01174 
01175 int GlobalParams::getPSPaperWidth() {
01176   int w;
01177 
01178   lockGlobalParams;
01179   w = psPaperWidth;
01180   unlockGlobalParams;
01181   return w;
01182 }
01183 
01184 int GlobalParams::getPSPaperHeight() {
01185   int h;
01186 
01187   lockGlobalParams;
01188   h = psPaperHeight;
01189   unlockGlobalParams;
01190   return h;
01191 }
01192 
01193 void GlobalParams::getPSImageableArea(int *llx, int *lly, int *urx, int *ury) {
01194   lockGlobalParams;
01195   *llx = psImageableLLX;
01196   *lly = psImageableLLY;
01197   *urx = psImageableURX;
01198   *ury = psImageableURY;
01199   unlockGlobalParams;
01200 }
01201 
01202 GBool GlobalParams::getPSCrop() {
01203   GBool f;
01204 
01205   lockGlobalParams;
01206   f = psCrop;
01207   unlockGlobalParams;
01208   return f;
01209 }
01210 
01211 GBool GlobalParams::getPSExpandSmaller() {
01212   GBool f;
01213 
01214   lockGlobalParams;
01215   f = psExpandSmaller;
01216   unlockGlobalParams;
01217   return f;
01218 }
01219 
01220 GBool GlobalParams::getPSShrinkLarger() {
01221   GBool f;
01222 
01223   lockGlobalParams;
01224   f = psShrinkLarger;
01225   unlockGlobalParams;
01226   return f;
01227 }
01228 
01229 GBool GlobalParams::getPSCenter() {
01230   GBool f;
01231 
01232   lockGlobalParams;
01233   f = psCenter;
01234   unlockGlobalParams;
01235   return f;
01236 }
01237 
01238 GBool GlobalParams::getPSDuplex() {
01239   GBool d;
01240 
01241   lockGlobalParams;
01242   d = psDuplex;
01243   unlockGlobalParams;
01244   return d;
01245 }
01246 
01247 PSLevel GlobalParams::getPSLevel() {
01248   PSLevel level;
01249 
01250   lockGlobalParams;
01251   level = psLevel;
01252   unlockGlobalParams;
01253   return level;
01254 }
01255 
01256 PSFontParam *GlobalParams::getPSFont(GString *fontName) {
01257   PSFontParam *p;
01258 
01259   lockGlobalParams;
01260   p = (PSFontParam *)psFonts->lookup(fontName);
01261   unlockGlobalParams;
01262   return p;
01263 }
01264 
01265 PSFontParam *GlobalParams::getPSFont16(GString *fontName,
01266                                    GString *collection, int wMode) {
01267   PSFontParam *p;
01268   int i;
01269 
01270   lockGlobalParams;
01271   p = NULL;
01272   if (fontName) {
01273     for (i = 0; i < psNamedFonts16->getLength(); ++i) {
01274       p = (PSFontParam *)psNamedFonts16->get(i);
01275       if (!p->pdfFontName->cmp(fontName) &&
01276          p->wMode == wMode) {
01277        break;
01278       }
01279       p = NULL;
01280     }
01281   }
01282   if (!p && collection) {
01283     for (i = 0; i < psFonts16->getLength(); ++i) {
01284       p = (PSFontParam *)psFonts16->get(i);
01285       if (!p->pdfFontName->cmp(collection) &&
01286          p->wMode == wMode) {
01287        break;
01288       }
01289       p = NULL;
01290     }
01291   }
01292   unlockGlobalParams;
01293   return p;
01294 }
01295 
01296 GBool GlobalParams::getPSEmbedType1() {
01297   GBool e;
01298 
01299   lockGlobalParams;
01300   e = psEmbedType1;
01301   unlockGlobalParams;
01302   return e;
01303 }
01304 
01305 GBool GlobalParams::getPSEmbedTrueType() {
01306   GBool e;
01307 
01308   lockGlobalParams;
01309   e = psEmbedTrueType;
01310   unlockGlobalParams;
01311   return e;
01312 }
01313 
01314 GBool GlobalParams::getPSEmbedCIDPostScript() {
01315   GBool e;
01316 
01317   lockGlobalParams;
01318   e = psEmbedCIDPostScript;
01319   unlockGlobalParams;
01320   return e;
01321 }
01322 
01323 GBool GlobalParams::getPSEmbedCIDTrueType() {
01324   GBool e;
01325 
01326   lockGlobalParams;
01327   e = psEmbedCIDTrueType;
01328   unlockGlobalParams;
01329   return e;
01330 }
01331 
01332 GBool GlobalParams::getPSOPI() {
01333   GBool opi;
01334 
01335   lockGlobalParams;
01336   opi = psOPI;
01337   unlockGlobalParams;
01338   return opi;
01339 }
01340 
01341 GBool GlobalParams::getPSASCIIHex() {
01342   GBool ah;
01343 
01344   lockGlobalParams;
01345   ah = psASCIIHex;
01346   unlockGlobalParams;
01347   return ah;
01348 }
01349 
01350 GString *GlobalParams::getTextEncodingName() {
01351   GString *s;
01352 
01353   lockGlobalParams;
01354   s = textEncoding->copy();
01355   unlockGlobalParams;
01356   return s;
01357 }
01358 
01359 EndOfLineKind GlobalParams::getTextEOL() {
01360   EndOfLineKind eol;
01361 
01362   lockGlobalParams;
01363   eol = textEOL;
01364   unlockGlobalParams;
01365   return eol;
01366 }
01367 
01368 GBool GlobalParams::getTextPageBreaks() {
01369   GBool pageBreaks;
01370 
01371   lockGlobalParams;
01372   pageBreaks = textPageBreaks;
01373   unlockGlobalParams;
01374   return pageBreaks;
01375 }
01376 
01377 GBool GlobalParams::getTextKeepTinyChars() {
01378   GBool tiny;
01379 
01380   lockGlobalParams;
01381   tiny = textKeepTinyChars;
01382   unlockGlobalParams;
01383   return tiny;
01384 }
01385 
01386 GString *GlobalParams::findFontFile(GString *fontName, char **exts) {
01387   GString *dir, *fileName;
01388   char **ext;
01389   FILE *f;
01390   int i;
01391 
01392   lockGlobalParams;
01393   for (i = 0; i < fontDirs->getLength(); ++i) {
01394     dir = (GString *)fontDirs->get(i);
01395     for (ext = exts; *ext; ++ext) {
01396       fileName = appendToPath(dir->copy(), fontName->getCString());
01397       fileName->append(*ext);
01398       if ((f = fopen(fileName->getCString(), "rb"))) {
01399        fclose(f);
01400        unlockGlobalParams;
01401        return fileName;
01402       }
01403       delete fileName;
01404     }
01405   }
01406   unlockGlobalParams;
01407   return NULL;
01408 }
01409 
01410 GString *GlobalParams::getInitialZoom() {
01411   GString *s;
01412 
01413   lockGlobalParams;
01414   s = initialZoom->copy();
01415   unlockGlobalParams;
01416   return s;
01417 }
01418 
01419 GBool GlobalParams::getEnableT1lib() {
01420   GBool f;
01421 
01422   lockGlobalParams;
01423   f = enableT1lib;
01424   unlockGlobalParams;
01425   return f;
01426 }
01427 
01428 GBool GlobalParams::getEnableFreeType() {
01429   GBool f;
01430 
01431   lockGlobalParams;
01432   f = enableFreeType;
01433   unlockGlobalParams;
01434   return f;
01435 }
01436 
01437 
01438 GBool GlobalParams::getAntialias() {
01439   GBool f;
01440 
01441   lockGlobalParams;
01442   f = antialias;
01443   unlockGlobalParams;
01444   return f;
01445 }
01446 
01447 GBool GlobalParams::getMapNumericCharNames() {
01448   GBool map;
01449 
01450   lockGlobalParams;
01451   map = mapNumericCharNames;
01452   unlockGlobalParams;
01453   return map;
01454 }
01455 
01456 GBool GlobalParams::getPrintCommands() {
01457   GBool p;
01458 
01459   lockGlobalParams;
01460   p = printCommands;
01461   unlockGlobalParams;
01462   return p;
01463 }
01464 
01465 GBool GlobalParams::getErrQuiet() {
01466   GBool q;
01467 
01468   lockGlobalParams;
01469   q = errQuiet;
01470   unlockGlobalParams;
01471   return q;
01472 }
01473 
01474 CharCodeToUnicode *GlobalParams::getCIDToUnicode(GString *collection) {
01475   GString *fileName;
01476   CharCodeToUnicode *ctu;
01477 
01478   lockGlobalParams;
01479   if (!(ctu = cidToUnicodeCache->getCharCodeToUnicode(collection))) {
01480     if ((fileName = (GString *)cidToUnicodes->lookup(collection)) &&
01481        (ctu = CharCodeToUnicode::parseCIDToUnicode(fileName, collection))) {
01482       cidToUnicodeCache->add(ctu);
01483     }
01484   }
01485   unlockGlobalParams;
01486   return ctu;
01487 }
01488 
01489 CharCodeToUnicode *GlobalParams::getUnicodeToUnicode(GString *fontName) {
01490   CharCodeToUnicode *ctu;
01491   GHashIter *iter;
01492   GString *fontPattern, *fileName;
01493 
01494   lockGlobalParams;
01495   fileName = NULL;
01496   unicodeToUnicodes->startIter(&iter);
01497   while (unicodeToUnicodes->getNext(&iter, &fontPattern, (void **)&fileName)) {
01498     if (strstr(fontName->getCString(), fontPattern->getCString())) {
01499       unicodeToUnicodes->killIter(&iter);
01500       break;
01501     }
01502     fileName = NULL;
01503   }
01504   if (fileName) {
01505     if (!(ctu = unicodeToUnicodeCache->getCharCodeToUnicode(fileName))) {
01506       if ((ctu = CharCodeToUnicode::parseUnicodeToUnicode(fileName))) {
01507        unicodeToUnicodeCache->add(ctu);
01508       }
01509     }
01510   } else {
01511     ctu = NULL;
01512   }
01513   unlockGlobalParams;
01514   return ctu;
01515 }
01516 
01517 UnicodeMap *GlobalParams::getUnicodeMap(GString *encodingName) {
01518   return getUnicodeMap2(encodingName);
01519 }
01520 
01521 UnicodeMap *GlobalParams::getUnicodeMap2(GString *encodingName) {
01522   UnicodeMap *map;
01523 
01524   if (!(map = getResidentUnicodeMap(encodingName))) {
01525     lockUnicodeMapCache;
01526     map = unicodeMapCache->getUnicodeMap(encodingName);
01527     unlockUnicodeMapCache;
01528   }
01529   return map;
01530 }
01531 
01532 CMap *GlobalParams::getCMap(GString *collection, GString *cMapName) {
01533   CMap *cMap;
01534 
01535   lockCMapCache;
01536   cMap = cMapCache->getCMap(collection, cMapName);
01537   unlockCMapCache;
01538   return cMap;
01539 }
01540 
01541 UnicodeMap *GlobalParams::getTextEncoding() {
01542   return getUnicodeMap2(textEncoding);
01543 }
01544 
01545 //------------------------------------------------------------------------
01546 // functions to set parameters
01547 //------------------------------------------------------------------------
01548 
01549 void GlobalParams::addDisplayFont(DisplayFontParam *param) {
01550   DisplayFontParam *old;
01551 
01552   lockGlobalParams;
01553   if ((old = (DisplayFontParam *)displayFonts->remove(param->name))) {
01554     delete old;
01555   }
01556   displayFonts->add(param->name, param);
01557   unlockGlobalParams;
01558 }
01559 
01560 void GlobalParams::setPSFile(char *file) {
01561   lockGlobalParams;
01562   if (psFile) {
01563     delete psFile;
01564   }
01565   psFile = new GString(file);
01566   unlockGlobalParams;
01567 }
01568 
01569 GBool GlobalParams::setPSPaperSize(char *size) {
01570   lockGlobalParams;
01571   if (!strcmp(size, "match")) {
01572     psPaperWidth = psPaperHeight = -1;
01573   } else if (!strcmp(size, "letter")) {
01574     psPaperWidth = 612;
01575     psPaperHeight = 792;
01576   } else if (!strcmp(size, "legal")) {
01577     psPaperWidth = 612;
01578     psPaperHeight = 1008;
01579   } else if (!strcmp(size, "A4")) {
01580     psPaperWidth = 595;
01581     psPaperHeight = 842;
01582   } else if (!strcmp(size, "A3")) {
01583     psPaperWidth = 842;
01584     psPaperHeight = 1190;
01585   } else {
01586     unlockGlobalParams;
01587     return gFalse;
01588   }
01589   psImageableLLX = psImageableLLY = 0;
01590   psImageableURX = psPaperWidth;
01591   psImageableURY = psPaperHeight;
01592   unlockGlobalParams;
01593   return gTrue;
01594 }
01595 
01596 void GlobalParams::setPSPaperWidth(int width) {
01597   lockGlobalParams;
01598   psPaperWidth = width;
01599   psImageableLLX = 0;
01600   psImageableURX = psPaperWidth;
01601   unlockGlobalParams;
01602 }
01603 
01604 void GlobalParams::setPSPaperHeight(int height) {
01605   lockGlobalParams;
01606   psPaperHeight = height;
01607   psImageableLLY = 0;
01608   psImageableURY = psPaperHeight;
01609   unlockGlobalParams;
01610 }
01611 
01612 void GlobalParams::setPSImageableArea(int llx, int lly, int urx, int ury) {
01613   lockGlobalParams;
01614   psImageableLLX = llx;
01615   psImageableLLY = lly;
01616   psImageableURX = urx;
01617   psImageableURY = ury;
01618   unlockGlobalParams;
01619 }
01620 
01621 void GlobalParams::setPSCrop(GBool crop) {
01622   lockGlobalParams;
01623   psCrop = crop;
01624   unlockGlobalParams;
01625 }
01626 
01627 void GlobalParams::setPSExpandSmaller(GBool expand) {
01628   lockGlobalParams;
01629   psExpandSmaller = expand;
01630   unlockGlobalParams;
01631 }
01632 
01633 void GlobalParams::setPSShrinkLarger(GBool shrink) {
01634   lockGlobalParams;
01635   psShrinkLarger = shrink;
01636   unlockGlobalParams;
01637 }
01638 
01639 void GlobalParams::setPSCenter(GBool center) {
01640   lockGlobalParams;
01641   psCenter = center;
01642   unlockGlobalParams;
01643 }
01644 
01645 void GlobalParams::setPSDuplex(GBool duplex) {
01646   lockGlobalParams;
01647   psDuplex = duplex;
01648   unlockGlobalParams;
01649 }
01650 
01651 void GlobalParams::setPSLevel(PSLevel level) {
01652   lockGlobalParams;
01653   psLevel = level;
01654   unlockGlobalParams;
01655 }
01656 
01657 void GlobalParams::setPSEmbedType1(GBool embed) {
01658   lockGlobalParams;
01659   psEmbedType1 = embed;
01660   unlockGlobalParams;
01661 }
01662 
01663 void GlobalParams::setPSEmbedTrueType(GBool embed) {
01664   lockGlobalParams;
01665   psEmbedTrueType = embed;
01666   unlockGlobalParams;
01667 }
01668 
01669 void GlobalParams::setPSEmbedCIDPostScript(GBool embed) {
01670   lockGlobalParams;
01671   psEmbedCIDPostScript = embed;
01672   unlockGlobalParams;
01673 }
01674 
01675 void GlobalParams::setPSEmbedCIDTrueType(GBool embed) {
01676   lockGlobalParams;
01677   psEmbedCIDTrueType = embed;
01678   unlockGlobalParams;
01679 }
01680 
01681 void GlobalParams::setPSOPI(GBool opi) {
01682   lockGlobalParams;
01683   psOPI = opi;
01684   unlockGlobalParams;
01685 }
01686 
01687 void GlobalParams::setPSASCIIHex(GBool hex) {
01688   lockGlobalParams;
01689   psASCIIHex = hex;
01690   unlockGlobalParams;
01691 }
01692 
01693 void GlobalParams::setTextEncoding(char *encodingName) {
01694   lockGlobalParams;
01695   delete textEncoding;
01696   textEncoding = new GString(encodingName);
01697   unlockGlobalParams;
01698 }
01699 
01700 GBool GlobalParams::setTextEOL(char *s) {
01701   lockGlobalParams;
01702   if (!strcmp(s, "unix")) {
01703     textEOL = eolUnix;
01704   } else if (!strcmp(s, "dos")) {
01705     textEOL = eolDOS;
01706   } else if (!strcmp(s, "mac")) {
01707     textEOL = eolMac;
01708   } else {
01709     unlockGlobalParams;
01710     return gFalse;
01711   }
01712   unlockGlobalParams;
01713   return gTrue;
01714 }
01715 
01716 void GlobalParams::setTextPageBreaks(GBool pageBreaks) {
01717   lockGlobalParams;
01718   textPageBreaks = pageBreaks;
01719   unlockGlobalParams;
01720 }
01721 
01722 void GlobalParams::setTextKeepTinyChars(GBool keep) {
01723   lockGlobalParams;
01724   textKeepTinyChars = keep;
01725   unlockGlobalParams;
01726 }
01727 
01728 void GlobalParams::setInitialZoom(char *s) {
01729   lockGlobalParams;
01730   delete initialZoom;
01731   initialZoom = new GString(s);
01732   unlockGlobalParams;
01733 }
01734 
01735 GBool GlobalParams::setEnableT1lib(char *s) {
01736   GBool ok;
01737 
01738   lockGlobalParams;
01739   ok = parseYesNo2(s, &enableT1lib);
01740   unlockGlobalParams;
01741   return ok;
01742 }
01743 
01744 GBool GlobalParams::setEnableFreeType(char *s) {
01745   GBool ok;
01746 
01747   lockGlobalParams;
01748   ok = parseYesNo2(s, &enableFreeType);
01749   unlockGlobalParams;
01750   return ok;
01751 }
01752 
01753 
01754 GBool GlobalParams::setAntialias(char *s) {
01755   GBool ok;
01756 
01757   lockGlobalParams;
01758   ok = parseYesNo2(s, &antialias);
01759   unlockGlobalParams;
01760   return ok;
01761 }
01762 
01763 void GlobalParams::setMapNumericCharNames(GBool map) {
01764   lockGlobalParams;
01765   mapNumericCharNames = map;
01766   unlockGlobalParams;
01767 }
01768 
01769 void GlobalParams::setPrintCommands(GBool printCommandsA) {
01770   lockGlobalParams;
01771   printCommands = printCommandsA;
01772   unlockGlobalParams;
01773 }
01774 
01775 void GlobalParams::setErrQuiet(GBool errQuietA) {
01776   lockGlobalParams;
01777   errQuiet = errQuietA;
01778   unlockGlobalParams;
01779 }