diff -Nuar xpdf-0.92/configure.in xpdf-0.92-thai/configure.in
--- xpdf-0.92/configure.in	Mon Dec  4 11:28:07 2000
+++ xpdf-0.92-thai/configure.in	Tue Sep  4 12:03:28 2001
@@ -19,6 +19,12 @@
 AC_ARG_ENABLE(no-text-select,
 [  --enable-no-text-select do not allow text selection],
 OPTIONS="$OPTIONS -DNO_TEXT_SELECT")
+AC_ARG_ENABLE(thai,
+[  --enable-thai           enable Thai font & output support],
+OPTIONS="$OPTIONS -DTHAI_SUPPORT")
+AC_ARG_ENABLE(thai-debug,
+[  --enable-thai-debug     enable debug messages for Thai support],
+OPTIONS="$OPTIONS -DTHAI_DEBUG")
 AC_ARG_ENABLE(opi,
 [  --enable-opi            include support for OPI comments],
 OPTIONS="$OPTIONS -DOPI_SUPPORT")
@@ -206,7 +212,7 @@
 
 dnl ##### Check for libXpm.
 if test -z "$no_x"; then
-  smr_CHECK_LIB(Xpm, Xpm, [pixmap library, used only for icon], 
+  smr_CHECK_LIB(Xpm, Xpm, [pixmap library to use icon], 
                 XpmCreatePixmapFromData, X11/xpm.h,
                 $X_LIBS $X_PRE_LIBS -lX11 $X_EXTRA_LIBS, $X_CFLAGS)
   AC_SUBST(Xpm_LIBS)
diff -Nuar xpdf-0.92/xpdf/GfxFont.cc xpdf-0.92-thai/xpdf/GfxFont.cc
--- xpdf-0.92/xpdf/GfxFont.cc	Mon Dec  4 11:28:07 2000
+++ xpdf-0.92-thai/xpdf/GfxFont.cc	Thu Sep  6 11:29:05 2001
@@ -26,6 +26,9 @@
 #include "Params.h"
 #include "FontFile.h"
 #include "GfxFont.h"
+#ifdef THAI_SUPPORT
+#include "Parser.h"
+#endif
 
 #include "FontInfo.h"
 #if JAPANESE_SUPPORT
@@ -249,6 +252,7 @@
   obj1.free();
 
   // get encoding and character widths
+  encoding = NULL;
   if (type == fontType0) {
     getType0EncAndWidths(fontDict);
   } else {
@@ -386,6 +390,63 @@
   return proc;
 }
 
+#ifdef THAI_SUPPORT
+void GfxFont::getToUnicode(Dict *fontDict)
+{
+  Object toUniRef;
+  fontDict->lookupNF("ToUnicode", &toUniRef);
+  if (toUniRef.isRef()) {
+    Object toUniObj;
+    toUniRef.fetch(&toUniObj);
+    if (toUniObj.isStream()) {
+      if (!encoding) encoding = new FontEncoding();
+      Parser parser(new Lexer(&toUniObj));
+      Object toUniElm;
+      while (!parser.getObj(&toUniElm)->isEOF()) {
+        // read until "beginbfrange"
+        if (toUniElm.isCmd("beginbfrange")) {
+          toUniElm.free();
+          // read map until "endbfrange"
+          while (!parser.getObj(&toUniElm)->isEOF() &&
+                 !toUniElm.isCmd("endbfrange"))
+          {
+            int rangeBegin = 0, rangeEnd = 0;
+            if (toUniElm.isString()) {
+              const char* s = toUniElm.getString()->getCString();
+              rangeBegin = (unsigned char)(s[0] ? s[0] : s[1]);
+            }
+            toUniElm.free();
+            parser.getObj(&toUniElm);
+            if (toUniElm.isString()) {
+              const char* s = toUniElm.getString()->getCString();
+              rangeEnd = (unsigned char)(s[0] ? s[0] : s[1]);
+            }
+            toUniElm.free();
+            parser.getObj(&toUniElm);
+            if (toUniElm.isString()) {
+              char* destStr = toUniElm.getString()->getCString();
+              unsigned int dest = ((unsigned char)destStr[0] << 8) |
+                                  ((unsigned char)destStr[1]);
+              for (int c = rangeBegin; c <= rangeEnd; ++c, ++dest) {
+                char destName[8];
+                sprintf(destName, "uni%04x", dest);
+                encoding->addChar(c, copyString(destName));
+              }
+            }
+            toUniElm.free();
+          }
+          break;
+        }
+        toUniElm.free();
+      }
+      toUniElm.free();
+    }
+    toUniObj.free();
+  }
+  toUniRef.free();
+}
+#endif // THAI_SUPPORT
+
 void GfxFont::getEncAndWidths(Dict *fontDict, BuiltinFont *builtinFont,
 			      int missingWidth) {
   Object obj1, obj2, obj3;
@@ -452,6 +513,9 @@
     }
   }
 
