XDrawString

Glynn Clements glynn at gclements.plus.com
Fri Dec 16 03:50:08 PST 2005


Russell Shaw wrote:

> To draw strings aligned with a left margin, should i use x=0:
> 
>    char *string;
>    ...
>    XDrawString(display, window, gc, 0, y, string, strlen(string));
> 
> or am i supposed to use lbearing? :
> 
>    XFontStruct *font;
>    ...
> 
>    int x = font->per_char[(int)str[0]].lbearing;
> 
>    XDrawString(display, window, gc, -x, y, string, strlen(string));

For most practical purposes, you should be using x=0. That will result
in lbearing blank pixel columns before the first drawn pixel. I can't
think of a practical situation where you might want to use -lbearing.

Apart from anything else, using x=0 is necessary for lines of text
using a monospaced font to align.

-- 
Glynn Clements <glynn at gclements.plus.com>



More information about the xorg mailing list