#include <tk.h> int Tk_MeasureChars(tkfont, string, numBytes, maxPixels, flags, lengthPtr) int Tk_TextWidth(tkfont, string, numBytes) Tk_DrawChars(display, drawable, gc, tkfont, string, numBytes, x, y) Tk_UnderlineChars(display, drawable, gc, tkfont, string, x, y, firstByte, lastByte)
These routines are for measuring and displaying simple single-font, single-line strings. To measure and display single-font, multi-line, justified text, refer to the documentation for Tk_ComputeTextLayout. There is no programming interface in the core of Tk that supports multi-font, multi-line text; support for that behavior must be built on top of simpler layers. Note that the interfaces described here are byte-oriented not character-oriented, so index values coming from Tcl scripts need to be converted to byte offsets using the Tcl_UtfAtIndex and related routines.
A glyph is the displayable picture of a letter, number, or some other symbol. Not all character codes in a given font have a glyph. Characters such as tabs, newlines/returns, and control characters that have no glyph are measured and displayed by these procedures in a platform-dependent manner; under X, they are replaced with backslashed escape sequences, while under Windows and Macintosh hollow or solid boxes may be substituted. Refer to the documentation for Tk_ComputeTextLayout for a programming interface that supports the platform-independent expansion of tab characters into columns and newlines/returns into multi-line text.
Tk_MeasureChars is used both to compute the length of a given string and to compute how many characters from a string fit in a given amount of space. The return value is the number of bytes from string that fit in the space specified by maxPixels subject to the conditions described by flags. If all characters fit, the return value will be numBytes. *lengthPtr is filled with the computed width, in pixels, of the portion of the string that was measured. For example, if the return value is 5, then *lengthPtr is filled with the distance between the left edge of string[0] and the right edge of string[4].
Tk_TextWidth is a wrapper function that provides a simpler interface to the Tk_MeasureChars function. The return value is how much space in pixels the given string needs.
Tk_DrawChars draws the string at the given location in the given drawable.
Tk_UnderlineChars underlines the given range of characters in the given string. It does not draw the characters (which are assumed to have been displayed previously by Tk_DrawChars); it just draws the underline. This procedure is used to underline a few characters without having to construct an underlined font. To produce natively underlined text, the appropriate underlined font should be constructed and used.