From cbfe08885813044c93c8d25f13c01216a18ca968 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Sun, 3 Dec 2017 20:27:08 +1030 Subject: [PATCH 12/13] win32: make char* version of GooFile::open() support unicode eventually the wchar_t* version can be removed --- goo/gfile.cc | 5 +++-- poppler/PDFDoc.cc | 18 ------------------ 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/goo/gfile.cc b/goo/gfile.cc index d28737cd..d4e20c23 100644 --- a/goo/gfile.cc +++ b/goo/gfile.cc @@ -345,13 +345,14 @@ Goffset GooFile::size() const { } GooFile* GooFile::open(const GooString *fileName) { - HANDLE handle = CreateFileA(fileName->getCString(), + wchar_t *wFileName = (wchar_t *)utf8ToUtf16(fileName->getCString()); + HANDLE handle = CreateFileW(wFileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - + delete wFileName; return handle == INVALID_HANDLE_VALUE ? NULL : new GooFile(handle); } diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc index 7339762a..cfcd70c2 100644 --- a/poppler/PDFDoc.cc +++ b/poppler/PDFDoc.cc @@ -137,31 +137,13 @@ PDFDoc::PDFDoc() PDFDoc::PDFDoc(GooString *fileNameA, GooString *ownerPassword, GooString *userPassword, void *guiDataA) { -#ifdef _WIN32 - int n, i; -#endif - init(); fileName = fileNameA; guiData = guiDataA; -#ifdef _WIN32 - n = fileName->getLength(); - fileNameU = (wchar_t *)gmallocn(n + 1, sizeof(wchar_t)); - for (i = 0; i < n; ++i) { - fileNameU[i] = (wchar_t)(fileName->getChar(i) & 0xff); - } - fileNameU[n] = L'\0'; -#endif // try to open file -#ifdef _WIN32 - wchar_t *wFileName = (wchar_t*)utf8ToUtf16(fileName->getCString()); - file = GooFile::open(wFileName); - delete wFileName; -#else file = GooFile::open(fileName); -#endif if (file == NULL) { // fopen() has failed. // Keep a copy of the errno returned by fopen so that it can be -- 2.11.0