Tk_MeasureChars(3)
π NAME π
Tk_MeasureChars, Tk_TextWidth, Tk_DrawChars, Tk_UnderlineChars β the little squad of routines that measure and display your simple single-line strings. No cap.
β¨ SYNOPSIS β¨
#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)
π ARGUMENTS π
okay bestie, here's the whole cast, one by one, no skips π
Tk_Font tkfont(in) β the token for the font your text is gonna be drawn or measured in. It literally must be one that a previous call toTk_GetFonthanded you back, don't just make one up.const char *string(in) β the text to measure or display. It does not need to be null terminated, so breathe. Any non-printing meta-characters hanging out in there (tabs, newlines, and other control characters) get measured or displayed in a platform-dependent way. it's giving "your mileage may vary."int numBytes(in) β the max number of bytes to even look at when measuring or drawingstring. Must be>= 0. periodt.int maxPixels(in) β ifmaxPixelsis>= 0, it says how long the line is allowed to get, in pixels. Characters fromstringget processed only until that many pixels have been covered. IfmaxPixelsis< 0, then the line length is unbounded and theflagsargument gets ignored entirely. she said "no limits, no rules" πint flags(in) β various flag bits OR-ed together, like a lil friendship bracelet:TK_PARTIAL_OKβ include a character as long as any part of it fits in the length given bymaxPixels. Otherwise, a character has to fit <b>completely</b> to even be considered.TK_WHOLE_WORDSβ stop on a word boundary, if possible.TK_AT_LEAST_ONEβ if it's set, it means return at least one character, even if no characters could fit in the length given bymaxPixels. IfTK_AT_LEAST_ONEis set <b>and</b>TK_WHOLE_WORDSis also set, it means that if not even one word fits on the line, return the first few letters of the word that <i>did</i> fit; and if not even one letter of the word fit, then the first letter will still be returned. she's persistent like that π«Ά
int *lengthPtr(out) β gets filled with the number of pixels occupied by the number of characters returned as the result ofTk_MeasureChars.Display *display(in) β the display to draw on.Drawable drawable(in) β the window or pixmap to draw in.GC gc(in) β the graphics context for drawing characters. Heads up: the font selected into this GC <b>must</b> be the same as thetkfont. same font, same vibe, or it's a problem.int x, y(in) β the coordinates where you place the left edge of the baseline when displayingstring.int firstByte(in) β the index of the first byte of the first character to underline instring. Underlining begins at the left edge of this character.int lastByte(in) β the index of the first byte of the last character up to which the underline will be drawn. The character specified bylastBytewill not itself be underlined. sneaky, ik.
πΈ DESCRIPTION πΈ
These routines are for measuring and displaying <b>simple single-font, single-line strings</b>. If you need single-font, <i>multi-line</i>, justified text, go read the docs for Tk_ComputeTextLayout instead, bestie. And ngl, there is <b>no</b> programming interface in the core of Tk that supports multi-font, multi-line text β if you want that behavior you gotta build it on top of simpler layers yourself. DIY queen behavior π
Also important: 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 Tcl_UtfAtIndex and related routines. do not skip that step, I'm begging π
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 β that's just how it is. Characters like tabs, newlines/returns, and control characters that have no glyph get measured and displayed by these procedures in a platform-dependent manner; under X they're replaced with backslashed escape sequences, while under Windows and Macintosh hollow or solid boxes may be substituted. iconic in a chaotic way π If you want a programming interface that supports platform-<i>independent</i> expansion of tab characters into columns and newlines/returns into multi-line text, refer to the documentation for Tk_ComputeTextLayout.
Tk_MeasureCharsis used both to compute the length of a given string <b>and</b> to compute how many characters from a string fit in a given amount of space. The return value is the number of bytes fromstringthat fit in the space specified bymaxPixels, subject to the conditions described byflags. If all the characters fit, the return value will benumBytes.*lengthPtrgets filled with the computed width, in pixels, of the portion of the string that was measured. For example, if the return value is5, then*lengthPtris filled with the distance between the left edge ofstring[0]and the right edge ofstring[4]. math but make it cute π§Tk_TextWidthis a wrapper function that provides a simpler interface to theTk_MeasureCharsfunction. The return value is how much space in pixels the given string needs. lowkey the easy mode of the group.Tk_DrawCharsdraws the string at the given location in the givendrawable. that's it, that's the job β¨Tk_UnderlineCharsunderlines the given range of characters in the given string. It does <b>not</b> draw the characters themselves (those are assumed to have already been displayed previously byTk_DrawChars) β it just draws the underline. This procedure is used to underline a few characters without having to construct an underlined font. If you want natively underlined text, the appropriate underlined font should be constructed and used instead. don't come for her, she's a specialist π
π SEE ALSO π
β KEYWORDS β
font, measurement
okay that's the whole page, you ate that π this little legend lives in the Tk Library Procedures corner of the manual, and she's been sitting pretty since Tk 8.1 β yeah bestie, Tk_MeasureChars(3), 8.1, the whole era. go forth and measure responsibly ππ
π¦ where this page comes from
- alpine 3.22: tk-doc 8.6.16-r0 Β· TCL
- alpine 3.23: tk-doc 8.6.17-r0 Β· TCL
- alpine 3.24: tk-doc 8.6.17-r1 Β· TCL
- arch rolling: tk 8.6.16-1 Β· TCL
- centos-stream 10: tk-devel 1:8.6.13-5.el10 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- centos-stream 9: tk-devel 1:8.6.10-9.el9 Β· TCL
- centos-stream 9: tk-devel 1:8.6.10-9.el9 Β· TCL
- fedora 43: tk8-devel 1:8.6.16-2.fc43 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 43: tk8-devel 1:8.6.16-2.fc43 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 44: tk8-devel 1:8.6.17-2.fc44 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 44: tk8-devel 1:8.6.17-2.fc44 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- opensuse-leap 16.0: tk-devel 8.6.13-160000.2.2 Β· TCL
- opensuse-leap 16.0: tk-devel 8.6.13-160000.2.2 Β· TCL
- opensuse-leap 16.0: tk-devel 8.6.13-160000.2.2 Β· TCL
- opensuse-leap 16.0: tk-devel 8.6.13-160000.2.2 Β· TCL
- Copyright (c) 1996 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms