text-system
Garnet system fonts
require "garnet-text-system" provides the platform's fonts as Garnet::Text::Fonts, so games need not ship or locate font files for interface text.
family = Garnet::Text.system_family # the system UI font
bold = Garnet::Text.system_family(bold: true)
serif = Garnet::Text.system_family("Georgia") # an installed family (Core Text)
world.add_plugin(MyHud.new(family))
On macOS and iOS, Garnet::Text::SystemFont.new(name = nil, bold: false) opens the system UI font, or an installed family by family, full or PostScript name (Text::Error if it is not installed), through Core Text. shape lays out a run with a CTLine: kerning, ligatures and the run's direction (direction: :rtl sets the base writing direction) are applied, and glyphs come back in visual order with UTF-8 cluster ranges like the HarfBuzz adapter's. Metrics, advances and outlines are em-normalized.
Core Text substitutes other installed fonts for characters the font lacks (emoji, CJK, Arabic, ...). Those glyphs keep working through the same SystemFont: glyph IDs carry the supplying font's slot in their upper 16 bits, and glyph_path outlines them from that font. supports?(char) is true whenever the font or Core Text's fallback covers the character, so a SystemFont is a good last entry in a FontFamily.
Elsewhere, Garnet::Text.system_family loads the first installed file in Garnet::Text::SYSTEM_FONT_PATHS (DejaVu Sans, Noto Sans or Liberation Sans on Linux, Segoe UI or Arial on Windows) with the HarfBuzz adapter; named families need Core Text there.
Native piece
native/system_font.c is a small C bridge over Core Text. Desktop macOS builds link native/libgarnet_text_system.a, which the shard's postinstall (make -C native, run by scripts/garnet env --natives and garnet build) builds; the Makefile builds nothing on other platforms. iOS apps compile the source beside the shared host: list it in the project's iOS target, with the CoreText framework:
"ios": {"platform": "ios", "backend": "metal", "entry": "ios.cr",
"host": "../../native/ios/host.m", "frameworks": ["CoreText", ...],
"link": ["../../../text-system/native/system_font.c"]}
Fonts are retained Core Text objects released by the font's finalizer; they hold no GPU memory.
text-system
- 0
- 0
- 0
- 1
- 4
- 2 days ago
- November 30, 2026
MIT License
Thu, 03 Dec 2026 02:11:08 GMT