Skip to content

LibGfx+LibWeb: Use per-code-point font fallback for SVG text - #11228

Open
sideshowbarker wants to merge 2 commits into
LadybirdBrowser:masterfrom
sideshowbarker:svg-text-font-fallback
Open

LibGfx+LibWeb: Use per-code-point font fallback for SVG text#11228
sideshowbarker wants to merge 2 commits into
LadybirdBrowser:masterfrom
sideshowbarker:svg-text-font-fallback

Conversation

@sideshowbarker

@sideshowbarker sideshowbarker commented Aug 20, 2026

Copy link
Copy Markdown
Member

Problem: Characters a generic font doesn’t cover drew as missing-glyph boxes inside SVG text; e.g. U+1D11E with font-family:serif — while the same character renders correctly in ordinary HTML text, and naming a font that does cover it renders it correctly inside SVG as well.

Cause: The SVG text path builder resolved one font for a whole run with first_available_font() — the first font in the list that covers the space character — and then handed the entire string to Skia to map through that font alone. So any code point outside it became glyph 0.

Fix: Shape each run with Gfx::shape_text() against the box’s full font list — the same way HTML text and canvas text already did. Fixes #11031.

Note

This PR branch contains two commits: The first commit has the change described above, while the second commit is entirely just deletions of the Path::text() and place_text_along() code — which no longer has any callers, after the change to using Gfx::shape_text() against the box’s full font list.

So, it might be easier to first review the first commit in isolation, and then review the deletions.

@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 826a8ed3-e730-458b-9b85-2ad47772b972

📥 Commits

Reviewing files that changed from the base of the PR and between 7192c79 and e96c05e.

⛔ Files ignored due to path filters (3)
  • Tests/LibWeb/Screenshot/expected/svg-gradient-paint-transformation.png is excluded by !**/*.png
  • Tests/LibWeb/Screenshot/expected/svg-text-effects.png is excluded by !**/*.png
  • Tests/LibWeb/Screenshot/expected/svg-textPath.png is excluded by !**/*.png
📒 Files selected for processing (11)
  • Libraries/LibGfx/Path.h
  • Libraries/LibGfx/PathSkia.cpp
  • Libraries/LibGfx/PathSkia.h
  • Libraries/LibWeb/Layout/LayoutRustBridge.cpp
  • Tests/LibWeb/Layout/expected/css-namespace-tag-name-selector.txt
  • Tests/LibWeb/Layout/expected/svg-text-dominant-baseline.txt
  • Tests/LibWeb/Layout/expected/svg-text-with-percentage-values.txt
  • Tests/LibWeb/Layout/expected/svg-text-with-viewbox.txt
  • Tests/LibWeb/Layout/expected/svg/svg-text-positioning.txt
  • Tests/LibWeb/Ref/expected/svg-text-font-fallback-ref.html
  • Tests/LibWeb/Ref/input/svg-text-font-fallback.html
🚧 Files skipped from review as they are similar to previous changes (10)
  • Tests/LibWeb/Layout/expected/css-namespace-tag-name-selector.txt
  • Tests/LibWeb/Ref/input/svg-text-font-fallback.html
  • Tests/LibWeb/Layout/expected/svg-text-with-viewbox.txt
  • Libraries/LibGfx/PathSkia.h
  • Tests/LibWeb/Ref/expected/svg-text-font-fallback-ref.html
  • Tests/LibWeb/Layout/expected/svg-text-with-percentage-values.txt
  • Libraries/LibWeb/Layout/LayoutRustBridge.cpp
  • Tests/LibWeb/Layout/expected/svg/svg-text-positioning.txt
  • Libraries/LibGfx/PathSkia.cpp
  • Libraries/LibGfx/Path.h

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

LibGfx replaces UTF-8 and UTF-16 text placement APIs with glyph-run placement APIs. The Skia backend transforms glyph outlines along paths using glyph positions, widths, and path tangents. SVG layout now shapes text with the complete font list for fallback support, uses glyph runs for measurement and rendering, and places them along paths. Layout expectations and SVG font-fallback tests were updated.

Sequence Diagram(s)

sequenceDiagram
  participant SVGLayout
  participant GfxShapeText
  participant PathSkia
  SVGLayout->>GfxShapeText: Shape text with the font list
  GfxShapeText-->>SVGLayout: Return glyph runs
  SVGLayout->>PathSkia: Place glyph runs along the path
  PathSkia-->>SVGLayout: Return transformed glyph outlines
Loading

Suggested reviewers: kalenikaliaksandr

Merge Risk: ⚪ Minimal · up to e96c0

SVG text now selects fallback fonts per code point, preventing missing-glyph boxes for unsupported characters while preserving the existing rendering path. No actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The pull request description directly explains the SVG font-fallback defect, its cause, the glyph-run shaping fix, and the removal of unused path text APIs. These changes match the summarized changese…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The pull request description directly explains the SVG font-fallback defect, its cause, the glyph-run shaping fix, and the removal of unused path text APIs. These changes match the summarized changeset.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the conflicts Pull request has merge conflicts that need resolution label Aug 28, 2026
@LadybirdBrowser LadybirdBrowser deleted a comment from github-actions Bot Aug 28, 2026
Problem: Characters a generic font doesn’t cover drew as missing-glyph
boxes inside SVG text; e.g. U+1D11E with font-family:serif — while the
same character renders correctly in ordinary HTML text, and naming a
font that does cover it renders it correctly inside SVG as well.

Cause: The SVG text path builder resolved one font for a whole run with
first_available_font() — the first font in the list that covers the
space character — and then handed the entire string to Skia to map
through that font alone. So any code point outside it became glyph 0.

Fix: Shape each run with Gfx::shape_text() against the box’s full font
list — the same way HTML text and canvas text already did.

Fixes LadybirdBrowser#11031
After SVG text path-building was reworked to build from shaped glyph
runs, Path::text() and place_text_along() no longer have any callers.
@sideshowbarker
sideshowbarker force-pushed the svg-text-font-fallback branch from 2067bf1 to e96c05e Compare August 28, 2026 12:17
@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@github-actions github-actions Bot removed the conflicts Pull request has merge conflicts that need resolution label Aug 28, 2026
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.

SVG <text> does not use fallback fonts for missing glyphs

1 participant