[comp.windows.x] XTextWidth broken.

net@TUB.BITNET (Oliver Laumann) (01/10/89)

XTextWidth() and probably other related functions are broken;
it is not possible to compute the width of a string containing
characters with codes greater than 127.  Therefore the upper
halves of the ISO Latin-1 fonts currently cannot be used.

The bugs are located in the (internal) functions GetCS and GetCS2d;
`char' is used in several places where `int' should have been used
instead.

The line
            row = (chars[ind] >> 8)-firstRow;

in GetCS2d() is particularly interesting; note that `chars' is a
character array!

One of the bugs can be reproduced with the following demonstration program.
It prints "15 0"; this is certainly not right.


#include <X11/Xlib.h>

main () $
    Display *d;
    XFontStruct *f;

    if ((d = XOpenDisplay ((char *)0)) == 0)
        return 1;
    if ((f = XLoadQueryFont (d, "*courier-bold-r-normal--24*")) == 0)
        return 1;
    printf ("%d %d\n", f->per_char[0273].width, XTextWidth (f, "\273", 1));
    return 0;



Regards,
--
Oliver Laumann              net@TUB.BITNET              net@tub.UUCP