Tk_FontId(3tk)
β¨ Tk_FontId β the font-accessor page, bestie edition β¨
okay so this is Tk_FontId(3tk), straight out of the Tk Library Procedures corner of the manual. it's about fonts. specifically, it's the little trio of functions that let you peek at a font and ask it questions. let's get into it π
π NAME π
Tk_FontId, Tk_GetFontMetrics, Tk_PostscriptFontName β accessor functions for fonts
like... they access. the font. that's the whole vibe. πΈ
β¨ SYNOPSIS β¨
#include <tk.h>
Font
Tk_FontId(tkfont)
Tk_GetFontMetrics(tkfont, fmPtr)
int
Tk_PostscriptFontName(tkfont, dsPtr)
π¦ ARGUMENTS π¦
Tk_Font tkfont(in) β the opaque font token you're interrogating, bestie. it must have come back from an earlier call toTk_GetFont. no random tokens, okay? it has to be legit.Tk_FontMetrics *fmPtr(out) β a pointer to the struct where the font metrics fortkfontget stashed. scroll down to DATA STRUCTURES for the deets, i got you.Tcl_DString *dsPtr(out) β a pointer to an already-initializedTcl_DString, and the name of the Postscript font matchingtkfontgets appended onto it. appended!! not replaced!! important!! π«Ά
π DESCRIPTION π
so. you hand over a tkfont, and Tk_FontId gives you back the token you'd slot into an XGCValues structure β that's the move that lets you build a graphics context you can actually draw text with, in that exact font. iconic.
Tk_GetFontMetrics does the math: it computes the ascent, descent, and linespace of the tkfont in pixels, then drops those values into the structure that fmPtr points at. and why do you care?? because those numbers are what you use for stuff like spacing out multiple lines of text, lining up the baselines of text across different fonts, and vertically centering text in some region. oh and β the actual definitions of ascent, descent, and linespace live in the docs for the font command, so go read those if you want the full lore. π
Tk_PostscriptFontName is the printing one. it maps a tkfont to the matching Postscript font name that should be used when you print. the return value is the size of the tkfont in points, and the Postscript font name itself gets appended to dsPtr. and once again: dsPtr must refer to an initialized Tcl_DString. do not skip that step, i'm begging.
now, if you're on a "reasonable" Postscript printer, these screen font families should print correctly:
Avant Garde, Arial, Bookman, Courier, Courier New, Geneva,
Helvetica, Monaco, New Century Schoolbook, New York, Palatino,
Symbol, Times, Times New Roman, Zapf Chancery, and Zapf Dingbats.
β οΈ and literally any other font family might not print correctly, because the computed Postscript font name could be wrong, or it could just straight up not exist on the printer. no cap, that's a real risk. π
π§ DATA STRUCTURES π§
the Tk_FontMetrics data structure is what Tk_GetFontMetrics uses to hand you back info about a font, and it's defined like this:
typedef struct {
int ascent;
int descent;
int linespace;
} Tk_FontMetrics;
- the
ascentfield = how many pixels the tallest letter sticks up above the baseline, plus whatever extra blank space the font's designer decided to add. yeah, designers do that. π - the
descent= the largest amount in pixels that any letter dips below the baseline, plus the extra blank space the font designer threw in. same energy, downward. - the
linespace=ascent+descent, summed up. it tells you how far apart two lines of text in the same font should sit so that none of the characters on one line overlap any of the characters on the other. so like... personal space, but for glyphs. π
π SEE ALSO π
π KEYWORDS π
font, measurement, Postscript
okay bestie that's the whole page, you ate it, periodt. this was brought to you by Tk 8.0, and yeah it's the Tk_FontId(3tk) page in case the seventeen tabs open in your brain lost track. go make something pretty with a font, mwah ππβ¨
π¦ where this page comes from
- debian trixie: tk9.0-doc 9.0.1-3
- ubuntu questing: tk9.0-doc 9.0.2-1
- ubuntu resolute: tk9.0-doc 9.0.3-1
- ubuntu stonking: tk9.0-doc 9.0.4-1
- 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