Skip to main content

Crate day_fonts

Crate day_fonts 

Source
Expand description

Bundled custom fonts (DESIGN §18.4).

A project ships font files under a top-level fonts/ directory. day build stages them into each platform’s native font location (Android res/font/, the iOS DayPieces bundle + UIAppFonts, ArkUI rawfile, loose Resources/fonts on the desktops) and each backend registers them at startup so Font::Custom("Family", pt) resolves by the font’s family name, the name baked into the file’s name table (what Font Book / fontconfig report), not its file name.

This module is the one implementation shared by the CLI (staging-time family extraction, identifier naming) and the runtimes (startup registration, family → file resolution):

  • parse_font_names: a minimal sfnt name-table reader for .ttf/.otf/.ttc.
  • font_dir / bundled_fonts: locate the staged font files at runtime (DAY_FONT_ROOT under day launch, bundle-relative Resources/fonts when packed).
  • resolve_font_file: map a requested family name to one of the bundled files, for backends whose native API wants a file path rather than a registered family (XAML).
  • font_ident: the identifier both the Android/ArkUI stagers and their runtimes derive from a family name ("Special Elite" → special_elite), so lookup needs no side table.

Structs§

FontNames
The names a font file reports for itself.

Constants§

FONT_EXTS
Font file extensions accepted under fonts/.

Functions§

bundled_fonts
Every bundled font file (font_dir filtered to FONT_EXTS), sorted by file name. The list backends iterate to register the app’s fonts at startup.
font_dir
The directory holding the app’s bundled font files at runtime: DAY_FONT_ROOT (the project’s fonts/ under day launch), then bundle-relative locations next to the executable (macOS .app Resources/fonts, files staged next to a desktop binary).
font_files_in
The font files directly under dir, sorted by file name (shared with the CLI’s scanner).
font_ident
The identifier the Android / ArkUI stagers derive from a family name, and that their runtimes re-derive to look the font up (Android R.font.<ident>): lowercase, [a-z0-9_] only, with a leading letter enforced. "Special Elite" → special_elite.
parse_font_names
Read the family and PostScript names from a raw font file (.ttf, .otf, or the first face of a .ttc). A tiny sfnt reader: only the table directory and the name table are touched, so it is safe to run on untrusted bytes (every access is bounds-checked).
resolve_font_file
Resolve a requested family name to the bundled font file that provides it (case-insensitive, PostScript name accepted too). For backends whose native font API takes a file path rather than a registered family name.