[comp.windows.x] naive query

bagchi@eecs.umich.edu (Ranjan Bagchi) (03/03/91)

	(Since I'm much too sleepy to find and wade through
the source...)
 
	Does anyone know exactly the algorithm which the XDrawString
functions use to draw one character after another?  Specifically, how
the horiz. position of each subsequent character is determined.
	I've written a small chunk of code which draws text in
either a line-by-line or character-by-character fashion...the problem
is that character-by-character just doesn't get the kerning right, and
the text drawn this way is always slightly off from when the text
would be drawn in one shot as a line.  I've been screwing around
with the info held in each XCharStruct, but I haven't been getting it
right yet.
 
	-zzzzzzzzz
--
--------------------------------------------------------------------------------
Ranjan Bagchi - the incredible sleeping hacker......  
bagchi@[eecs                            |  
        caen].math.lsa.umich.edu        | Pleasure has become a weapon now! 
                                        |  
--------------------------------------------------------------------------------

mouse@lightning.mcrcim.mcgill.EDU (der Mouse) (03/04/91)

> (Since I'm much too sleepy to find and wade through the source...)

> Does anyone know exactly the algorithm which the XDrawString
> functions use to draw one character after another?  Specifically, how
> the horiz. position of each subsequent character is determined.

Do you want to know how they *actually* do it or how they're *supposed*
to do it? :-)

In the Xlib document, in the discussion of the font structures, such as
XCharStruct, I find

	For a character origin at [x,y], the bounding box of a
	character (that is, the smallest rectangle that encloses the
	character's shape) described in terms of XCharStruct components
	is [...].

	The origin for the next character is defined to be:
	        [x + width, y]

In other words, you simply step along the X axis by adding the width
field of each character's XCharStruct after drawing that character's
glyph.

As for how they *actually* do it....  XTextWidth and XTextExtents
really do do things this way, at least in the MIT source.  A quick scan
of the mfb code gives me the impression that it does as well, though to
be sure would require a much more careful scan.  (And note that not all
servers use mfb, of course.)

> I've written a small chunk of code which draws text in either a
> line-by-line or character-by-character fashion...the problem is that
> character-by-character just doesn't get the kerning right, and the
> text drawn this way is always slightly off from when the text would
> be drawn in one shot as a line.

If the above doesn't help, I'd have to see the code.

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu