CLASS v1.8.0

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.

Reference

PYTHON API
Font(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

property
alignment: TextAlign

Get or set the text alignment for wrapped text.

ascent

property
ascent: int

Get the pixel ascent of the font.

Returns

  • int — The font ascent in pixels.

bold

property
bold: bool

Get or set whether bold text style is enabled.

descent

property
descent: int

Get the pixel descent of the font.

Returns

  • int — The font descent in pixels.

height

property
height: int

Get the maximum pixel height of all glyphs in the font.

Returns

  • int — The font height in pixels.

hinting

property
hinting: FontHint

Get or set the font hinting mode.

italic

property
italic: bool

Get or set whether italic text style is enabled.

kerning

property
kerning: bool

Get or set whether kerning is enabled.

line_spacing

property
line_spacing: int

Get or set the spacing between lines of text in pixels.

outline

property
outline: int

Get or set the outline width in pixels (0 for no outline).

pt_size

property
pt_size: int

Get or set the point size of the font. Values below 8 are clamped to 8.

strikethrough: bool

Get or set whether strikethrough text style is enabled.

underline

property
underline: bool

Get or set whether underline text style is enabled.

Find your next step

Start typing to search the manual.