On Fri, 6 Dec 2019 14:51:39 +0100 Vincent Lefevre <vinc...@vinc17.net> wrote:
> It is not possible to search for various Unicode characters.
[...]
> The "Find" dialogue box does not accept such characters, either
> via the keyboard or via copy-paste.

It was actually worse than that -- none of the text entry boxes accepted
non-ISO-8859-1 characters, and the search operated in ISO-8859-1
regardless of your locale's character encoding! To be fair to xpdf, it
does quite considerably predate Unicode support in Motif...

I've fixed this in xpopple with the patches below (use Unicode fonts,
enable locale support, convert the search string from the locale's
encoding), but I suspect there might be other locale problems lurking,
so I'll hold off pushing this to master until I've used it in practice
for a few days.

Cheers,
Adam

diff --git a/xpdf/XPDFApp.cc b/xpdf/XPDFApp.cc
index 990a01e..de460a7 100644
--- a/xpdf/XPDFApp.cc
+++ b/xpdf/XPDFApp.cc
@@ -31,9 +31,9 @@
 //------------------------------------------------------------------------
 
 static String fallbackResources[] = {
-  "*.zoomComboBox*FontList: 
-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-1",
-  "*XmTextField.FontList: -*-courier-medium-r-normal--12-*-*-*-*-*-iso8859-1",
-  "*.FontList: -*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-1",
+  "*.zoomComboBox*FontList: 
-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso10646-1",
+  "*XmTextField.FontList: -*-courier-medium-r-normal--12-*-*-*-*-*-iso10646-1",
+  "*.FontList: -*-helvetica-medium-r-normal--12-*-*-*-*-*-iso10646-1",
   "*XmTextField.translations: #override\\n"
   "  Ctrl<Key>a:beginning-of-line()\\n"
   "  Ctrl<Key>b:backward-character()\\n"
diff --git a/xpdf/XPDFViewer.cc b/xpdf/XPDFViewer.cc
index 54380eb..8fe77c6 100644
--- a/xpdf/XPDFViewer.cc
+++ b/xpdf/XPDFViewer.cc
@@ -2767,11 +2767,11 @@ void XPDFViewer::initAboutDialog() {
 
   //----- fonts
   aboutBigFont =
-    createFontList("-*-times-bold-i-normal--20-*-*-*-*-*-iso8859-1");
+    createFontList("-*-times-bold-i-normal--20-*-*-*-*-*-iso10646-1");
   aboutVersionFont =
-    createFontList("-*-times-medium-r-normal--16-*-*-*-*-*-iso8859-1");
+    createFontList("-*-times-medium-r-normal--16-*-*-*-*-*-iso10646-1");
   aboutFixedFont =
-    createFontList("-*-courier-medium-r-normal--12-*-*-*-*-*-iso8859-1");
+    createFontList("-*-courier-medium-r-normal--12-*-*-*-*-*-iso10646-1");
 
   //----- heading
   n = 0;
diff --git a/xpdf/XPDFApp.cc b/xpdf/XPDFApp.cc
index de460a7..c72e0af 100644
--- a/xpdf/XPDFApp.cc
+++ b/xpdf/XPDFApp.cc
@@ -121,6 +121,8 @@ static int xErrorHandler(Display *display, XErrorEvent *ev) 
{
 #endif
 
 XPDFApp::XPDFApp(int *argc, char *argv[]) {
+  XtSetLanguageProc(NULL, NULL, NULL);
+
   appShell = XtAppInitialize(&appContext, xpdfAppName, xOpts, nXOpts,
                             argc, argv, fallbackResources, NULL, 0);
   display = XtDisplay(appShell);
diff --git a/xpdf/PDFCore.cc b/xpdf/PDFCore.cc
index 4e7814b..aab0a18 100644
--- a/xpdf/PDFCore.cc
+++ b/xpdf/PDFCore.cc
@@ -12,6 +12,7 @@
 
 #include <math.h>
 #include <memory>
+#include <stdlib.h>
 #include <goo/GooString.h>
 #include "GlobalParams.h"
 #include "XPDFParams.h"
@@ -1650,16 +1651,21 @@ GooString *PDFCore::extractText(int pg, double xMin, 
double yMin,
 
 bool PDFCore::find(const char *s, bool caseSensitive, bool next, bool backward,
                   bool wholeWord, bool onePageOnly) {
+  wchar_t *wbuf;
   Unicode *u;
   int len, i;
   bool ret;
 
-  // convert to Unicode
-  len = (int)strlen(s);
+  // Convert from the current locale's encoding to Unicode.
+  // (Poppler's Unicode type is not necessarily the same as wchar_t!)
+  len = (int)mbstowcs(NULL, s, 0);
+  wbuf = (wchar_t *)gmallocn(len + 1, sizeof(wchar_t));
+  mbstowcs(wbuf, s, len + 1);
   u = (Unicode *)gmallocn(len, sizeof(Unicode));
   for (i = 0; i < len; ++i) {
-    u[i] = (Unicode)(s[i] & 0xff);
+    u[i] = (Unicode)wbuf[i];
   }
+  gfree(wbuf);
 
   ret = findU(u, len, caseSensitive, next, backward, wholeWord, onePageOnly);
 
-- 
Adam Sampson <a...@offog.org>                         <http://offog.org/>

Reply via email to