]> www.fi.muni.cz Git - evince.git/blobdiff - pdf/xpdf/GlobalParams.cc
Reused eog HIG dialog in GPdf.
[evince.git] / pdf / xpdf / GlobalParams.cc
index 0bc908eada7a8c4d78f01fa65996887ac34ffbbb..c5083b2afc41ef1f758a21e8e28c4a78d412fbb5 100644 (file)
@@ -2,15 +2,16 @@
 //
 // GlobalParams.cc
 //
-// Copyright 2001-2002 Glyph & Cog, LLC
+// Copyright 2001-2003 Glyph & Cog, LLC
 //
 //========================================================================
 
-#ifdef __GNUC__
+#include <aconf.h>
+
+#ifdef USE_GCC_PRAGMAS
 #pragma implementation
 #endif
 
-#include <aconf.h>
 #include <string.h>
 #include <ctype.h>
 #if HAVE_PAPER_H
 #include "FontEncodingTables.h"
 #include "GlobalParams.h"
 
+#if MULTITHREADED
+#  define globalParamsLock gLockMutex(&mutex)
+#  define globalParamsUnlock gUnlockMutex(&mutex)
+#else
+#  define globalParamsLock
+#  define globalParamsUnlock
+#endif
+
 #include "NameToUnicodeTable.h"
 #include "UnicodeMapTables.h"
 #include "DisplayFontTable.h"
