--- grx246p1/src/fonts/fdv_xwin.c	2003-02-25 20:23:40.000000000 +0200
+++ grx246/src/fonts/fdv_xwin.c	2003-02-25 22:42:44.000000000 +0200
@@ -16,6 +16,9 @@
  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  **
+ ** Contributions by Dimitar Zhekov (jimmy@is-vn.bg) 25/02/2003
+ **   - use the default underline height instead of font descent
+ **   - use a separate X display and window (how costly is that?)
  **/
 
 #include <stdio.h>
@@ -27,6 +30,8 @@
 #include "allocate.h"
 #include "arith.h"
 
+static Display *        fontdsp = NULL;
+static Window           fontwin = None;
 static XFontStruct *    fontp = NULL;
 static Pixmap           fontbmp = None;
 static GC               fontgc = None;
@@ -50,11 +55,15 @@
 
 static void cleanup(void)
 {
-  if (_XGrDisplay != NULL) {
-    if (fontp != NULL) XFreeFont (_XGrDisplay, fontp);
-    if (fontbmp != None) XFreePixmap (_XGrDisplay, fontbmp);
-    if (fontgc != None) XFreeGC (_XGrDisplay, fontgc);
+  if (fontdsp != NULL) {
+    if (fontp != NULL) XFreeFont (fontdsp, fontp);
+    if (fontbmp != None) XFreePixmap (fontdsp, fontbmp);
+    if (fontgc != None) XFreeGC (fontdsp, fontgc);
+    if (fontwin != None) XDestroyWindow (fontdsp, fontwin);
+    XCloseDisplay (fontdsp);
   }
+  fontdsp = NULL;
+  fontwin = None;
   fontp = NULL;
   fontbmp = None;
   fontgc = None;
@@ -62,34 +71,46 @@
 
 static int openfile(char *fname)
 {
+  int res;
+  Window root;
   int i, numchars;
 
+  res = FALSE;
   init_swap_byte();
   cleanup();
-  if (_XGrDisplay != NULL) fontp = XLoadQueryFont (_XGrDisplay, fname);
-  if (fontp == NULL)    return(cleanup(), FALSE);
+  fontdsp = XOpenDisplay ("");
+  if (fontdsp == NULL)  goto done;
+  root = DefaultRootWindow (fontdsp);
+  fontwin = XCreateSimpleWindow (fontdsp, root, 0, 0, 1, 1, 0, 0, 0);
+  if (fontwin == None)  goto done;
+
+  fontp = XLoadQueryFont (fontdsp, fname);
+  if (fontp == NULL)    goto done;
 
   numchars = fontp->max_char_or_byte2 - fontp->min_char_or_byte2 + 1;
-  fontbmp = XCreatePixmap (_XGrDisplay, _XGrWindow,
+  fontbmp = XCreatePixmap (fontdsp, fontwin,
 			   numchars * fontp->max_bounds.width,
 			   fontp->ascent + fontp->descent, 1);
-  if (fontbmp == None)  return(cleanup(), FALSE);
-  fontgc = XCreateGC (_XGrDisplay, fontbmp, 0L, NULL);
-  if (fontgc == None)   return(cleanup(), FALSE);
-  XSetFont (_XGrDisplay, fontgc, fontp->fid);
-  XSetForeground (_XGrDisplay, fontgc, 0);
-  XFillRectangle (_XGrDisplay, fontbmp, fontgc, 0, 0,
+  if (fontbmp == None)  goto done;
+  fontgc = XCreateGC (fontdsp, fontbmp, 0L, NULL);
+  if (fontgc == None)   goto done;
+  XSetFont (fontdsp, fontgc, fontp->fid);
+  XSetForeground (fontdsp, fontgc, 0);
+  XFillRectangle (fontdsp, fontbmp, fontgc, 0, 0,
 		  numchars * fontp->max_bounds.width,
 		  fontp->ascent + fontp->descent);
-  XSetForeground (_XGrDisplay, fontgc, 1);
-  XSetBackground (_XGrDisplay, fontgc, 0);
+  XSetForeground (fontdsp, fontgc, 1);
+  XSetBackground (fontdsp, fontgc, 0);
   for (i = 0; i < numchars; i++) {
     char c = fontp->min_char_or_byte2 + i;
-    XDrawString (_XGrDisplay, fontbmp, fontgc,
+    XDrawString (fontdsp, fontbmp, fontgc,
 		 i * fontp->max_bounds.width,
 		 fontp->ascent, &c, 1);
   }
-  return(TRUE);
+  res = TRUE;
+done:
+  if (!res) cleanup();
+  return(res);
 }
 
 static int header(GrFontHeader *hdr)
@@ -133,8 +154,8 @@
   if (fontp == NULL || fontbmp == None) return(FALSE);
   if ((w <= 0) || (w != charwdt(chr)))  return(FALSE);
   if ((h <= 0) || (h != (fontp->ascent + fontp->descent)))      return(FALSE);
-  if (_XGrDisplay == NULL)      return(FALSE);
-  img = XGetImage (_XGrDisplay,
+  if (fontdsp == NULL)  return(FALSE);
+  img = XGetImage (fontdsp,
 		   fontbmp,
 		   (chr - fontp->min_char_or_byte2) * fontp->max_bounds.width,
 		   0,
@@ -142,7 +163,7 @@
 		   h,
 		   AllPlanes,
 		   ZPixmap);
-  if (img == NULL)              return(FALSE);
+  if (img == NULL)      return(FALSE);
   data = (unsigned char *)(img->data);
   bpl = (w + 7) >> 3;
   for (y = 0; y < h; y++) {
