Skip to content

FontManager

Drew Chase (Work) edited this page Mar 31, 2026 · 2 revisions

FontManager

The FontManager struct manages font loading and provides access to the underlying cosmic_text::FontSystem. It lives in the aurora_text::font_manager module.

Feature gate

FontManager is part of the aurora_text crate and is available when the text feature is enabled on the main aurora crate.

Struct

pub struct FontManager {
    font_system: cosmic_text::FontSystem,
}

Constructor

FontManager::new()

Creates a new font manager with an empty font database. Equivalent to FontManager::default().

let mut font_manager = FontManager::new();

FontManager::new_with_locale(locale)

Creates a new font manager with a BCP 47 locale tag (e.g. "en-US", "ar-SA", "ja-JP"). The locale is passed to cosmic_text::FontSystem for locale-aware font fallback — for example, choosing Japanese vs Chinese variants of shared Han characters.

let mut fm = FontManager::new_with_locale("ja-JP");

FontManager::new_with_locale_and_system_db(locale)

Same as new_with_locale but also loads system fonts. Combines locale support with system font discovery.

let mut fm = FontManager::new_with_locale_and_system_db("ar-SA");

When using App::locale("ja-JP"), the platform automatically calls new_with_locale or new_with_locale_and_system_db based on the use_system_font setting.

Methods

load(path) -> Result<(), FontError>

Loads a font from a file path on disk. The path can be anything that implements AsRef<Path>.

font_manager.load("fonts/Roboto-Regular.ttf")?;

load_from_bytes(bytes) -> Option<String>

Loads a font from a byte slice. Returns the font family name on success, or None if the font could not be parsed.

This is the preferred method when embedding fonts with include_bytes!:

let family = font_manager.load_from_bytes(include_bytes!("Roboto-Regular.ttf"));
assert_eq!(family, Some("Roboto".to_string()));

font_system_mut() -> &mut cosmic_text::FontSystem

Returns a mutable reference to the underlying cosmic_text::FontSystem. Needed by TextLayout for shaping and rasterisation.

Usage with App

Fonts can be registered on the App builder using the font() method, which calls load_from_bytes internally:

App::new()
    .font(include_bytes!("Roboto-Regular.ttf"))
    .run(|window, _| { /* ... */ })
    .unwrap();

FontError

Errors returned by FontManager::load.

pub enum FontError {
    FailedToLoadFont(io::Error),
}
Variant Cause
FailedToLoadFont The file could not be read from disk

FontError implements Display and converts from io::Error.

AuroraUI is a cross-platform desktop UI framework that treats performance as a first-class constraint — not an afterthought.

Platform

  • App - Application builder, windowing, and event loop
  • MultiWindow - Window spawning, modals, messaging
  • Native Menu - OS menu bars (menu feature)
  • System Tray - System tray icons (tray feature)
  • Threading - Background tasks, thread-safe state

Core

  • Color - Color utilities and color schemes
  • Undo / Redo - UndoStack and text input undo

Geometry

  • Rect - Rectangle geometry
  • Point - Point geometry
  • Size - Size geometry
  • Edges - Edge insets (padding, margins, borders)
  • Corners - Corner radii for rounded rectangles

GPU

  • GpuContext - GPU surface abstraction and backends

Render

Text

Widgets

  • Layout - Column, Row, Stack, Positioned
  • ScrollView - Scrollable viewport with scrollbar
  • VirtualList - Virtualized list for large datasets
  • Button - Styled button with any child content
  • BoxWidget - Colored rectangle container
  • TextInput - Single-line text input
  • TouchArea - Invisible hit-testing region
  • Drag & Drop - Draggable sources and drop zones
  • ContentSwitch - Conditional child display
  • Image - Raster image display (PNG, JPEG)
  • Composite - Stateful composites & #[composite_widget]
  • TreeView - Hierarchical data with expand/collapse

Components

  • Display - Badge, Card, Alert, Progress, Spinner, Kbd, and more
  • Stepper - Step-by-step progress indicator
  • Forms - Checkbox, Switch, Slider, RadioGroup, Tabs, Accordion, and more
  • SegmentedControl - iOS-style segmented toggle bar
  • NumberInput - Numeric input with +/- buttons
  • RichTextEditor - Rich text editing with bold/italic/underline
  • Form Validation - Validators, error states, form-level validation
  • Overlays - Tooltip, Popover, Dialog, DropdownMenu, Select, Toast
  • Sheet - Slide-in panel from screen edge
  • TagInput - Multi-value input with removable tags
  • SplitPane - Resizable split view with drag handle
  • ColorPicker - Color selection with hex/RGB
  • TimePicker - Time selection with hour/minute spinners
  • DateRangePicker - Dual-calendar date range selection
  • DateTimePicker - Combined date and time selection
  • Data & Advanced - Table, Calendar, Combobox, Command, and more

Theme

  • Theme - Color profiles, slots, and runtime switching

Animation

  • Animation - Tweens, easing, keyframes, timelines, and presets

Code

  • Syntax - Syntax highlighting for 16+ languages

Accessibility

Internationalization

  • i18n - Locale detection, message formatting, RTL layout

Integrations

  • Iconify - Compile-time icons from iconify.design
  • Fonts - Compile-time Google Fonts embedding

Clone this wiki locally