Skip to content

gpui: Fix SVG renderer not rendering text when system fonts are unavailable#51623

Merged
smitbarmase merged 1 commit into
zed-industries:mainfrom
Dnreikronos:51466-mermaid-diagrams-missing-text
Apr 7, 2026
Merged

gpui: Fix SVG renderer not rendering text when system fonts are unavailable#51623
smitbarmase merged 1 commit into
zed-industries:mainfrom
Dnreikronos:51466-mermaid-diagrams-missing-text

Conversation

@Dnreikronos

Copy link
Copy Markdown
Contributor

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:

  • Fixed mermaid diagrams not showing text in markdown preview by bundling fallback fonts and fixing generic font family resolution in the SVG renderer.

@cla-bot

cla-bot Bot commented Mar 15, 2026

Copy link
Copy Markdown

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Dnreikronos.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email email@example.com
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

@Dnreikronos Dnreikronos force-pushed the 51466-mermaid-diagrams-missing-text branch from e92a9ca to 974a463 Compare March 15, 2026 20:21
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Mar 15, 2026
@Dnreikronos

Copy link
Copy Markdown
Contributor Author

The problem

Mermaid 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.

Impact

Mermaid 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.

@maxdeviant maxdeviant changed the title gpui: Fix mermaid diagrams not showing text in markdown preview (#51466) gpui: Fix mermaid diagrams not showing text in markdown preview Mar 15, 2026
@Dnreikronos Dnreikronos force-pushed the 51466-mermaid-diagrams-missing-text branch from 0dac4e4 to 80bd968 Compare March 27, 2026 17:51
@zed-industries-bot

zed-industries-bot commented Apr 6, 2026

Copy link
Copy Markdown
Contributor
Warnings
⚠️

This PR is missing release notes.

Please add a "Release Notes" section that describes the change:

Release Notes:

- Added/Fixed/Improved ...

If your change is not user-facing, you can use "N/A" for the entry:

Release Notes:

- N/A

Generated by 🚫 dangerJS against 4fbe7d7

@Dnreikronos Dnreikronos force-pushed the 51466-mermaid-diagrams-missing-text branch from 69de58d to 4fbe7d7 Compare April 6, 2026 22:04

@smitbarmase smitbarmase left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@smitbarmase smitbarmase changed the title gpui: Fix mermaid diagrams not showing text in markdown preview gpui: Fix SVG renderer not rendering text when system fonts are unavailable Apr 7, 2026
@smitbarmase smitbarmase merged commit eaf14d0 into zed-industries:main Apr 7, 2026
31 checks passed
KlausUllrich added a commit to KlausUllrich/zed that referenced this pull request Apr 8, 2026
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>
@qnfm

qnfm commented Apr 9, 2026

Copy link
Copy Markdown

Thanks, finally landed in upstream. I don't need to maintain a cherry-picked branch.

piper-of-dawn pushed a commit to piper-of-dawn/zed that referenced this pull request Apr 25, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mermaid diagrams don't show text

4 participants