diff -ur xpdf-orig/doc/pdfinfo.cat xpdf-3.02/doc/pdfinfo.cat
--- xpdf-orig/doc/pdfinfo.cat	2007-02-27 23:05:51.000000000 +0100
+++ xpdf-3.02/doc/pdfinfo.cat	2007-08-06 14:13:39.000000000 +0200
@@ -72,9 +72,10 @@
        -enc encoding-name
               Sets the encoding to  use  for  text  output.   The
               encoding-name  must  be defined with the unicodeMap
-              command (see xpdfrc(5)).  This defaults to "Latin1"
-              (which is a built-in encoding).  [config file: tex-
-              tEncoding]
+              command (see xpdfrc(5)).  This defaults to  "UTF-8"
+              in UTF-8 locales, to "Latin1" in all other  locales
+              ("UTF-8"  and  "Latin1"  are  built-in  encodings).
+              [config file: textEncoding]
 
        -opw password
               Specify the owner password for the PDF file.   Pro-
diff -ur xpdf-orig/doc/pdfinfo.hlp xpdf-3.02/doc/pdfinfo.hlp
--- xpdf-orig/doc/pdfinfo.hlp	2007-02-27 23:05:51.000000000 +0100
+++ xpdf-3.02/doc/pdfinfo.hlp	2007-08-06 14:13:39.000000000 +0200
@@ -74,9 +74,10 @@
        -enc encoding-name
               Sets the encoding to  use  for  text  output.   The
               encoding-name  must  be defined with the unicodeMap
-              command (see xpdfrc(5)).  This defaults to "Latin1"
-              (which is a built-in encoding).  [config file: tex-
-              tEncoding]
+              command (see xpdfrc(5)).  This defaults to  "UTF-8"
+              in UTF-8 locales, to "Latin1" in all other  locales
+              ("UTF-8"  and  "Latin1"  are  built-in  encodings).
+              [config file: textEncoding]
 
        -opw password
               Specify the owner password for the PDF file.   Pro-
diff -ur xpdf-orig/doc/pdfinfo.1 xpdf-3.02/doc/pdfinfo.1
--- xpdf-orig/doc/pdfinfo.1	2007-02-27 23:05:51.000000000 +0100
+++ xpdf-3.02/doc/pdfinfo.1	2007-08-06 14:13:39.000000000 +0200
@@ -102,7 +102,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 \-opw " password"
diff -ur xpdf-orig/doc/pdftotext.cat xpdf-3.02/doc/pdftotext.cat
--- xpdf-orig/doc/pdftotext.cat	2007-02-27 23:05:51.000000000 +0100
+++ xpdf-3.02/doc/pdftotext.cat	2007-08-06 14:13:39.000000000 +0200
@@ -57,9 +57,10 @@
               Sets  the  encoding  to  use  for text output.  The
               encoding-name must be defined with  the  unicodeMap
               command  (see  xpdfrc(5)).   The  encoding  name is
-              case-sensitive.  This defaults to  "Latin1"  (which
-              is  a built-in encoding).  [config file: textEncod-
-              ing]
+              case-sensitive.  It  defaults  to  "UTF-8" in UTF-8
+              locales, to "Latin1"  in all other locales ("UTF-8"
+              and   "Latin1"  are  built-in  encodings).  [config
+              file: textEncoding]
 
        -eol unix | dos | mac
               Sets the end-of-line convention  to  use  for  text
diff -ur xpdf-orig/doc/pdftotext.hlp xpdf-3.02/doc/pdftotext.hlp
--- xpdf-orig/doc/pdftotext.hlp	2007-02-27 23:05:51.000000000 +0100
+++ xpdf-3.02/doc/pdftotext.hlp	2007-08-06 14:13:39.000000000 +0200
@@ -59,9 +59,10 @@
               Sets  the  encoding  to  use  for text output.  The
               encoding-name must be defined with  the  unicodeMap
               command  (see  xpdfrc(5)).   The  encoding  name is
-              case-sensitive.  This defaults to  "Latin1"  (which
-              is  a built-in encoding).  [config file: textEncod-
-              ing]
+              case-sensitive.  This defaults to  "UTF-8" in UTF-8
+              locales, to "Latin1" in all other  locales  ("UTF-8
+              and "Latin1" are built-in encodings). [config file:
+              textEncoding]
 
        -eol unix | dos | mac
               Sets the end-of-line convention  to  use  for  text