+#ifdef THAI_SUPPORT
+  getToUnicode(fontDict);
+#endif
   // get default base encoding
   if (!encoding) {
     if (builtinFont)
@@ -658,6 +722,10 @@
   widths16.exceps = NULL;
   widths16.excepsV = NULL;
 
+#ifdef THAI_SUPPORT
+  getToUnicode(fontDict);
+#endif
+
   // get the CIDFont
   fontDict->lookup("DescendantFonts", &obj1);
   if (!obj1.isArray() || obj1.arrayGetLength() != 1) {
@@ -962,7 +1030,7 @@
  err1:
   obj1.free();
   //~ fix this --> add 16-bit font support to FontFile
-  encoding = new FontEncoding();
+  if (!encoding) encoding = new FontEncoding();
   makeWidths(fontDict, NULL, NULL, 0);
 }
 
diff -Nuar xpdf-0.92/xpdf/GfxFont.h xpdf-0.92-thai/xpdf/GfxFont.h
--- xpdf-0.92/xpdf/GfxFont.h	Mon Dec  4 11:28:07 2000
+++ xpdf-0.92-thai/xpdf/GfxFont.h	Tue Sep  4 11:42:10 2001
@@ -186,6 +186,9 @@
   void makeWidths(Dict *fontDict, FontEncoding *builtinEncoding,
 		  Gushort *builtinWidths, int missingWidth);
   void getType0EncAndWidths(Dict *fontDict);
+#ifdef THAI_SUPPORT
+  void getToUnicode(Dict *fontDict);
+#endif
 
   GString *tag;			// PDF font tag
   Ref id;			// reference (used as unique ID)
diff -Nuar xpdf-0.92/xpdf/TextOutputDev.cc xpdf-0.92-thai/xpdf/TextOutputDev.cc
--- xpdf-0.92/xpdf/TextOutputDev.cc	Mon Dec  4 11:28:07 2000
+++ xpdf-0.92-thai/xpdf/TextOutputDev.cc	Thu Sep  6 11:29:26 2001
@@ -161,6 +161,16 @@
 
 static char **isoLatin5Subst = isoLatin1Subst;
 
+#ifdef THAI_SUPPORT
+static char *winThaiSubst[] = {
+  "\xb0", "\xd4", "\xd5", "\xd6", "\xd7", "...", "\xe8", "\xe9",
+  "\xea", "\xeb","\xec", "\xe8", "\xe9", "\xea", "\xeb","\xec", 
+  "\xad", "'", "'", "\"", "\"", "*", "--", "---",
+  "\xd1", "\xed", "\xe7", "\xe8", "\xe9", "\xea", "\xeb","\xec", 
+  "\xd8", "\xd9", "\xda"
+};
+#endif
+
 //------------------------------------------------------------------------
 // 16-bit fonts
 //------------------------------------------------------------------------
@@ -302,6 +312,7 @@
   // append translated character(s) to string
   sub = NULL;
   n = 1;
+  if (!c) { return; }
   if ((charName = state->getFont()->getCharName(c))) {
     if ((c1 = generalSubstEncoding.getCharCode(charName)) >= 0) {
       charName = generalSubst[c1];
@@ -319,6 +330,11 @@
     case textOutLatin5:
       c1 = isoLatin5Encoding.getCharCode(charName);
       break;
+#ifdef THAI_SUPPORT
+    case textOutTIS620:
+      c1 = winThaiEncoding.getCharCode(charName);
+      break;
+#endif
     }
     if (c1 < 0) {
       m = strlen(charName);
@@ -395,6 +411,14 @@
 	  n = strlen(sub);
 	}
 	break;
+#ifdef THAI_SUPPORT
+      case textOutTIS620:
+	if (c1 >= 256) {
+	  sub = winThaiSubst[c1 - 256];
+	  n = strlen(sub);
+	}
+	break;
+#endif
     }
   } else {
     c1 = -1;
diff -Nuar xpdf-0.92/xpdf/TextOutputDev.h xpdf-0.92-thai/xpdf/TextOutputDev.h
--- xpdf-0.92/xpdf/TextOutputDev.h	Mon Dec  4 11:28:07 2000
+++ xpdf-0.92-thai/xpdf/TextOutputDev.h	Tue Sep  4 11:42:30 2001
@@ -28,6 +28,9 @@
   textOutLatin1,
   textOutLatin2,
   textOutLatin5
+#ifdef THAI_SUPPORT
+  , textOutTIS620
+#endif
 };
 
 //------------------------------------------------------------------------
