Font
pykraken.Font A font typeface for rendering text.
More about Font
This class wraps an SDL_ttf font and manages font properties like size, style, and alignment. You can load fonts from a file path or use one of the built-in typefaces:
- "kraken-modern": A modern sans-serif font bundled with the engine.
- "kraken-retro": A pixel/retro font bundled with the engine. Point size is rounded to the nearest multiple of 8 for crisp rendering.
Note
A window/renderer must be created before using fonts. Typically you should call kn.window.create(...) first, which initializes the font engine.
At a glance
14 membersReference
PYTHON APIConstructor
methodFont(file_dir: str | PathLike, pt_size: int)Create a Font.
Args
- file_dir (
str | PathLike[str]) — Path to a .ttf font file, or one of the built-in names "kraken-modern" or "kraken-retro". - pt_size (
int) — The point size. Values below 8 are clamped to 8. For "kraken-retro", the size is rounded to the nearest multiple of 8 to preserve pixel alignment.
Raises
- RuntimeError — If the font fails to load.
alignment
propertyalignment: TextAlignGet or set the text alignment for wrapped text.
ascent
propertyascent: intGet the pixel ascent of the font.
Returns
- int — The font ascent in pixels.
bold
propertybold: boolGet or set whether bold text style is enabled.
descent
propertydescent: intGet the pixel descent of the font.
Returns
- int — The font descent in pixels.
height
propertyheight: intGet the maximum pixel height of all glyphs in the font.
Returns
- int — The font height in pixels.
hinting
propertyhinting: FontHintGet or set the font hinting mode.
italic
propertyitalic: boolGet or set whether italic text style is enabled.
kerning
propertykerning: boolGet or set whether kerning is enabled.
line_spacing
propertyline_spacing: intGet or set the spacing between lines of text in pixels.
outline
propertyoutline: intGet or set the outline width in pixels (0 for no outline).
pt_size
propertypt_size: intGet or set the point size of the font. Values below 8 are clamped to 8.
strikethrough
propertystrikethrough: boolGet or set whether strikethrough text style is enabled.
underline
propertyunderline: boolGet or set whether underline text style is enabled.