--- xpdf.cc~	Fri Oct 26 19:52:42 2001
+++ xpdf.cc	Sun Oct 28 14:29:40 2001
@@ -37,6 +37,19 @@
 #include "Error.h"
 #include "config.h"
 
+#ifdef __EMX__
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/stat.h>
+#define INCL_DOSMISC
+#include <os2.h>
+
+static char *OS2PSFontsPath(const char *str);
+static char *XGSPSFontsPath(const char *str);
+static const char *PSFontsPath(const char *str);
+static char QueryBootDrive(void);
+#endif /* if __EMX__ */
+
 #ifdef XlibSpecificationRelease
 #if XlibSpecificationRelease < 5
 typedef char *XPointer;
@@ -585,6 +598,38 @@
 #if CHINESE_CNS_SUPPORT
   cns13Font = app->getStringResource("chineseCNSFont", NULL);
 #endif
+#ifdef __EMX__
+  if (!t1Courier)
+    t1Courier = new GString(PSFontsPath("t1Courier"));
+  if (!t1CourierBold)
+    t1CourierBold = new GString(PSFontsPath("t1CourierBold"));
+  if (!t1CourierBoldOblique)
+    t1CourierBoldOblique = new GString(PSFontsPath("t1CourierBoldOblique"));
+  if (!t1CourierOblique)
+    t1CourierOblique = new GString(PSFontsPath("t1CourierOblique"));
+  if (!t1Helvetica)
+    t1Helvetica = new GString(PSFontsPath("t1Helvetica"));
+  if (!t1HelveticaBold)
+    t1HelveticaBold = new GString(PSFontsPath("t1HelveticaBold"));
+  if (!t1HelveticaBoldOblique)
+    t1HelveticaBoldOblique =  new GString(PSFontsPath("t1HelveticaBoldOblique"));
+  if (!t1HelveticaOblique)
+    t1HelveticaOblique = new GString(PSFontsPath("t1HelveticaOblique"));
+  if (!t1Symbol)
+    t1Symbol = new GString(PSFontsPath("t1Symbol"));
+  if (!t1TimesBold)
+    t1TimesBold = new GString(PSFontsPath("t1TimesBold"));
+  if (!t1TimesBoldItalic)
+    t1TimesBoldItalic = new GString(PSFontsPath("t1TimesBoldItalic"));
+  if (!t1TimesItalic)
+    t1TimesItalic = new GString(PSFontsPath("t1TimesItalic"));
+  if (!t1TimesRoman)
+    t1TimesRoman = new GString(PSFontsPath("t1TimesRoman"));
+  if (!t1ZapfDingbats)
+    t1ZapfDingbats = new GString( PSFontsPath("t1ZapfDingbats"));
+/* japanase, chinese fonts ? */
+#endif /* __EMX__ */
+
   if (fullScreen) {
     zoom = zoomPage;
   } else {
@@ -2397,3 +2442,141 @@
     findWin = NULL;
   }
 }
