Repository navigation
Fix invisible mermaid labels on Linux (font fallback) - #108
Closed
lazy-dinosaur wants to merge 1 commit into
Closed
lazy-dinosaur wants to merge 1 commit into
lazy-dinosaur wants to merge 1 commit into
Conversation
terminal_theme() requested only generic CSS font families (Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif). On Linux, none of those resolve to a real face in usvg/resvg's bundled fontdb (it does not honour the 'sans-serif' generic alias and only indexes face names from font directories). resvg therefore drops every <text> glyph silently, leaving boxes and arrows but no labels. Insert DejaVu Sans and Liberation Sans before the generic sans-serif fallback. Both ship by default on virtually every Linux desktop install and are absent on macOS/Windows, so platform-native families (Inter/Segoe UI/-apple-system) still win first there.
1 task
zombi3butt
pushed a commit
to zombi3butt/jcode
that referenced
this pull request
May 22, 2026
The terminal mermaid theme set `font_family` to "Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif". On most desktop Linux distributions none of those names resolve to an installed font (Inter is rare, ui-sans-serif/system-ui are CSS-only, Segoe UI is Windows-only), so resvg's text rasterizer fell back to a font that lacked the glyphs jcode actually emits in node labels — labels rendered invisible inside the rendered PNG. Append "DejaVu Sans" and "Liberation Sans" to the family list. Both are part of `fonts-dejavu-core` / `fonts-liberation` which are pulled in by virtually every desktop Linux install. macOS and Windows still hit `-apple-system` / `Segoe UI` first, so this is purely additive. Ports upstream PR 1jehuang#108. Closes 1jehuang#92
Owner
|
Thanks! This repo no longer accepts external PRs, but the underlying problem is real - it's now tracked in #371 (with credit to this PR). Closing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Body Draft
Summary
On Linux, mermaid diagrams rendered by jcode show only the box outlines and arrows — node labels are invisible. This PR adds Linux-native font fallbacks (
DejaVu Sans,Liberation Sans) toterminal_theme()so the bundledresvg/usvgrenderer can resolve a real font face for SVG<text>elements.Reproduction (before fix)
graph LR A[Start] --> B[Middle] --> C[End]On Arch Linux + kitty + tmux + jcode v0.11.9, the rendered diagram pinned in the side panel shows three box outlines connected by arrows but no text inside the boxes.
Verified on:
jcode v0.11.9(release build) andv0.11.6-dev(built fromf071bc2a)resvg 0.46,usvg 0.46DejaVu Sans,Liberation Sans,Noto Sans CJK KR,Noto Color Emoji, etc.Root cause
crates/jcode-tui-mermaid/src/mermaid_content.rs::terminal_theme()declares the SVGfont-familyas:mermaid-rs-rendereremits real SVG<text>elements with this font-family verbatim.resvg/usvg's embeddedfontdbthen tries to resolve those names:Interui-sans-serifsystem-ui-apple-systemSegoe UIsans-seriffontdbdoes not resolve generic CSS families→ resvg falls through every name and emits
Warning (in usvg::text:129): No match for '...' font-family.Then it skips drawing the text glyphs entirely while still drawing the rect/path/marker elements. Result: empty boxes.I verified this by:
/usr/bin/resvgdirectly → identical empty output, identical OCR (zero text)."DejaVu Sans"→ resvg renders text correctly, OCR picks up "Start", "Middle", "End".mermaid-rs-rendereritself emits proper SVG<text>with the labels — the SVG is fine, the renderer's fontdb is the bottleneck.This is not the same as the well-known mermaid
<foreignObject>/htmlLabelsissue, sincemermaid-rs-renderer(a pure Rust mermaid implementation, notmmdc) emits real SVG<text>elements rather than embedded HTML.Fix
Add
DejaVu SansandLiberation SansbetweenSegoe UIandsans-serif. These are present on essentially every Linux desktop install (Debian/Ubuntu/Fedora/Arch/openSUSE all ship one or both via base font packages), and are absent on macOS/Windows so the existing platform-preferred families still win there.After fix
Same diagram, same machine, with the patched binary (
v0.11.6-dev (dirty)):usvg::textwarnings in stderrNotes / alternatives considered
trebuchet ms→DejaVu Sansetc.) does not work becauseusvg::fontdb::Database::load_system_fonts()only scans font directories, it does not interpret fontconfig alias rules.mermaid-rs-rendererhas analogous font-fallback issues in itsTheme::mermaid_default()andTheme::modern()— happy to send a follow-up PR there too if helpful.Interkeeps macOS/Windows behavior unchanged:Inter/Segoe UI/-apple-systemstill win first when present.Test plan
cargo build --release(nightly toolchain) succeedstests/fixtures/*corpus viammdrCLI)Need help on this PR? Tag
@codesmithwith what you need.