- Project: Ferrite (markdown editor, Rust + egui)
- Tech Stack: Rust 2021, egui 0.28
- Context file: Always read
ai-context.mdfirst — it contains project rules, architecture, and conventions. - Branch: master
- NO HISTORY: Do not include a project history document or past task details unless they directly impact this specific task.
- SCOPE: Focus ONLY on the current task detailed below.
- Run
cargo buildorcargo checkafter code changes. - Mark tasks in Task Master:
in-progresswhen starting,donewhen verified. - Document by feature under
docs/technical/and add an entry todocs/index.md. - Prefer Task Master MCP tools over CLI when available.
- Use Context7 MCP when needed.
- Status: pending
- Priority: high
- Complexity: 7
- Dependencies: Task 37 (done)
Prevent app crash when selecting custom system fonts on Linux by catching epaint panics, validating TTF/OTF font data with magic bytes, falling back to Inter font, and adding toast notifications. Extend shaping support for FONT_CUSTOM in ttf_bytes_for_font_id_shaping.
Five changes across fonts and central panel:
- Panic protection — Wrap font loading in
std::panic::catch_unwindinload_system_font_by_name. - Font validation — Add TTF/OTF magic byte check (
\0\1\0\0for TTF,OTTOfor OTF) before passing data to epaint. Reject.ttccollections, Type 1, broken files. - Graceful fallback + toast — On failure, reset to Inter font and show a toast notification with the error.
- Fix shaping — Add
FONT_CUSTOMcase tottf_bytes_for_font_id_shapingso custom fonts get proper text shaping. - Reload integration — Ensure
reload_fonts()incentral_panel.rshandles errors without propagating panics.
src/fonts.rs—load_system_font_by_name,FONT_CUSTOM,create_font_definitions_with_cjk_spec,ttf_bytes_for_font_id_shapingsrc/app/central_panel.rs—reload_fontscall
- Empty/broken font files, font collections (.ttc), non-TTF/OTF formats (Type 1, WOFF)
- font-kit returning invalid data
- Rapid font switching
- Complexity: 7/10 (medium-high)
- Recommendation: Default model is fine. Involves panic handling, byte validation, and fallback logic but is well-scoped to two files.
Before starting any new task:
cargo build