beetlebug▾
/

font

Makes named fonts, changes them, and measures text in a font.

font SUBCOMMAND ?ARG ...?

Description

A font is a font description or the name of a named font. A description is a list: a family, a size, and style words, such as {Helvetica 12 bold}. It can also be a list of options and values, such as {-family Times -size 10}. The style words are normal, bold, roman, italic, underline, and overstrike.

A size above 0 is in points, and a size below 0 is in pixels. [tk scaling](cmd:tk scaling) gives the count of pixels in one point.

A named font has a name and the six attributes -family, -size, -weight, -slant, -underline, and -overstrike. A widget with a named font in its -font option draws again when the font changes. The standard fonts, such as TkDefaultFont and TkFixedFont, are named fonts. Each one gives the font of the theme until a script sets one of its attributes.

ztk draws text with the faces in its package: Inter Regular and Bold, and JetBrains Mono Regular. A monospace family, such as Courier, gets JetBrains Mono, and each other family gets Inter. On Linux, the ztk program also finds the installed fonts, and a family of an installed font gets its nearest face. On Windows, DirectWrite draws the fonts of the system. The headless backend uses only the faces of the package. [font load](cmd:font load) adds the faces of a font file of the app, and their family comes before each other face of that name.

Subcommands

SubcommandDescription
font createMakes a named font.
font configureGives or sets the attributes of a named font.
font actualGives the attributes of a font description or a named font.
font deleteDeletes one or more named fonts.
font familiesGives the names of the font families that ztk knows.
font loadReads a font file of the app and gives its family.
font measureGives the width of a text in a font, in pixels.
font metricsGives the heights of a font and tells if its characters have one width.
font namesGives the names of the named fonts.

Examples

% font measure {Courier 12} abc
29

% font create Title -family Helvetica -size 18 -weight bold
> font actual Title -weight
bold

Errors

% font
wrong # args: should be "font option ?arg?"
-errorcode TCL WRONGARGS

% font size x
bad option "size": must be actual, configure, create, delete, families, load, measure, metrics, or names
-errorcode NONE

Differences from Tcl

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztk 1.0.0-beta.1

See also