Serious bug in gdk_draw_text() ?



When an XFree86 3.3.6 server is used with certain fonts from XFree86
4.1, the version clash causes many GTK programs to display squares
instead of letters and digits.  Many applications are affected,
including Gnumeric 0.69, Pan 0.10, XChat 1.8.2, etc.

The root cause lies either in the old X server or in the new fonts.

However, I'm wondering why the following code in Gdk has remained
basically untouched since at least version 0.99.  The code appears in
gdk_draw_text() in gtk 1.2, and in gdk_x11_draw_text() in the latest
CVS tree:

  XFontStruct *xfont = (XFontStruct *) font_private->xfont;
  XSetFont(drawable_private->xdisplay, gc_private->xgc, xfont->fid);
  if ((xfont->min_byte1 == 0) && (xfont->max_byte1 == 0))
  {
    XDrawString (drawable_private->xdisplay, drawable_private->xwindow,
		 gc_private->xgc, x, y, text, text_length);
  }
  else
  {
    XDrawString16 (drawable_private->xdisplay, drawable_private->xwindow,
		   gc_private->xgc, x, y, (XChar2b *) text, text_length / 2);
  }

As you can see, the problem is that, roughly speaking, if the font has
more than 256 glyphs, the function silently assumes that you're
passing it a string of 16-bit characters, and calls XDrawString16()
instead of XDrawString().

Since gdk_draw_text_wc() has been officially doing the Unicode thing
for a long while, I'm wondering why gdk_draw_text() needs do to it
too.

One of the fonts which cause gdk_draw_text() to misbehave is:

  -adobe-helvetica-medium-r-normal-*-12-*-*-*-*-*-*-*

which corresponds to file

  /usr/X11R6/lib/X11/fonts/75dpi/helvR12-ISO8859-1.pcf.gz

in XFree86 4.x.  I want to emphasize again that squares get displayed
only when you use an old Xserver (3.3.6) with the new fonts (4.x).

Many people would just shrug and say it's a user problem, but I think
the odd behavior of gdk_draw_text() is a little too fragile (not to
mention undocumented).  When I changed the code to

  XFontStruct *xfont = (XFontStruct *) font_private->xfont;
  XSetFont(drawable_private->xdisplay, gc_private->xgc, xfont->fid);
  XDrawString (drawable_private->xdisplay, drawable_private->xwindow,
               gc_private->xgc, x, y, text, text_length);

suddenly Gnumeric, XChat, Pan, etc. all started working again, despite
the 3.3.6/4.x version clash.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]