LibGfx+LibWeb: Support per-glyph font fallbacks in canvas text painting

Instead of using the first font from the FontCascadeList for all glyphs
in a text, we perform a text shaping process that finds a suitable font
for each glyph and returns a list of glyph runs, where each glyph run
represents consecutive glyphs using the same font.
This commit is contained in:
Aliaksandr Kalenik 2025-04-19 21:36:26 +02:00 committed by Andreas Kling
parent 1e7922fac8
commit f6b0851c38
Notes: github-actions[bot] 2025-04-21 07:52:18 +00:00
3 changed files with 49 additions and 4 deletions

View file

@ -232,11 +232,13 @@ Gfx::Path CanvasRenderingContext2D::text_path(StringView text, float x, float y,
auto& drawing_state = this->drawing_state();
auto const& font = font_cascade_list()->first();
auto const& font_cascade_list = this->font_cascade_list();
auto const& font = font_cascade_list->first();
auto glyph_runs = Gfx::shape_text({ x, y }, Utf8View(text), *font_cascade_list);
Gfx::Path path;
auto glyph_run = Gfx::shape_text({ x, y }, 0, Utf8View(text), font, Gfx::GlyphRun::TextType::Ltr, {});
path.glyph_run(*glyph_run);
for (auto const& glyph_run : glyph_runs) {
path.glyph_run(glyph_run);
}
auto text_width = path.bounding_box().width();
Gfx::AffineTransform transform = {};