Tk_FontId(3tk)

πŸ“¦
version 9.0.4 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ 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 to Tk_GetFont. no random tokens, okay? it has to be legit.
  • Tk_FontMetrics *fmPtr (out) β€” a pointer to the struct where the font metrics for tkfont get stashed. scroll down to DATA STRUCTURES for the deets, i got you.
  • Tcl_DString *dsPtr (out) β€” a pointer to an already-initialized Tcl_DString, and the name of the Postscript font matching tkfont gets 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 ascent field = 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