gpui: Fix SVG renderer not rendering text when system fonts are unavailable#51623
Conversation
|
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Dnreikronos.
|
e92a9ca to
974a463
Compare
The problemMermaid diagrams in Zed's markdown preview showed up as empty boxes. No text at all. The logs were full of this: No match for '"Inter", "ui-sans-serif", "system-ui", sans-serif' font-family. Two things going wrong here. On some Linux setups, fontconfig doesn't resolve fonts properly, leaving the database empty or stuck with defaults that aren't actually installed. On top of that, fontdb doesn't understand CSS keywords like system-ui or ui-sans-serif, which is exactly what Mermaid puts in its SVG output. So even when the right fonts are on the machine, they weren't being found. What changed (crates/gpui/src/svg_renderer.rs) First, we load IBM Plex Sans and Lilex (both already ship with Zed) into the SVG font database via load_bundled_fonts(). This way there's always at least one sans-serif and one monospace font available. Second, we remap generic font families. fontdb points sans-serif at Arial, monospace at Courier New, and so on. Those don't exist on most Linux systems. fix_generic_font_families() redirects these to the bundled fonts when the defaults fail to resolve. Third, we added a last-resort fallback in the font resolver. If nothing matches (e.g. system-ui), we pick the first available font instead of returning nothing. ImpactMermaid text renders correctly now, even on systems with broken font resolution. System fonts are still loaded and preferred; the bundled fonts only step in as fallbacks. The font database is built once (LazyLock) and cloned, so there's no extra I/O cost. No new dependencies since both fonts already ship with Zed. |
0dac4e4 to
80bd968
Compare
69de58d to
4fbe7d7
Compare
Load bundled fonts (IBM Plex Sans, Lilex) into the font database and fix generic font family resolution on Linux where fontconfig may not override fontdb's Microsoft font defaults. Adds sans-serif fallback for unrecognized CSS system font keywords like "system-ui". Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Thanks, finally landed in upstream. I don't need to maintain a cherry-picked branch. |
…ilable (zed-industries#51623) Closes zed-industries#51466 Before you mark this PR as ready for review, make sure that you have: - [x] Added a solid test coverage and/or screenshots from doing manual testing - [x] Done a self-review taking into account security and performance aspects - [ ] Aligned any UI changes with the [UI checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) Release Notes: - Fixed mermaid diagrams not showing text in markdown preview by bundling fallback fonts and fixing generic font family resolution in the SVG renderer.
Closes #51466
Before you mark this PR as ready for review, make sure that you have:
Added a solid test coverage and/or screenshots from doing manual testing
Done a self-review taking into account security and performance aspects
Aligned any UI changes with the UI checklist
Release Notes: