Skip to main content

Crate system_fonts

Crate system_fonts 

Source
Expand description

System font discovery and locale-based preset selection.

This crate provides a small API for:

  • Detecting the current system locale
  • Mapping a locale to a FontRegion
  • Resolving a prioritized list of installed system fonts using fontdb

The output (FoundFont) is designed to be consumed by UI toolkits (e.g. egui_system_fonts), where the caller loads the font bytes and registers them into the UI font system.

§Quick start

Resolve fonts from the current system locale:

use system_fonts::{find_for_system_locale, FontStyle};

let (_locale, region, fonts) = find_for_system_locale(FontStyle::Sans);
println!("region={region:?}, fonts={}", fonts.len());

Force a locale or region policy manually:

use system_fonts::{find_for_locale, FontStyle};

let (region, fonts) = find_for_locale("ko-KR", FontStyle::Sans);
println!("region={region:?}, fonts={}", fonts.len());

§Notes

  • Font resolution is best-effort: unknown families are skipped.
  • The internal font database is cached (loaded once per process).
  • FoundFont::key is unique within a single run; do not persist it across runs.

Structs§

FoundFont
A resolved system font entry usable by UI code.

Enums§

FontPreset
A preset represents a prioritized group of candidate font families.
FontRegion
Writing system/locale region used to decide fallback priority.
FontStyle
Font preference used when selecting system fonts.
FoundFontSource
Font bytes source resolved from the system font database.

Functions§

find_for_locale
Detects a region from the given locale string, then resolves fonts using that region’s presets.
find_for_system_locale
Resolves fonts based on the current system locale.
find_from_presets
Resolves system fonts from presets and style.
presets_for_region
Returns the default preset priority list for a given region.
region_from_locale
Converts a locale string into a FontRegion.
system_locale
Returns the current system locale string (e.g. “ko-KR”, “en-US”) if available.