diff -ur xpdf-orig/doc/pdftotext.1 xpdf-3.02/doc/pdftotext.1
--- xpdf-orig/doc/pdftotext.1	2007-02-27 23:05:51.000000000 +0100
+++ xpdf-3.02/doc/pdftotext.1	2007-08-06 14:13:39.000000000 +0200
@@ -64,8 +64,9 @@
 .I encoding\-name
 must be defined with the unicodeMap command (see
 .BR xpdfrc (5)).
-The encoding name is case-sensitive.  This defaults to "Latin1" (which
-is a built-in encoding).
+The encoding name is case-sensitive.  It 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"
diff -ur xpdf-orig/doc/xpdf.cat xpdf-3.02/doc/xpdf.cat
--- xpdf-orig/doc/xpdf.cat	2007-02-27 23:05:51.000000000 +0100
+++ xpdf-3.02/doc/xpdf.cat	2007-08-06 14:13:39.000000000 +0200
@@ -146,9 +146,10 @@
        -enc encoding-name
               Sets  the  encoding  to  use  for text output.  The
               encoding-name must be defined with  the  unicodeMap
-              command (see xpdfrc(5)).  This defaults to "Latin1"
-              (which is a built-in encoding).  [config file: tex-
-              tEncoding]
+              command (see xpdfrc(5)).  This defaults to  "UTF-8"
+              in UTF-8 locales, to "Latin1" in all other locales.
+              ("UTF-8" and "Latin1" are built-in encodings).
+              [config file: textEncoding]
 
        -eol unix | dos | mac
               Sets  the  end-of-line  convention  to use for text
Pouze v xpdf-3.02/doc: xpdf.cat.orig
diff -ur xpdf-orig/doc/xpdf.hlp xpdf-3.02/doc/xpdf.hlp
--- xpdf-orig/doc/xpdf.hlp	2007-02-27 23:05:51.000000000 +0100
+++ xpdf-3.02/doc/xpdf.hlp	2007-08-06 14:13:39.000000000 +0200
@@ -148,9 +148,10 @@
        -enc encoding-name
               Sets the encoding to  use  for  text  output.   The
               encoding-name  must  be defined with the unicodeMap
-              command (see xpdfrc(5)).  This defaults to "Latin1"
-              (which is a built-in encoding).  [config file: tex-
-              tEncoding]
+              command (see xpdfrc(5)).  This defaults to  "UTF-8"
+              in UTF-8 locales, to "Latin1" in all other  locales
+              ("UTF-8"  and  "Latin1"  are  built-in  encodings).
+              [config file: textEncoding]
 
        -eol unix | dos | mac
               Sets the end-of-line convention  to  use  for  text
Pouze v xpdf-3.02/doc: xpdf.hlp.orig
diff -ur xpdf-orig/doc/xpdfrc.cat xpdf-3.02/doc/xpdfrc.cat
--- xpdf-orig/doc/xpdfrc.cat	2007-02-27 23:05:51.000000000 +0100
+++ xpdf-3.02/doc/xpdfrc.cat	2007-08-06 14:14:16.000000000 +0200
@@ -317,7 +317,8 @@
               can be overridden with the  "-enc"  switch  on  the
               command  line.)   The encoding-name must be defined
               with the  unicodeMap  command  (see  above).   This
-              defaults to "Latin1".
+	      defaults to "UTF-8" in UTF-8 locales,  to  "Latin1"
+	      in all other locales.
 
        textEOL unix | dos | mac
               Sets  the  end-of-line  convention  to use for text
Pouze v xpdf-3.02/doc: xpdfrc.cat.orig
diff -ur xpdf-orig/doc/xpdfrc.hlp xpdf-3.02/doc/xpdfrc.hlp
--- xpdf-orig/doc/xpdfrc.hlp	2007-02-27 23:05:51.000000000 +0100
+++ xpdf-3.02/doc/xpdfrc.hlp	2007-08-06 14:13:39.000000000 +0200
@@ -309,7 +309,8 @@
               can be overridden with the  "-enc"  switch  on  the
               command  line.)   The encoding-name must be defined
               with the  unicodeMap  command  (see  above).   This