diff -Nuar xpdf-0.92/xpdf/TextOutputFontInfo.h xpdf-0.92-thai/xpdf/TextOutputFontInfo.h
--- xpdf-0.92/xpdf/TextOutputFontInfo.h	Mon Dec  4 11:28:07 2000
+++ xpdf-0.92-thai/xpdf/TextOutputFontInfo.h	Tue Sep  4 11:44:19 2001
@@ -1077,4 +1077,162 @@
 static FontEncoding isoLatin5Encoding(isoLatin5EncodingNames,
                                       isoLatin5EncodingSize);
 
+#ifdef THAI_SUPPORT
+#define winThaiEncodingSize 291
+static char *winThaiEncodingNames[winThaiEncodingSize] = {
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  NULL,
+  "space",
+  "exclam",
+  "quotedbl",
+  "numbersign",
+  "dollar",
+  "percent",
+  "ampersand",
+  "quoteright",
+  "parenleft",
+  "parenright",
+  "asterisk",
+  "plus",
+  "comma",
+  "minus",
+  "period",
+  "slash",
+  "zero",
+  "one",
+  "two",
+  "three",
+  "four",
+  "five",
+  "six",
+  "seven",
+  "eight",
+  "nine",
+  "colon",
+  "semicolon",
+  "less",
+  "equal",
+  "greater",
+  "question",
+  "at",
+  "A",
+  "B",
+  "C",
+  "D",
+  "E",
+  "F",
+  "G",
+  "H",
+  "I",
+  "J",
+  "K",
+  "L",
+  "M",
+  "N",
+  "O",
+  "P",
+  "Q",
+  "R",
+  "S",
+  "T",
+  "U",
+  "V",
+  "W",
+  "X",
+  "Y",
+  "Z",
+  "bracketleft",
+  "backslash",
+  "bracketright",
+  "asciicircum",
+  "underscore",
+  "quoteleft",
+  "a",
+  "b",
+  "c",
+  "d",
+  "e",
+  "f",
+  "g",
+  "h",
+  "i",
+  "j",
+  "k",
+  "l",
+  "m",
+  "n",
+  "o",
+  "p",
+  "q",
+  "r",
+  "s",
+  "t",
+  "u",
+  "v",
+  "w",
+  "x",
+  "y",
+  "z",
+  "braceleft",
+  "bar",
+  "braceright",
+  "asciitilde",
+  NULL,
+       NULL,      NULL,      NULL,      NULL,      NULL,      NULL,      NULL,      NULL,
+       NULL,      NULL,      NULL,      NULL,      NULL,      NULL,      NULL,      NULL,
+       NULL,      NULL,      NULL,      NULL,      NULL,      NULL,      NULL,      NULL, 
+       NULL,      NULL,      NULL,      NULL,      NULL,      NULL,      NULL,      NULL,
+  "uni00a0", "uni0e01", "uni0e02", "uni0e03", "uni0e04", "uni0e05", "uni0e06", "uni0e07",
+  "uni0e08", "uni0e09", "uni0e0a", "uni0e0b", "uni0e0c", "uni0e0d", "uni0e0e", "uni0e0f",
+  "uni0e10", "uni0e11", "uni0e12", "uni0e13", "uni0e14", "uni0e15", "uni0e16", "uni0e17",
+  "uni0e18", "uni0e19", "uni0e1a", "uni0e1b", "uni0e1c", "uni0e1d", "uni0e1e", "uni0e1f",
+  "uni0e20", "uni0e21", "uni0e22", "uni0e23", "uni0e24", "uni0e25", "uni0e26", "uni0e27",
+  "uni0e28", "uni0e29", "uni0e2a", "uni0e2b", "uni0e2c", "uni0e2d", "uni0e2e", "uni0e2f",
+  "uni0e30", "uni0e31", "uni0e32", "uni0e33", "uni0e34", "uni0e35", "uni0e36", "uni0e37",
+  "uni0e38", "uni0e39", "uni0e3a",     NULL,     NULL,     NULL,     NULL, "uni0e3f",
+  "uni0e40", "uni0e41", "uni0e42", "uni0e43", "uni0e44", "uni0e45", "uni0e46", "uni0e47",
+  "uni0e48", "uni0e49", "uni0e4a", "uni0e4b", "uni0e4c", "uni0e4d", "uni0e4e", "uni0e4f",
+  "uni0e50", "uni0e51", "uni0e52", "uni0e53", "uni0e54", "uni0e55", "uni0e56", "uni0e57",
+  "uni0e58", "uni0e59", "uni0e5a", "uni0e5b",      NULL,      NULL,      NULL,   NULL,
+// glyph variations, to be subsititued
+  "unif700", "unif701", "unif702", "unif703", "unif704", "uni2026", "unif705", "unif706",
+  "unif707", "unif708", "unif709", "unif70a", "unif70b", "unif70c", "unif70d", "unif70e",
+  "unif70f", "uni2018", "uni2019", "uni201c", "uni201d", "uni2022", "uni2013", "uni2014",
+  "unif710", "unif711", "unif712", "unif713", "unif714", "unif715", "unif716", "unif717",
+  "unif718", "unif719", "unif71a"
+};
+static FontEncoding winThaiEncoding(winThaiEncodingNames,
+                                    winThaiEncodingSize);
+#endif // THAI_SUPPORT
+
 #endif
