core.git: Branch 'libreoffice-24-2' - sdext/source

2024-04-05 Thread Mike Kaganski (via logerrit)
 sdext/source/pdfimport/xpdfwrapper/wrapper_gpl.cxx |   82 +++--
 1 file changed, 61 insertions(+), 21 deletions(-)

New commits:
commit 4ad24b828b77b9ebbaf09a08eafa52093349c32f
Author: Mike Kaganski 
AuthorDate: Wed Apr 3 12:40:06 2024 +0500
Commit: Michael Stahl 
CommitDate: Fri Apr 5 10:49:54 2024 +0200

tdf#160260: make poppler wrapper executable Unicode-aware on Windows

Change-Id: I76dc31ee14d1794fa73f990e641540ff941c7201
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165735
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 
(cherry picked from commit 7b9905df455b47977968a185a7c43f35541e018b)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165717
Reviewed-by: Michael Stahl 

diff --git a/sdext/source/pdfimport/xpdfwrapper/wrapper_gpl.cxx 
b/sdext/source/pdfimport/xpdfwrapper/wrapper_gpl.cxx
index e924547e9357..383f6810b2a2 100644
--- a/sdext/source/pdfimport/xpdfwrapper/wrapper_gpl.cxx
+++ b/sdext/source/pdfimport/xpdfwrapper/wrapper_gpl.cxx
@@ -21,6 +21,8 @@
 #ifdef _WIN32
 # include 
 # include   /*_O_BINARY*/
+#define WIN32_LEAN_AND_MEAN
+#include 
 #endif
 #ifndef SYSTEM_POPPLER
 #include  // std::string
@@ -30,24 +32,58 @@
 
 FILE* g_binary_out=stderr;
 
-static const char *ownerPassword = "";
-static const char *userPassword  = "";
-static const char *outputFile= "";
-static const char *options   = "";
+#ifdef _WIN32
+
+// Use Unicode API
+
+static const wchar_t *ownerPassword = nullptr;
+static const wchar_t *userPassword  = nullptr;
+static const wchar_t *outputFile= nullptr;
+static const wchar_t *options   = L"";
+
+#define TO_STRING_VIEW(s) std::wstring_view(L##s)
+using my_string = std::wstring;
+
+// Poppler expects UTF-8 strings on Windows - see its openFile in 
poppler/goo/gfile.cc.
+static std::string myStringToStdString(std::wstring_view s)
+{
+int len = WideCharToMultiByte(CP_UTF8, 0, s.data(), s.size(), nullptr, 0, 
nullptr, nullptr);
+char* buff = static_cast(_alloca(len * sizeof(char)));
+len = WideCharToMultiByte(CP_UTF8, 0, s.data(), s.size(), buff, len, 
nullptr, nullptr);
+return std::string(buff, len);
+}
+
+#else // ! _WIN32
+
+static const char *ownerPassword = nullptr;
+static const char *userPassword  = nullptr;
+static const char *outputFile= nullptr;
+static const char *options   = "";
 
+#define TO_STRING_VIEW(s) std::string_view(s)
+using my_string = std::string;
+
+static std::string myStringToStdString(std::string&& s) { return std::move(s); 
}
+
+#endif
+
+#ifdef _WIN32
+int wmain(int argc, wchar_t **argv)
+#else
 int main(int argc, char **argv)