+
+
+#ifdef __EMX__
+/* On OS/2 we don't have fixed paths for neither the systems or 
+   the X11 installation. But we're able to detect them during
+   runtime. So these subroutines try to find installed system 
+   PS fonts or those supplied with xpdf without having the
+   user to adjust any settings! */
+   
+static char QueryBootDrive(void) {
+
+  ULONG   StartIndex, LastIndex;
+  ULONG   Buf[64];
+  APIRET  rc;
+  char btdrv;
+ 
+  StartIndex = QSV_BOOT_DRIVE;
+  LastIndex  = StartIndex;
+  rc = DosQuerySysInfo (StartIndex,  LastIndex, Buf, sizeof(Buf));
+  if (rc) 
+    return 'C';
+  else {
+    btdrv = 'A' + Buf[0] - 1;
+    return btdrv;
+  }
+}
+
+/* An almost complete mapping to OS/2 native PSFonts */
+const static char OS2PSFonts[][2][256] = {
+  {"t1Courier", "COUR.PFB"},
+  {"t1CourierBold", "COURB.PFB"},
+  {"t1CourierBoldOblique", "COURBI.PFB"},
+  {"t1CourierOblique", "COURI.PFB"},
+  {"t1Helvetica", "HELV.PFB"},
+  {"t1HelveticaBold", "HELVB.PFB"},
+  {"t1HelveticaBoldOblique", "HELVBI.PFB"},
+  {"t1HelveticaOblique", "HELVI.PFB"},
+  {"t1Symbol", "SYMB.PFB"},
+  {"t1TimesBold", "TNRB.PFB"},
+  {"t1TimesBoldItalic", "TNRBI.PFB"},
+  {"t1TimesItalic", "TNRI.PFB"},
+  {"t1TimesRoman", "TNR.PFB"},
+  {"t1ZapfDingbats", ""},
+  {"", ""} 
+  };
+
+/* A complete mapping to ghostscript PSFonts */  
+const static char GhostPSFonts[][2][256] = {
+  {"t1Courier", "n022003l.pfb"},
+  {"t1CourierBold", "n022004l.pfb"},
+  {"t1CourierBoldOblique", "n022024l.pfb"},
+  {"t1CourierOblique", "n022023l.pfb"},
+  {"t1Helvetica", "n019003l.pfb"},
+  {"t1HelveticaBold", "n019004l.pfb"},
+  {"t1HelveticaBoldOblique", "n019024l.pfb"},
+  {"t1HelveticaOblique", "n019023l.pfb"},
+  {"t1Symbol", "s050000l.pfb"},
+  {"t1TimesBold", "n021004l.pfb"},
+  {"t1TimesBoldItalic", "n021024l.pfb"},
+  {"t1TimesItalic", "n021023l.pfb"},
+  {"t1TimesRoman", "n021003l.pfb"},
+  {"t1ZapfDingbats", "d050000l.pfb"},
+  {"", ""} 
+  };
+ 
+
+static char *OS2PSFontsPath(const char *str) {
+
+  char *path;
+  int i;
+  int mapindex = -1;
+  struct stat buf;
+  
+  for (i=0; (strcmp("", OS2PSFonts[i][0]) && strcmp("", OS2PSFonts[i][1]) ); i++) {
+    if (!strcmp(str, OS2PSFonts[i][0])) {
+      mapindex = i;
+    }
+  }
+  if (mapindex < 0)
+    return NULL;
+  path = (char *)malloc(MAXPATHLEN);
+  path[0] = QueryBootDrive();
+  path[1] = '\0';
+  strcat(path, ":/PSFONTS/");
+  strcat(path, OS2PSFonts[mapindex][1]);
+//  fprintf(stderr, "os2ps stating for *%s*\n", path);
+  if (stat(path, &buf)==0)
+    return path;
+  else {
+    free(path);
+    return NULL;
+  }
+}
+
+
+static char *XGSPSFontsPath(const char *str) {
+
+  char *path, *xpath;
+  int i;
+  int mapindex = -1;
+  struct stat buf;
+  
+  for (i=0; (strcmp("",GhostPSFonts[i][0]) && strcmp("", GhostPSFonts[i][0]) ); i++) {
+    if (!strcmp(str, GhostPSFonts[i][0])) {
+      mapindex = i;
+    }
+  }
+  if (mapindex < 0)
+    return NULL;
+  xpath = getenv("X11ROOT");
+  if (!xpath) 
+    return NULL;
+  path = (char *)malloc(MAXPATHLEN);
+  strcpy(path, xpath);
+  strcat(path, "/XFree86/lib/X11/fonts/ghost/");
+  strcat(path, GhostPSFonts[mapindex][1]);
+//  fprintf(stderr, "xgps stating for *%s*\n", path);
+  if (stat(path, &buf)==0)
+    return path;
+  else {
+    free(path);
+    return NULL;
+  }
+}
+
+
+static const char *PSFontsPath(const char *str) {
+  char *fontfile;
+
+ if ( (fontfile  = OS2PSFontsPath(str)) ) {
+   return fontfile;
+ } else if ( (fontfile = XGSPSFontsPath(str)) ) {
+   return fontfile;
+ } else {
+   return NULL;
+ }
+}
+#endif /* __EMX__ */