diff -Nuar xpdf-0.92/xpdf/pdftotext.cc xpdf-0.92-thai/xpdf/pdftotext.cc
--- xpdf-0.92/xpdf/pdftotext.cc	Mon Dec  4 11:28:07 2000
+++ xpdf-0.92-thai/xpdf/pdftotext.cc	Tue Sep  4 11:45:14 2001
@@ -34,6 +34,9 @@
 #if JAPANESE_SUPPORT
 static GBool useEUCJP = gFalse;
 #endif
+#ifdef THAI_SUPPORT
+static GBool useThai = gFalse;
+#endif
 static GBool rawOrder = gFalse;
 static char userPassword[33] = "";
 static GBool printVersion = gFalse;
@@ -54,6 +57,10 @@
   {"-eucjp",  argFlag,     &useEUCJP,      0,
    "convert Japanese text to EUC-JP"},
 #endif
+#ifdef THAI_SUPPORT
+  {"-thai",  argFlag,     &useThai,      0,
+   "convert Thai text to TIS-620"},
+#endif
   {"-raw",    argFlag,     &rawOrder,      0,
    "keep strings in content stream order"},
   {"-upw",    argString,   userPassword,   sizeof(userPassword),
@@ -152,6 +159,11 @@
   } else if (useLatin5) {
     charSet = textOutLatin5;
   }
+#ifdef THAI_SUPPORT
+  else if (useThai) {
+    charSet = textOutTIS620;
+  }
+#endif
   textOut = new TextOutputDev(textFileName->getCString(), charSet, rawOrder);
   if (textOut->isOk()) {
     doc->displayPages(textOut, firstPage, lastPage, 72, 0, gFalse);

