Skip to content

create.text

Fonts: Font and FontWeight, with Noto Sans built in.

Font

struct Font

A typeface loaded from a file: an asset, like an Image.

Font.load(path) opens it once; copies share the open face, so a font is cheap to keep in a field, a Style or several of each. The face is closed when the last copy goes. Size and weight are not part of a font — they come from the style each time text is drawn.

Its italic is the italic_path file where one was given, otherwise the font's own italic axis, otherwise its upright glyphs sheared.

Implements Copyable, Deinitable, ImplicitlyCopyable, Movable, Writable.

load

@staticmethod
def load(path: String, italic_path: Optional[String] = None) raises -> Self

Open the face at path, and the italic at italic_path if given. Raises if either cannot be read as one.

A relative path is resolved against the directory of the calling source file, not the working directory, as Image.load's is.

path

def path(self) -> String

The file it was loaded from.

italic_path

def italic_path(self) -> Optional[String]

The file its italic was loaded from, if it was given one.

has_glyph

def has_glyph(self, codepoint: Int) raises -> Bool

Whether this face can render codepoint.

FontWeight

struct FontWeight

A stroke weight, for canvas.font_weight.

Design-space values on the packaged variable faces, so they interpolate rather than selecting a file — any number in 100..900 is valid, the constants are CSS's names for each hundred. FontWeight(450) names one in between.

A wrapped number rather than a bare Int, like WindowMode, so a stray number — a font size, say — cannot be passed where a weight is expected.

Implements Copyable, Deinitable, Equatable, ImplicitlyCopyable, Movable, Writable.

Constants

  • THIN = FontWeight(Int(100))
  • EXTRA_LIGHT = FontWeight(Int(200))
  • LIGHT = FontWeight(Int(300))
  • REGULAR = FontWeight(Int(400))
  • MEDIUM = FontWeight(Int(500))
  • SEMI_BOLD = FontWeight(Int(600))
  • BOLD = FontWeight(Int(700))
  • EXTRA_BOLD = FontWeight(Int(800))
  • BLACK = FontWeight(Int(900))

Fields

  • value: Int

Constructors

@staticmethod
def __init__(out self, value: Int)

__eq__

def __eq__(self, other: Self) -> Bool

__ne__

def __ne__(self, other: Self) -> Bool