File xpdf-poppler-cut-and-paste-default-output-encoding.patch of Package xpdf-poppler

--- BUILD/xpdf-3.02-poppler/GlobalParams.cc
+++ BUILD/xpdf-3.02-poppler/GlobalParams.cc
@@ -39,6 +39,8 @@
 #include "CMap.h"
 #include "BuiltinFontTables.h"
 #include "FontEncodingTables.h"
+#include <langinfo.h>
+#include <locale.h>
 #ifdef ENABLE_PLUGINS
 #  include "XpdfPluginAPI.h"
 #endif
@@ -687,7 +689,12 @@
   psPreload = gFalse;
   psOPI = gFalse;
   psASCIIHex = gFalse;
-  textEncoding = new GooString("UTF-8");
+  setlocale(LC_ALL,"");
+  setlocale(LC_NUMERIC,"POSIX");
+  if (strcmp("UTF-8",nl_langinfo(CODESET)))
+         textEncoding = new GooString("Latin1");
+  else
+         textEncoding = new GooString("UTF-8");
 #if defined(WIN32)
   textEOL = eolDOS;
 #elif defined(MACOS)
--- BUILD/xpdf-3.02-poppler/XPDFCore.cc
+++ BUILD/xpdf-3.02-poppler/XPDFCore.cc
@@ -427,13 +427,17 @@
 				      XtPointer *value, unsigned long *length,
 				      int *format) {
   Atom *array;
+  static Atom utf8str = XInternAtom(currentSelectionOwner->display, "UTF8_STRING", False);
 
   // send back a list of supported conversion targets
   if (*target == targetsAtom) {
     if (!(array = (Atom *)XtMalloc(sizeof(Atom)))) {
       return False;
     }
-    array[0] = XA_STRING;
+    if (strcmp("UTF-8",globalParams->getTextEncodingName()->getCString()))
+	    array[0] = XA_STRING;
+    else
+	    array[0] = utf8str;
     *value = (XtPointer)array;
     *type = XA_ATOM;
     *format = 32;
@@ -441,11 +445,11 @@
     return True;
 
   // send the selected text
-  } else if (*target == XA_STRING) {
+  } else if (*target == XA_STRING || *target == utf8str) {
     //~ for multithreading: need a mutex here
     *value = XtNewString(currentSelection->getCString());
     *length = currentSelection->getLength();
-    *type = XA_STRING;
+    *type = *target;
     *format = 8; // 8-bit elements
     return True;
   }
--- BUILD/xpdf-3.02-poppler/XPDFViewer.cc
+++ BUILD/xpdf-3.02-poppler/XPDFViewer.cc
@@ -2658,7 +2658,10 @@
     // create the new labels
     items = core->getDoc()->getOutline()->getItems();
     if (items && items->getLength() > 0) {
-      enc = new GooString("Latin1");
+      if (strcmp("UTF-8",globalParams->getTextEncodingName()->getCString()))
+             enc = new GooString("Latin1");
+      else
+             enc = new GooString("UTF-8");
       uMap = globalParams->getUnicodeMap(enc);
       delete enc;
       setupOutlineItems(items, NULL, uMap);
--- BUILD/xpdf-3.02-poppler/xpdf.1
+++ BUILD/xpdf-3.02-poppler/xpdf.1
@@ -151,7 +151,8 @@
 .I encoding\-name
 must be defined with the unicodeMap command (see
 .BR xpdfrc (5)).
-This defaults to "Latin1" (which is a built-in encoding).
+This defaults to "UTF-8" in UTF-8 locales, to "Latin1" in all other
+locales ("UTF-8" and "Latin1" are built-in encodings).
 .RB "[config file: " textEncoding ]
 .TP
 .BI \-eol " unix | dos | mac"
openSUSE Build Service is sponsored by