From: fabian@xenox.w.open.de (Fabian Hoppe 02332/83518)
Newsgroups: fj.mail-lists.x-window
Subject: Problems with XDrawImageString
Date: 4 Nov 92 23:47:45 GMT
Distribution: fj
Organization: SubNet - The Next Generation

Date: 4 Nov 92 11:29:36 GMT
Message-Id: <1992Nov4.112936.10970@xenox.w.open.de>
Newsgroups: comp.windows.x


Hi!

I have a strange problem with X11R5-XFree86 on a noname-386 under ISC 2.2.
The XDrawImageString shows a funny behaviour: The fillrectangle-command
that erases the area where the String is to be printed doesn't works 
correctly: Depending on the position of the window, the left border of 
the erased area is calculated wrongly. When a number of chars are printed
with only one XDrawImageString command, everything works fine. When you
seperate the command in several XDrawImageString-calls (for each char one)
one can regard that the fillrectangle which is performed by XDrImSt erases
not only the area for the char to be printed, but also a bit of the left
char (up to three rows..). But this depends on the absolute position of the
window in which the commands are performed!!!!

An easy example:

	char *s="6x13";	
	font_struct=XLoadQueryFont(display,s);	
	XSetFont(display,gc,font_struct->fid); /* gc with gcCopy and white */
					       /* text on black background */	

	XMapWindow(display,win);

	char *t='o';
	int  width=fontstruct->min_bounds.width;
	
	for (i=0;i<30;i++) {
		XMoveWindow(display,win,100+i,100);
		XClearWindow(display,win);
		XDrawImageString(display,win,gc,10,13,t,1);
		XDrawImageString(display,win,gc,10+width,13,t,1); 
	
		/* wait a bit .. */
	}

I will paste a complet program to the end of the article..

It's funny to regard: First everything works fine, then after the first move,
one row of the first "o" is erased, then two rows, the three and then after
four moves everthing is OK and so on..
The problem is, that this command is one of the mostly used (e.g in xterm for
displaying the cursor) and it's nearly unpossible to work with X11, because
the characters are always cutted. (Or I've to position the window absolute 
on an address where the fillrectangle-command works fine.. ;-) ) 


Help me, I'm not so good in Xserver-debugging ;-) !!

Fabian 
fabian\@xenox.w.open.de


X11R5 - patchlevel 17
XFree86 1.1 - patches up to 01.10.92
compiled with cc
ISC 2.2
SVGA Targa-Win+

----- cut here ---
/****************************************************************/
/* test.c 							*/
/****************************************************************/
#include <malloc.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

#define   NULL	0

Display	       *display;
int		screen;
Window		win;
XEvent		event;
unsigned long	mask, valuemask;
GC		gc;
XGCValues	values;
XSetWindowAttributes	attr;
XFontStruct    *font_struct;

void main()
{
	int		x,y,i;
	char	       *s="6x13";
	char	       *t="o";
	char	       *hostdisplay="vivian:0.0";

	display = XOpenDisplay(hostdisplay);
	if (display == (Display *) NULL) {
		printf("Cannot open Display %s\n",hostdisplay);
		exit(1);
	}
	screen = DefaultScreen(display);
	valuemask = CWBackPixel;
	attr.background_pixel = WhitePixel(display,screen);	
	win = XCreateWindow(display,RootWindow(display,screen),
			0,0,100 /* width */,30 /* height */, 1 /* b_width */,
			CopyFromParent,CopyFromParent,CopyFromParent,
			valuemask,&attr);	
	mask = GCForeground|GCBackground|GCFunction;
	values.background = BlackPixel(display,screen);
	values.foreground = WhitePixel(display,screen);
	values.function = GXcopy;	
	
	gc = XCreateGC(display,win,mask,&values);
	font_struct = XLoadQueryFont(display,s);
	XSetFont(display,gc,font_struct->fid);
	XSelectInput(display,win,KeyPressMask|ExposureMask|ButtonPressMask);
	XMapWindow(display,win);
		
	i = 0;

	while (1)
	{
		XNextEvent(display,&event);
		switch (event.type) {
		case KeyPress :
			XCloseDisplay(display);
			exit();
		case Expose :
			XDrawImageString(display,
					 win,
					 gc,
					 10,
					 13,
					 t,
					 1);
			XDrawImageString(display,
					 win,
					 gc,
					 10+font_struct->min_bounds.width,
					 13,
					 t,
					 1);
			break;
		case ButtonPress:
			XMoveWindow(display,win,100+i,100);
			i++;
			XClearWindow(display,win);
			XDrawImageString(display,
					 win,
					 gc,
					 10,
					 13,
					 t,
					 1);
			XDrawImageString(display,
					 win,
					 gc,
					 10+font_struct->min_bounds.width,
					 13,
					 t,
					 1);
			break;
			break;
		default:
			break;
		}
	}
}