glynn at gclements.plus.com
Fri Dec 16 22:34:35 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].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.
> I wasn't sure if the lbearing of all chars is the same.
> If lbearing was
> the same for all chars, then why have it? If it wasn't the same, then
> text wouldn't align on the left margin.
Making text "aligned" doesn't mean having the leftmost non-blank
pixels all occur in the same pixel column. Some glyphs are meant to
have more space on one side or the other.
> Hmm, maybe the lbearing space is for the cursor?
No, the space around a glyph is so that it doesn't visually merge with
In most cases, you don't need to know the bounds of the non-blank
portion of the glyph. You just need the bounds of the glyph as a
whole, i.e. the values from the width field of each character and the
ascent and descent fields from the XFontStruct (not those in the
IOW, each glyph is just a rectangle; the program has no need to know
which pixels are filled and which are blank.
Glynn Clements <glynn at gclements.plus.com>
More information about the xorg