+#endif
 {
-int k = 0;
+int k = 1;
 while (k < argc)
 {
-if (!strcmp(argv[k], "-f"))
+if (argv[k] == TO_STRING_VIEW("-f"))
 {
 outputFile = argv[k+1];
 argc -= 2;
 for (int j = k; j < argc; ++j)
 argv[j] = argv[j+2];
 }
-else if (!strcmp(argv[k], "-o"))
+else if (argv[k] == TO_STRING_VIEW("-o"))
 {
 options = argv[k+1];
 argc -= 2;
@@ -55,14 +91,14 @@ int main(int argc, char **argv)
 argv[j] = argv[j+2];
 }
 
-else if (!strcmp(argv[k], "-opw"))
+else if (argv[k] == TO_STRING_VIEW("-opw"))
 {
 ownerPassword = argv[k+1];
 argc -= 2;
 for (int j = k; j < argc; ++j)
 argv[j] = argv[j+2];
 }
-else if (!strcmp(argv[k], "-upw"))
+else if (argv[k] == TO_STRING_VIEW("-upw"))
 {
 userPassword = argv[k+1];
 argc -= 2;
@@ -79,10 +115,10 @@ int main(int argc, char **argv)
 /* Creates an absolute path to the poppler_data directory, by taking the 
path
  * to the xpdfimport executable (provided in argv[0], and concatenating a
  * relative path to the poppler_data directory from the program directory. 
*/
-const std::string execPath = argv[0];
-const std::size_t filenameStartPos = execPath.find_last_of("/\")+1;
-const std::string programPath = execPath.substr(0,filenameStartPos);
-const std::string popplerDataPath = programPath + "../" LIBO_SHARE_FOLDER 
"/xpdfimport/poppler_data";
+const my_string execPath = argv[0];
+const std::size_t filenameStartPos = 
execPath.find_last_of(TO_STRING_VIEW("/\")) + 1;
+const my_string programPath = execPath.substr(0, filenameStartPos);
+const std::string popplerDataPath = myStringToStdString(programPath + 
my_string(TO_STRING_VIEW("../" LIBO_SHARE_FOLDER "/xpdfimport/poppler_data")));
 const char* datadir = popplerDataPath.c_str();
 #endif
 
@@ -115,22 +151,26 @@ int main(int argc, char **argv)
 }
 
 // PDFDoc takes over ownership for all strings below
-GooString* pFileName= new GooString(argv[1]);
-GooString* pErrFileName = new GooString(argv[2]);
+GooString* pFileName = new GooString(myStringToStdString(argv[1]));

core.git: Branch 'libreoffice-24-2' - sdext/source

2024-01-15 Thread Thorsten Behrens (via logerrit)
 sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx |   12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

New commits:
commit d5fde3f3fc9da416089baecef4f43e904b3969da
Author: Thorsten Behrens 
AuthorDate: Sat Jan 13 21:40:09 2024 +0100
Commit: Xisco Fauli 
CommitDate: Mon Jan 15 12:46:06 2024 +0100

Fix obscure xpdfimport crash on missing fonts

Invert logic, such that the case WMode == 0 and no font set now run
the former else branch. Happened here for an obscure pdf I was missing
some fonts for.

Change-Id: I2825c914a04f6a95d459eeeffb8091ed8f1819dc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162029
Tested-by: Jenkins
Reviewed-by: Thorsten Behrens 
(cherry picked from commit 1637610478c4493c29a29286b66250ef47507681)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162093
Reviewed-by: Michael Stahl 

diff --git a/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx 
b/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx
index 3ad139b65fa3..2517618e1019 100644
--- a/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx
+++ b/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx
@@ -956,18 +956,18 @@ void PDFOutDev::drawChar(GfxState *state, double x, 
double y,
 
 double csdx = 0.0;
 double csdy = 0.0;
-if (state->getFont()->getWMode())
+if (!state->getFont() || !state->getFont()->getWMode())
 {
-csdy = state->getCharSpace();
+csdx = state->getCharSpace();
 if (*u == ' ')
-csdy += state->getWordSpace();
+csdx += state->getWordSpace();
+csdx *= state->getHorizScaling();
 }
 else
 {
-csdx = state->getCharSpace();
+csdy = state->getCharSpace();
 if (*u == ' ')
-csdx += state->getWordSpace();
-csdx *= state->getHorizScaling();
+csdy += state->getWordSpace();
 }
 
 double cstdx = 0.0;