[poppler] Branch 'xpdf303merge' - 3 commits - fofi/FoFiType1C.cc goo/gfile.cc goo/gfile.h poppler/CharCodeToUnicode.cc poppler/GlobalParams.cc

Albert Astals Cid aacid at kemper.freedesktop.org
Thu Sep 1 14:28:20 PDT 2011


 fofi/FoFiType1C.cc           |    2 
 goo/gfile.cc                 |  108 +++++++++++++++++++++++++++++++++++++++++--
 goo/gfile.h                  |   13 +++++
 poppler/CharCodeToUnicode.cc |    4 -
 poppler/GlobalParams.cc      |   10 +--
 5 files changed, 127 insertions(+), 10 deletions(-)

New commits:
commit 830d2b40770333489a08f23a3b16a372770a8d19
Author: Albert Astals Cid <aacid at kde.org>
Date:   Thu Sep 1 23:23:57 2011 +0200

    xpdf303: Use openFile

diff --git a/poppler/CharCodeToUnicode.cc b/poppler/CharCodeToUnicode.cc
index 4befdc8..e44f304 100644
--- a/poppler/CharCodeToUnicode.cc
+++ b/poppler/CharCodeToUnicode.cc
@@ -123,7 +123,7 @@ CharCodeToUnicode *CharCodeToUnicode::parseCIDToUnicode(GooString *fileName,
   Unicode u;
   CharCodeToUnicode *ctu;
 
-  if (!(f = fopen(fileName->getCString(), "r"))) {
+  if (!(f = openFile(fileName->getCString(), "r"))) {
     error(errIO, -1, "Couldn't open cidToUnicode file '{0:t}'",
 	  fileName);
     return NULL;
@@ -170,7 +170,7 @@ CharCodeToUnicode *CharCodeToUnicode::parseUnicodeToUnicode(
   int line, n, i;
   char *tokptr;
 
-  if (!(f = fopen(fileName->getCString(), "r"))) {
+  if (!(f = openFile(fileName->getCString(), "r"))) {
     gfree(uBuf);
     error(errIO, -1, "Couldn't open unicodeToUnicode file '{0:t}'",
 	  fileName);
diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc
index f49950d..dc08ccc 100644
--- a/poppler/GlobalParams.cc
+++ b/poppler/GlobalParams.cc
@@ -798,7 +798,7 @@ void GlobalParams::parseNameToUnicode(GooString *name) {
   Unicode u;
   char *tokptr;
 
-  if (!(f = fopen(name->getCString(), "r"))) {
+  if (!(f = openFile(name->getCString(), "r"))) {
     error(errIO, -1, "Couldn't open 'nameToUnicode' file '{0:t}'",
 	  name);
     return;
@@ -957,7 +957,7 @@ FILE *GlobalParams::getUnicodeMapFile(GooString *encodingName) {
 
   lockGlobalParams;
   if ((fileName = (GooString *)unicodeMaps->lookup(encodingName))) {
-    f = fopen(fileName->getCString(), "r");
+    f = openFile(fileName->getCString(), "r");
   } else {
     f = NULL;
   }
@@ -980,7 +980,7 @@ FILE *GlobalParams::findCMapFile(GooString *collection, GooString *cMapName) {
   for (i = 0; i < list->getLength(); ++i) {
     dir = (GooString *)list->get(i);
     fileName = appendToPath(dir->copy(), cMapName->getCString());
-    f = fopen(fileName->getCString(), "r");
+    f = openFile(fileName->getCString(), "r");
     delete fileName;
     if (f) {
       unlockGlobalParams;
@@ -1000,7 +1000,7 @@ FILE *GlobalParams::findToUnicodeFile(GooString *name) {
   for (i = 0; i < toUnicodeDirs->getLength(); ++i) {
     dir = (GooString *)toUnicodeDirs->get(i);
     fileName = appendToPath(dir->copy(), name->getCString());
-    f = fopen(fileName->getCString(), "r");
+    f = openFile(fileName->getCString(), "r");
     delete fileName;
     if (f) {
       unlockGlobalParams;
@@ -1487,7 +1487,7 @@ GooString *GlobalParams::findFontFile(GooString *fontName, const char **exts) {
     for (ext = exts; *ext; ++ext) {
       fileName = appendToPath(dir->copy(), fontName->getCString());
       fileName->append(*ext);
-      if ((f = fopen(fileName->getCString(), "rb"))) {
+      if ((f = openFile(fileName->getCString(), "rb"))) {
 	fclose(f);
 	unlockGlobalParams;
 	return fileName;
commit ddf9d6e35b40b902519cbaa8cb664ba6dfdfd510
Author: Albert Astals Cid <aacid at kde.org>
Date:   Thu Sep 1 23:21:26 2011 +0200

    xpdf303: openFile + minor fixes for openTempFile in Windows

diff --git a/goo/gfile.cc b/goo/gfile.cc
index 2e4271f..7522424 100644
--- a/goo/gfile.cc
+++ b/goo/gfile.cc
@@ -39,6 +39,7 @@
 #    include <sys/stat.h>
 #    include <fcntl.h>
 #  endif
+#  include <time.h>
 #  include <limits.h>
 #  include <string.h>
 #  if !defined(VMS) && !defined(ACORN) && !defined(MACOS)
@@ -476,11 +477,11 @@ GBool openTempFile(GooString **name, FILE **f, const char *mode) {
   } else {
     s = new GooString();
   }
-  s->append("x");
+  s->appendf("x_{0:d}_{1:d}_",
+	     (int)GetCurrentProcessId(), (int)GetCurrentThreadId());
   t = (int)time(NULL);
   for (i = 0; i < 1000; ++i) {
-    sprintf(buf, "%d", t + i);
-    s2 = s->copy()->append(buf);
+    s2 = s->copy()->appendf("{0:d}", t + i);
     if (!(f2 = fopen(s2->getCString(), "r"))) {
       if (!(f2 = fopen(s2->getCString(), mode))) {
 	delete s2;
@@ -552,6 +553,107 @@ GBool executeCommand(char *cmd) {
 #endif
 }
 
+#ifdef WIN32
+GooString *fileNameToUTF8(char *path) {
+  GooString *s;
+  char *p;
+
+  s = new GooString();
+  for (p = path; *p; ++p) {
+    if (*p & 0x80) {
+      s->append((char)(0xc0 | ((*p >> 6) & 0x03)));
+      s->append((char)(0x80 | (*p & 0x3f)));
+    } else {
+      s->append(*p);
+    }
+  }
+  return s;
+}
+
+GooString *fileNameToUTF8(wchar_t *path) {
+  GooString *s;
+  wchar_t *p;
+
+  s = new GooString();
+  for (p = path; *p; ++p) {
+    if (*p < 0x80) {
+      s->append((char)*p);
+    } else if (*p < 0x800) {
+      s->append((char)(0xc0 | ((*p >> 6) & 0x1f)));
+      s->append((char)(0x80 | (*p & 0x3f)));
+    } else {
+      s->append((char)(0xe0 | ((*p >> 12) & 0x0f)));
+      s->append((char)(0x80 | ((*p >> 6) & 0x3f)));
+      s->append((char)(0x80 | (*p & 0x3f)));
+    }
+  }
+  return s;
+}
+#endif
+
+FILE *openFile(const char *path, const char *mode) {
+#ifdef WIN32
+  OSVERSIONINFO version;
+  wchar_t wPath[_MAX_PATH + 1];
+  char nPath[_MAX_PATH + 1];
+  wchar_t wMode[8];
+  const char *p;
+  int i;
+
+  // NB: _wfopen is only available in NT
+  version.dwOSVersionInfoSize = sizeof(version);
+  GetVersionEx(&version);
+  if (version.dwPlatformId == VER_PLATFORM_WIN32_NT) {
+    for (p = path, i = 0; *p && i < _MAX_PATH; ++i) {
+      if ((p[0] & 0xe0) == 0xc0 &&
+	  p[1] && (p[1] & 0xc0) == 0x80) {
+	wPath[i] = (wchar_t)(((p[0] & 0x1f) << 6) |
+			     (p[1] & 0x3f));
+	p += 2;
+      } else if ((p[0] & 0xf0) == 0xe0 &&
+		 p[1] && (p[1] & 0xc0) == 0x80 &&
+		 p[2] && (p[2] & 0xc0) == 0x80) {
+	wPath[i] = (wchar_t)(((p[0] & 0x0f) << 12) |
+			     ((p[1] & 0x3f) << 6) |
+			     (p[2] & 0x3f));
+	p += 3;
+      } else {
+	wPath[i] = (wchar_t)(p[0] & 0xff);
+	p += 1;
+      }
+    }
+    wPath[i] = (wchar_t)0;
+    for (i = 0; mode[i] && i < sizeof(mode) - 1; ++i) {
+      wMode[i] = (wchar_t)(mode[i] & 0xff);
+    }
+    wMode[i] = (wchar_t)0;
+    return _wfopen(wPath, wMode);
+  } else {
+    for (p = path, i = 0; *p && i < _MAX_PATH; ++i) {
+      if ((p[0] & 0xe0) == 0xc0 &&
+	  p[1] && (p[1] & 0xc0) == 0x80) {
+	nPath[i] = (char)(((p[0] & 0x1f) << 6) |
+			  (p[1] & 0x3f));
+	p += 2;
+      } else if ((p[0] & 0xf0) == 0xe0 &&
+		 p[1] && (p[1] & 0xc0) == 0x80 &&
+		 p[2] && (p[2] & 0xc0) == 0x80) {
+	nPath[i] = (char)(((p[1] & 0x3f) << 6) |
+			  (p[2] & 0x3f));
+	p += 3;
+      } else {
+	nPath[i] = p[0];
+	p += 1;
+      }
+    }
+    nPath[i] = '\0';
+    return fopen(nPath, mode);
+  }
+#else
+  return fopen(path, mode);
+#endif
+}
+
 char *getLine(char *buf, int size, FILE *f) {
   int c, i;
 
diff --git a/goo/gfile.h b/goo/gfile.h
index 208d391..d4b9082 100644
--- a/goo/gfile.h
+++ b/goo/gfile.h
@@ -107,6 +107,19 @@ extern GBool openTempFile(GooString **name, FILE **f, const char *mode);
 // Execute <command>.  Returns true on success.
 extern GBool executeCommand(char *cmd);
 
+#ifdef WIN32
+// Convert a file name from Latin-1 to UTF-8.
+extern GooString *fileNameToUTF8(char *path);
+
+// Convert a file name from UCS-2 to UTF-8.
+extern GooString *fileNameToUTF8(wchar_t *path);
+#endif
+
+// Open a file.  On Windows, this converts the path from UTF-8 to
+// UCS-2 and calls _wfopen (if available).  On other OSes, this simply
+// calls fopen.
+extern FILE *openFile(const char *path, const char *mode);
+
 // Just like fgets, but handles Unix, Mac, and/or DOS end-of-line
 // conventions.
 extern char *getLine(char *buf, int size, FILE *f);
commit 68e8fa9ff4f13b6703148b3eb6ea628418211243
Author: Albert Astals Cid <aacid at kde.org>
Date:   Thu Sep 1 23:17:59 2011 +0200

    xpdf303: make gcc happy

diff --git a/fofi/FoFiType1C.cc b/fofi/FoFiType1C.cc
index 1abc866..97943de 100644
--- a/fofi/FoFiType1C.cc
+++ b/fofi/FoFiType1C.cc
@@ -2093,6 +2093,8 @@ void FoFiType1C::readFD(int offset, int length, Type1CPrivateDict *pDict) {
   GBool hasFontMatrix;
 
   hasFontMatrix = gFalse;
+  fontMatrix[0] = fontMatrix[1] = fontMatrix[2] = 0; // make gcc happy
+  fontMatrix[3] = fontMatrix[4] = fontMatrix[5] = 0;
   pSize = pOffset = 0;
   pos = offset;
   nOps = 0;


More information about the poppler mailing list