Skip to content

fix(components): factor typeface resolution and stop panicking on missing fonts#28

Merged
LeadcodeDev merged 1 commit into
mainfrom
fix/components-typeface-fallback
Jul 18, 2026
Merged

fix(components): factor typeface resolution and stop panicking on missing fonts#28
LeadcodeDev merged 1 commit into
mainfrom
fix/components-typeface-fallback

Conversation

@LeadcodeDev

Copy link
Copy Markdown
Owner

Closes #8.

Goal: rendering never panics because a font is missing; one shared resolution path.

  • ~32 duplicated match_family_style(...).or_else(Helvetica).or_else(Arial) chains across 37 files replaced by the existing typeface_with_fallback (already re-exported from renderer, already documented "use this instead of .expect" — it just wasn't used)
  • All panicking tails removed, including the panic!("No fonts available") in codeblock/highlight.rs (its JetBrains Mono → Fira Code → … monospace preference chain is preserved; only the tail changed)
  • On FontNotFound (essentially unreachable): painters skip the affected text — font helpers return Option, callers bail with balanced canvas.save()/restore() (comparison.rs restores before returning; terminal.rs/table.rs/notification.rs resolve fonts before saving)
  • rich_text spans resolve per-span (filter_map) so one unresolvable span doesn't abort the whole paint

Verify: cargo test --workspace → 133 passed ✓ · cargo fmt --check ✓ · clippy 0 warnings ✓ · grep: no panicking font resolution remains ✓

Replace ~32 duplicated match_family_style fallback chains and every
panicking resolution (.expect("No fallback font"), panic!("No fonts
available")) with the existing typeface_with_fallback helper. On the
essentially-unreachable FontNotFound, painters now skip the affected
text instead of crashing the render; font helpers return Option and
callers bail out with balanced canvas save/restore.
@LeadcodeDev
LeadcodeDev merged commit cafa619 into main Jul 18, 2026
@LeadcodeDev
LeadcodeDev deleted the fix/components-typeface-fallback branch July 18, 2026 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(components): factor typeface resolution and stop panicking on missing fonts

1 participant