-              defaults to "Latin1".
+              defaults to "UTF-8" in UTF-8 locales,  to  "Latin1"
+              in all other locales.
 
        textEOL unix | dos | mac
               Sets  the  end-of-line  convention  to use for text
Pouze v xpdf-3.02/doc: xpdfrc.hlp.orig
diff -ur xpdf-orig/doc/xpdfrc.5 xpdf-3.02/doc/xpdfrc.5
--- xpdf-orig/doc/xpdfrc.5	2007-02-27 23:05:51.000000000 +0100
+++ xpdf-3.02/doc/xpdfrc.5	2007-08-06 14:13:39.000000000 +0200
@@ -333,8 +333,8 @@
 Sets the encoding to use for text output.  (This can be overridden
 with the "-enc" switch on the command line.)  The
 .I encoding\-name
-must be defined with the unicodeMap command (see above).  This
-defaults to "Latin1".
+must be defined with the unicodeMap command (see above).  It defaults
+to "UTF-8" in UTF-8 locales, to "Latin1" in all other locales.
 .TP
 .BR textEOL " unix | dos | mac"
 Sets the end-of-line convention to use for text output.  The options
Pouze v xpdf-3.02/doc: xpdfrc.5.orig
diff -ur xpdf-orig/doc/xpdf.1 xpdf-3.02/doc/xpdf.1
--- xpdf-orig/doc/xpdf.1	2007-02-27 23:05:51.000000000 +0100
+++ xpdf-3.02/doc/xpdf.1	2007-08-06 14:13:39.000000000 +0200
@@ -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"
Pouze v xpdf-3.02/doc: xpdf.1.orig
diff -ur xpdf-orig/xpdf/GlobalParams.cc xpdf-3.02/xpdf/GlobalParams.cc
--- xpdf-orig/xpdf/GlobalParams.cc	2007-02-27 23:05:52.000000000 +0100
+++ xpdf-3.02/xpdf/GlobalParams.cc	2007-08-06 14:24:43.000000000 +0200
@@ -38,6 +38,8 @@
 #include "CMap.h"
 #include "BuiltinFontTables.h"
 #include "FontEncodingTables.h"
+#include <langinfo.h>
+#include <locale.h>
 #ifdef ENABLE_PLUGINS
 #  include "XpdfPluginAPI.h"
 #endif
@@ -678,7 +680,12 @@
   psPreload = gFalse;
   psOPI = gFalse;
   psASCIIHex = gFalse;
-  textEncoding = new GString("Latin1");
+  setlocale(LC_ALL,"");
+  setlocale(LC_NUMERIC,"POSIX");
+  if (strcmp("UTF-8",nl_langinfo(CODESET)))
+	  textEncoding = new GString("Latin1");
+  else
+	  textEncoding = new GString("UTF-8");
 #if defined(WIN32)
   textEOL = eolDOS;
 #elif defined(MACOS)
diff -ur xpdf-orig/xpdf/XPDFCore.cc xpdf-3.02/xpdf/XPDFCore.cc
--- xpdf-orig/xpdf/XPDFCore.cc	2007-02-27 23:05:52.000000000 +0100
+++ xpdf-3.02/xpdf/XPDFCore.cc	2007-08-06 14:13:39.000000000 +0200
@@ -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;
   }
Pouze v xpdf-3.02/xpdf: XPDFCore.cc.orig
diff -ur xpdf-orig/xpdf/XPDFViewer.cc xpdf-3.02/xpdf/XPDFViewer.cc
--- xpdf-orig/xpdf/XPDFViewer.cc	2007-02-27 23:05:52.000000000 +0100
+++ xpdf-3.02/xpdf/XPDFViewer.cc	2007-08-06 14:13:39.000000000 +0200
@@ -2658,7 +2658,10 @@
     // create the new labels
     items = core->getDoc()->getOutline()->getItems();
     if (items && items->getLength() > 0) {
-      enc = new GString("Latin1");
+      if (strcmp("UTF-8",globalParams->getTextEncodingName()->getCString()))
+	      enc = new GString("Latin1");
+      else
+	      enc = new GString("UTF-8");
       uMap = globalParams->getUnicodeMap(enc);
       delete enc;
       setupOutlineItems(items, NULL, uMap);
Pouze v xpdf-3.02/xpdf: XPDFViewer.cc.orig