@@ -123,6 +132,10 @@ GlobalParams::GlobalParams(char *cfgFileName) {
   FILE *f;
   int i;
 
+#if MULTITHREADED
+  gInitMutex(&mutex);
+#endif
+
   initBuiltinFontTables();
 
   // scan the encoding in reverse because we want the lowest-numbered
@@ -144,11 +157,18 @@ GlobalParams::GlobalParams(char *cfgFileName) {
   displayCIDFonts = new GHash();
   displayNamedCIDFonts = new GHash();
 #if HAVE_PAPER_H
+  char *paperName;
   const struct paper *paperType;
   paperinit();
-  paperType = paperinfo(systempapername());
-  psPaperWidth = (int)paperpswidth(paperType);
-  psPaperHeight = (int)paperpsheight(paperType);
+  if ((paperName = systempapername())) {
+    paperType = paperinfo(paperName);
+    psPaperWidth = (int)paperpswidth(paperType);
+    psPaperHeight = (int)paperpsheight(paperType);
+  } else {
+    error(-1, "No paper information available - using defaults");
+    psPaperWidth = defPaperWidth;
+    psPaperHeight = defPaperHeight;
+  }
   paperdone();
 #else
   psPaperWidth = defPaperWidth;
@@ -174,12 +194,15 @@ GlobalParams::GlobalParams(char *cfgFileName) {
 #else
   textEOL = eolUnix;
 #endif
+  textKeepTinyChars = gFalse;
   fontDirs = new GList();
   initialZoom = new GString("1");
   t1libControl = fontRastAALow;
   freetypeControl = fontRastAALow;
   urlCommand = NULL;
+  movieCommand = NULL;
   mapNumericCharNames = gTrue;
+  printCommands = gFalse;
   errQuiet = gFalse;
 
   cidToUnicodeCache = new CIDToUnicodeCache();
@@ -192,18 +215,21 @@ GlobalParams::GlobalParams(char *cfgFileName) {
   }
 
   // set up the residentUnicodeMaps table
-  map = new UnicodeMap("Latin1", latin1UnicodeMapRanges, latin1UnicodeMapLen);
+  map = new UnicodeMap("Latin1", gFalse,
+                      latin1UnicodeMapRanges, latin1UnicodeMapLen);
   residentUnicodeMaps->add(map->getEncodingName(), map);
-  map = new UnicodeMap("ASCII7", ascii7UnicodeMapRanges, ascii7UnicodeMapLen);
+  map = new UnicodeMap("ASCII7", gFalse,
+                      ascii7UnicodeMapRanges, ascii7UnicodeMapLen);
   residentUnicodeMaps->add(map->getEncodingName(), map);
-  map = new UnicodeMap("Symbol", symbolUnicodeMapRanges, symbolUnicodeMapLen);
+  map = new UnicodeMap("Symbol", gFalse,
+                      symbolUnicodeMapRanges, symbolUnicodeMapLen);
   residentUnicodeMaps->add(map->getEncodingName(), map);
-  map = new UnicodeMap("ZapfDingbats", zapfDingbatsUnicodeMapRanges,
+  map = new UnicodeMap("ZapfDingbats", gFalse, zapfDingbatsUnicodeMapRanges,
                       zapfDingbatsUnicodeMapLen);
   residentUnicodeMaps->add(map->getEncodingName(), map);
-  map = new UnicodeMap("UTF-8", &mapUTF8);
+  map = new UnicodeMap("UTF-8", gTrue, &mapUTF8);
   residentUnicodeMaps->add(map->getEncodingName(), map);
-  map = new UnicodeMap("UCS-2", &mapUCS2);
+  map = new UnicodeMap("UCS-2", gTrue, &mapUCS2);
   residentUnicodeMaps->add(map->getEncodingName(), map);
 
   // default displayFonts table
@@ -235,7 +261,7 @@ GlobalParams::GlobalParams(char *cfgFileName) {
     i = GetModuleFileName(NULL, buf, sizeof(buf));
     if (i <= 0 || i >= sizeof(buf)) {
       // error or path too long for buffer - just use the current dir
-      buf[i] = '\0';
+      buf[0] = '\0';
     }
     fileName = grabPath(buf);
     appendToPath(fileName, xpdfSysConfigFile);
@@ -249,6 +275,7 @@ GlobalParams::GlobalParams(char *cfgFileName) {
   if (f) {
     parseFile(fileName, f);
     delete fileName;
+    fclose(f);
   }
 }
 
@@ -261,7 +288,7 @@ void GlobalParams::parseFile(GString *fileName, FILE *f) {
   FILE *f2;
 
   line = 1;
-  while (fgets(buf, sizeof(buf) - 1, f)) {
+  while (getLine(buf, sizeof(buf) - 1, f)) {
 
     // break the line into tokens
     tokens = new GList();
@@ -278,7 +305,7 @@ void GlobalParams::parseFile(GString *fileName, FILE *f) {
        for (p2 = p1 + 1; *p2 && !isspace(*p2); ++p2) ;
       }
       tokens->append(new GString(p1, p2 - p1));
-      p1 = p2 + 1;
+      p1 = *p2 ? p2 + 1 : p2;
     }
 
     if (tokens->getLength() > 0 &&
@@ -314,12 +341,24 @@ void GlobalParams::parseFile(GString *fileName, FILE *f) {
        parseDisplayFont(tokens, displayFonts, displayFontT1, fileName, line);
       } else if (!cmd->cmp("displayFontTT")) {
        parseDisplayFont(tokens, displayFonts, displayFontTT, fileName, line);
+      } else if (!cmd->cmp("displayNamedCIDFontX")) {
+       parseDisplayFont(tokens, displayNamedCIDFonts,
+                        displayFontX, fileName, line);
       } else if (!cmd->cmp("displayCIDFontX")) {
        parseDisplayFont(tokens, displayCIDFonts,
                         displayFontX, fileName, line);
-      } else if (!cmd->cmp("displayNamedCIDFontX")) {
+      } else if (!cmd->cmp("displayNamedCIDFontT1")) {
        parseDisplayFont(tokens, displayNamedCIDFonts,
-                        displayFontX, fileName, line);
+                        displayFontT1, fileName, line);
+      } else if (!cmd->cmp("displayCIDFontT1")) {
+       parseDisplayFont(tokens, displayCIDFonts,
+                        displayFontT1, fileName, line);
+      } else if (!cmd->cmp("displayNamedCIDFontTT")) {
+       parseDisplayFont(tokens, displayNamedCIDFonts,
+                        displayFontTT, fileName, line);
+      } else if (!cmd->cmp("displayCIDFontTT")) {
+       parseDisplayFont(tokens, displayCIDFonts,
+                        displayFontTT, fileName, line);
       } else if (!cmd->cmp("psFile")) {
        parsePSFile(tokens, fileName, line);
       } else if (!cmd->cmp("psFont")) {
@@ -354,6 +393,9 @@ void GlobalParams::parseFile(GString *fileName, FILE *f) {
        parseTextEncoding(tokens, fileName, line);
       } else if (!cmd->cmp("textEOL")) {
        parseTextEOL(tokens, fileName, line);
+      } else if (!cmd->cmp("textKeepTinyChars")) {
+       parseYesNo("textKeepTinyChars", &textKeepTinyChars,
+                  tokens, fileName, line);
       } else if (!cmd->cmp("fontDir")) {
        parseFontDir(tokens, fileName, line);
       } else if (!cmd->cmp("initialZoom")) {
@@ -365,10 +407,14 @@ void GlobalParams::parseFile(GString *fileName, FILE *f) {
        parseFontRastControl("freetypeControl", &freetypeControl,
                             tokens, fileName, line);
       } else if (!cmd->cmp("urlCommand")) {
-       parseURLCommand(tokens, fileName, line);
+       parseCommand("urlCommand", &urlCommand, tokens, fileName, line);
+      } else if (!cmd->cmp("movieCommand")) {
+       parseCommand("movieCommand", &movieCommand, tokens, fileName, line);
       } else if (!cmd->cmp("mapNumericCharNames")) {
        parseYesNo("mapNumericCharNames", &mapNumericCharNames,
                   tokens, fileName, line);
+      } else if (!cmd->cmp("printCommands")) {
+       parseYesNo("printCommands", &printCommands, tokens, fileName, line);
       } else if (!cmd->cmp("errQuiet")) {
        parseYesNo("errQuiet", &errQuiet, tokens, fileName, line);
       } else if (!cmd->cmp("fontpath") || !cmd->cmp("fontmap")) {
@@ -406,7 +452,7 @@ void GlobalParams::parseNameToUnicode(GList *tokens, GString *fileName,
     return;
   }
   line2 = 1;
-  while (fgets(buf, sizeof(buf), f)) {
+  while (getLine(buf, sizeof(buf), f)) {
     tok1 = strtok(buf, " \t\r\n");
     tok2 = strtok(NULL, " \t\r\n");
     if (tok1 && tok2) {
@@ -697,17 +743,17 @@ void GlobalParams::parseFontRastControl(char *cmdName, FontRastControl *val,
   }
 }
 
-void GlobalParams::parseURLCommand(GList *tokens, GString *fileName,
-                                  int line) {
+void GlobalParams::parseCommand(char *cmdName, GString **val,
+                               GList *tokens, GString *fileName, int line) {
   if (tokens->getLength() != 2) {
-    error(-1, "Bad 'urlCommand' config file command (%s:%d)",
-         fileName->getCString(), line);
+    error(-1, "Bad '%s' config file command (%s:%d)",
+         cmdName, fileName->getCString(), line);
     return;
   }
-  if (urlCommand) {
-    delete urlCommand;
+  if (*val) {
+    delete *val;
   }
-  urlCommand = ((GString *)tokens->get(1))->copy();
+  *val = ((GString *)tokens->get(1))->copy();
 }
 
 void GlobalParams::parseYesNo(char *cmdName, GBool *flag,
@@ -759,6 +805,9 @@ GlobalParams::~GlobalParams() {
   if (urlCommand) {
     delete urlCommand;
   }
+  if (movieCommand) {
+    delete movieCommand;
+  }
 
   cMapDirs->startIter(&iter);
   while (cMapDirs->getNext(&iter, &key, (void **)&list)) {
@@ -769,6 +818,10 @@ GlobalParams::~GlobalParams() {
   delete cidToUnicodeCache;
   delete unicodeMapCache;
   delete cMapCache;
+
+#if MULTITHREADED
+  gDestroyMutex(&mutex);
+#endif
 }
 
 //------------------------------------------------------------------------
@@ -845,7 +898,12 @@ FILE *GlobalParams::findToUnicodeFile(GString *name) {
 }
 
 DisplayFontParam *GlobalParams::getDisplayFont(GString *fontName) {
-  return (DisplayFontParam *)displayFonts->lookup(fontName);
+  DisplayFontParam *dfp;
+
+  globalParamsLock;
+  dfp = (DisplayFontParam *)displayFonts->lookup(fontName);
+  globalParamsUnlock;
+  return dfp;
 }
 
 DisplayFontParam *GlobalParams::getDisplayCIDFont(GString *fontName,
@@ -859,6 +917,51 @@ DisplayFontParam *GlobalParams::getDisplayCIDFont(GString *fontName,
   return dfp;
 }
 
+GString *GlobalParams::getPSFile() {
+  GString *s;
+
+  globalParamsLock;
+  s = psFile ? psFile->copy() : (GString *)NULL;
+  globalParamsUnlock;
+  return s;
+}
+
+int GlobalParams::getPSPaperWidth() {
+  int w;
+
+  globalParamsLock;
+  w = psPaperWidth;
+  globalParamsUnlock;
+  return w;
+}
+
+int GlobalParams::getPSPaperHeight() {
+  int h;
+
+  globalParamsLock;
+  h = psPaperHeight;
+  globalParamsUnlock;
+  return h;
+}
+
+GBool GlobalParams::getPSDuplex() {
+  GBool d;
+
+  globalParamsLock;
+  d = psDuplex;
+  globalParamsUnlock;
+  return d;
+}
+
+PSLevel GlobalParams::getPSLevel() {
+  PSLevel level;
+
+  globalParamsLock;
+  level = psLevel;
+  globalParamsUnlock;
+  return level;
+}
+
 PSFontParam *GlobalParams::getPSFont(GString *fontName) {
   return (PSFontParam *)psFonts->lookup(fontName);
 }
@@ -892,26 +995,89 @@ PSFontParam *GlobalParams::getPSFont16(GString *fontName,
   return p;
 }
 
-GString *GlobalParams::findFontFile(GString *fontName,
-                                   char *ext1, char *ext2) {
+GBool GlobalParams::getPSEmbedType1() {
+  GBool e;
+
+  globalParamsLock;
+  e = psEmbedType1;
+  globalParamsUnlock;
+  return e;
+}
+
+GBool GlobalParams::getPSEmbedTrueType() {
+  GBool e;
+
+  globalParamsLock;
+  e = psEmbedTrueType;
+  globalParamsUnlock;
+  return e;
+}
+
+GBool GlobalParams::getPSEmbedCIDPostScript() {
+  GBool e;
+
+  globalParamsLock;
+  e = psEmbedCIDPostScript;
+  globalParamsUnlock;
+  return e;
+}
+
+GBool GlobalParams::getPSEmbedCIDTrueType() {
+  GBool e;
+
+  globalParamsLock;
+  e = psEmbedCIDTrueType;
+  globalParamsUnlock;
+  return e;
+}
+
+GBool GlobalParams::getPSOPI() {
+  GBool opi;
+
+  globalParamsLock;
+  opi = psOPI;
+  globalParamsUnlock;
+  return opi;
+}
+
+GBool GlobalParams::getPSASCIIHex() {
+  GBool ah;
+
+  globalParamsLock;
+  ah = psASCIIHex;
+  globalParamsUnlock;
+  return ah;
+}
+
+EndOfLineKind GlobalParams::getTextEOL() {
+  EndOfLineKind eol;
+
+  globalParamsLock;
+  eol = textEOL;
+  globalParamsUnlock;
+  return eol;
+}
+
+GBool GlobalParams::getTextKeepTinyChars() {
+  GBool tiny;
+
+  globalParamsLock;
+  tiny = textKeepTinyChars;
+  globalParamsUnlock;
+  return tiny;
+}
+
+GString *GlobalParams::findFontFile(GString *fontName, char **exts) {
   GString *dir, *fileName;
+  char **ext;
   FILE *f;
   int i;
 
   for (i = 0; i < fontDirs->getLength(); ++i) {
     dir = (GString *)fontDirs->get(i);
-    if (ext1) {
-      fileName = appendToPath(dir->copy(), fontName->getCString());
-      fileName->append(ext1);
-      if ((f = fopen(fileName->getCString(), "r"))) {
-       fclose(f);
-       return fileName;
-      }
-      delete fileName;
-    }
-    if (ext2) {
+    for (ext = exts; *ext; ++ext) {
       fileName = appendToPath(dir->copy(), fontName->getCString());
-      fileName->append(ext2);
+      fileName->append(*ext);
       if ((f = fopen(fileName->getCString(), "r"))) {
        fclose(f);
        return fileName;
@@ -922,41 +1088,136 @@ GString *GlobalParams::findFontFile(GString *fontName,
   return NULL;
 }
 
+GString *GlobalParams::getInitialZoom() {
+  GString *s;
+
+  globalParamsLock;
+  s = initialZoom->copy();
+  globalParamsUnlock;
+  return s;
+}
+
+FontRastControl GlobalParams::getT1libControl() {
+  FontRastControl c;
+
+  globalParamsLock;
+  c = t1libControl;
+  globalParamsUnlock;
+  return c;
+}
+
+FontRastControl GlobalParams::getFreeTypeControl() {
+  FontRastControl c;
+
+  globalParamsLock;
+  c = freetypeControl;
+  globalParamsUnlock;
+  return c;
+}
+
+GBool GlobalParams::getMapNumericCharNames() {
+  GBool map;
+
+  globalParamsLock;
+  map = mapNumericCharNames;
+  globalParamsUnlock;
+  return map;
+}
+
+GBool GlobalParams::getPrintCommands() {
+  GBool p;
+
+  globalParamsLock;
+  p = printCommands;
+  globalParamsUnlock;
+  return p;
+}
+
+GBool GlobalParams::getErrQuiet() {
+  GBool q;
+
+  globalParamsLock;
+  q = errQuiet;
+  globalParamsUnlock;
+  return q;
+}
+
 CharCodeToUnicode *GlobalParams::getCIDToUnicode(GString *collection) {
-  return cidToUnicodeCache->getCIDToUnicode(collection);
+  CharCodeToUnicode *ctu;
+
+  globalParamsLock;
+  ctu = cidToUnicodeCache->getCIDToUnicode(collection);
+  globalParamsUnlock;
+  return ctu;
 }
 
 UnicodeMap *GlobalParams::getUnicodeMap(GString *encodingName) {
   UnicodeMap *map;
 
+  globalParamsLock;
+  map = getUnicodeMap2(encodingName);
+  globalParamsUnlock;
+  return map;
+}
+
+UnicodeMap *GlobalParams::getUnicodeMap2(GString *encodingName) {
+  UnicodeMap *map;
+
   if ((map = getResidentUnicodeMap(encodingName))) {
     map->incRefCnt();
-    return map;
+  } else {
+    map = unicodeMapCache->getUnicodeMap(encodingName);
   }
-  return unicodeMapCache->getUnicodeMap(encodingName);
+  return map;
 }
 
 CMap *GlobalParams::getCMap(GString *collection, GString *cMapName) {
-  return cMapCache->getCMap(collection, cMapName);
+  CMap *cMap;
+
+  globalParamsLock;
+  cMap = cMapCache->getCMap(collection, cMapName);
+  globalParamsUnlock;
+  return cMap;
 }
 
 UnicodeMap *GlobalParams::getTextEncoding() {
-  return getUnicodeMap(textEncoding);
+  UnicodeMap *map;
+
+  globalParamsLock;
+  map = getUnicodeMap2(textEncoding);
+  globalParamsUnlock;
+  return map;
 }
 
 //------------------------------------------------------------------------
 // functions to set parameters
 //------------------------------------------------------------------------
 
+void GlobalParams::addDisplayFont(DisplayFontParam *param) {
+  DisplayFontParam *old;
+
+  globalParamsLock;
+  if ((old = (DisplayFontParam *)displayFonts->remove(param->name))) {
+    delete old;
+  }
+  displayFonts->add(param->name, param);
+  globalParamsUnlock;
+}
+
 void GlobalParams::setPSFile(char *file) {
+  globalParamsLock;
   if (psFile) {
     delete psFile;
   }
   psFile = new GString(file);
+  globalParamsUnlock;
 }
 
 GBool GlobalParams::setPSPaperSize(char *size) {
-  if (!strcmp(size, "letter")) {
+  globalParamsLock;
+  if (!strcmp(size, "match")) {
+    psPaperWidth = psPaperHeight = -1;
+  } else if (!strcmp(size, "letter")) {
     psPaperWidth = 612;
     psPaperHeight = 792;
   } else if (!strcmp(size, "legal")) {
@@ -969,57 +1230,82 @@ GBool GlobalParams::setPSPaperSize(char *size) {
     psPaperWidth = 842;
     psPaperHeight = 1190;
   } else {
+    globalParamsUnlock;
     return gFalse;
   }
+  globalParamsUnlock;
   return gTrue;
 }
 
 void GlobalParams::setPSPaperWidth(int width) {
+  globalParamsLock;
   psPaperWidth = width;
+  globalParamsUnlock;
 }
 
 void GlobalParams::setPSPaperHeight(int height) {
+  globalParamsLock;
   psPaperHeight = height;
+  globalParamsUnlock;
 }
 
 void GlobalParams::setPSDuplex(GBool duplex) {
+  globalParamsLock;
   psDuplex = duplex;
+  globalParamsUnlock;
 }
 
 void GlobalParams::setPSLevel(PSLevel level) {
+  globalParamsLock;
   psLevel = level;
+  globalParamsUnlock;
 }
 
 void GlobalParams::setPSEmbedType1(GBool embed) {
+  globalParamsLock;
   psEmbedType1 = embed;
+  globalParamsUnlock;
 }
 
 void GlobalParams::setPSEmbedTrueType(GBool embed) {
+  globalParamsLock;
   psEmbedTrueType = embed;
+  globalParamsUnlock;
 }
 
 void GlobalParams::setPSEmbedCIDPostScript(GBool embed) {
+  globalParamsLock;
   psEmbedCIDPostScript = embed;
+  globalParamsUnlock;
 }
 
 void GlobalParams::setPSEmbedCIDTrueType(GBool embed) {
+  globalParamsLock;
   psEmbedCIDTrueType = embed;
+  globalParamsUnlock;
 }
 
 void GlobalParams::setPSOPI(GBool opi) {
+  globalParamsLock;
   psOPI = opi;
+  globalParamsUnlock;
 }
 
 void GlobalParams::setPSASCIIHex(GBool hex) {
+  globalParamsLock;
   psASCIIHex = hex;
+  globalParamsUnlock;
 }
 
 void GlobalParams::setTextEncoding(char *encodingName) {
+  globalParamsLock;
   delete textEncoding;
   textEncoding = new GString(encodingName);
+  globalParamsUnlock;
 }
 
 GBool GlobalParams::setTextEOL(char *s) {
+  globalParamsLock;
   if (!strcmp(s, "unix")) {
     textEOL = eolUnix;
   } else if (!strcmp(s, "dos")) {
@@ -1027,22 +1313,42 @@ GBool GlobalParams::setTextEOL(char *s) {
   } else if (!strcmp(s, "mac")) {
     textEOL = eolMac;
   } else {
+    globalParamsUnlock;
     return gFalse;
   }
+  globalParamsUnlock;
   return gTrue;
 }
 
+void GlobalParams::setTextKeepTinyChars(GBool keep) {
+  globalParamsLock;
+  textKeepTinyChars = keep;
+  globalParamsUnlock;
+}
+
 void GlobalParams::setInitialZoom(char *s) {
+  globalParamsLock;
   delete initialZoom;
   initialZoom = new GString(s);
+  globalParamsUnlock;
 }
 
 GBool GlobalParams::setT1libControl(char *s) {
-  return setFontRastControl(&t1libControl, s);
+  GBool ok;
+
+  globalParamsLock;
+  ok = setFontRastControl(&t1libControl, s);
+  globalParamsUnlock;
+  return ok;
 }
 
 GBool GlobalParams::setFreeTypeControl(char *s) {
-  return setFontRastControl(&freetypeControl, s);
+  GBool ok;
+
+  globalParamsLock;
+  ok = setFontRastControl(&freetypeControl, s);
+  globalParamsUnlock;
+  return ok;
 }
 
 GBool GlobalParams::setFontRastControl(FontRastControl *val, char *s) {
@@ -1060,6 +1366,20 @@ GBool GlobalParams::setFontRastControl(FontRastControl *val, char *s) {
   return gTrue;
 }
 
+void GlobalParams::setMapNumericCharNames(GBool map) {
+  globalParamsLock;
+  mapNumericCharNames = map;
+  globalParamsUnlock;
+}
+
+void GlobalParams::setPrintCommands(GBool printCommandsA) {
+  globalParamsLock;
+  printCommands = printCommandsA;
+  globalParamsUnlock;
+}
+
 void GlobalParams::setErrQuiet(GBool errQuietA) {
+  globalParamsLock;
   errQuiet = errQuietA;
+  globalParamsUnlock;
 }