Skip to content
resolve_font_file_for_char

resolve_font_file_for_char

Mojo function 🡭

resolve_font_file_for_char

fn def resolve_font_file_for_char(family: String, slant: FontSlant, weight: FontWeight, codepoint: Int) -> String

Like resolve_font_file, but constrained to a font that contains codepoint – the fallback render.mojo uses when the requested family has no glyph for a character, such as CJK text under a Latin-only “Sans”.

If no installed font has codepoint, the unconstrained best match is returned. Check the result with glyph_outline.has_glyph to distinguish that from a real hit.

Args:

  • family (String): Font family name or generic alias (e.g. “sans-serif”).
  • slant (FontSlant): Requested upright/italic/oblique style.
  • weight (FontWeight): Requested normal/bold weight.
  • codepoint (Int): Unicode codepoint the matched font should contain.

Returns:

String: The matched font’s absolute file path.

Raises:

Error: no font files were found on this machine.