]> 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 b50c15bd1cfcfd2eab951dfbc1b465b4464f417c..c5083b2afc41ef1f758a21e8e28c4a78d412fbb5 100644 (file)
@@ -2,7 +2,7 @@
 //
 // GlobalParams.cc
 //
-// Copyright 2001-2002 Glyph & Cog, LLC
+// Copyright 2001-2003 Glyph & Cog, LLC
 //
 //========================================================================
 
 #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"
@@ -124,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
@@ -276,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();
@@ -293,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 &&
@@ -329,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")) {
@@ -428,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) {
@@ -794,6 +818,10 @@ GlobalParams::~GlobalParams() {
   delete cidToUnicodeCache;
   delete unicodeMapCache;
   delete cMapCache;
+
+#if MULTITHREADED
+  gDestroyMutex(&mutex);
+#endif
 }
 
 //------------------------------------------------------------------------
@@ -870,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,
@@ -884,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);
 }
@@ -917,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;
@@ -947,26 +1088,105 @@ 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;
 }
 
 //------------------------------------------------------------------------
@@ -976,21 +1196,28 @@ UnicodeMap *GlobalParams::getTextEncoding() {
 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")) {
@@ -1003,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")) {
@@ -1061,26 +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) {
@@ -1099,13 +1367,19 @@ GBool GlobalParams::setFontRastControl(FontRastControl *val, char *s) {
 }
 
 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;
 }