LibGfx+LibWeb: Simplify text shaping API by removing per glyph callback

All places where text shaping happens, the callback is used to simply
append a glyph into the end of glyphs vector. This change removes the
callback parameter and makes the text shaping function return a glyph
run.
This commit is contained in:
Aliaksandr Kalenik 2024-09-14 19:54:41 +02:00 committed by Alexander Kalenik
commit 17f4ed6ea1
Notes: github-actions[bot] 2024-09-15 13:43:30 +00:00
5 changed files with 19 additions and 42 deletions

View file

@ -513,16 +513,10 @@ CanvasRenderingContext2D::PreparedText CanvasRenderingContext2D::prepare_text(By
Gfx::FloatPoint anchor { 0, 0 };
auto physical_alignment = Gfx::TextAlignment::CenterLeft;
auto glyph_run = adopt_ref(*new Gfx::GlyphRun({}, *font, Gfx::GlyphRun::TextType::Ltr));
float glyph_run_width = 0;
Gfx::for_each_glyph_position(
anchor, replaced_text.code_points(), *font, [&](Gfx::DrawGlyph const& glyph) {
glyph_run->append(glyph);
},
glyph_run_width);
auto glyph_run = Gfx::shape_text(anchor, replaced_text.code_points(), *font, Gfx::GlyphRun::TextType::Ltr);
// 8. Let result be an array constructed by iterating over each glyph in the inline box from left to right (if any), adding to the array, for each glyph, the shape of the glyph as it is in the inline box, positioned on a coordinate space using CSS pixels with its origin is at the anchor point.
PreparedText prepared_text { glyph_run, physical_alignment, { 0, 0, static_cast<int>(glyph_run_width), static_cast<int>(height) } };
PreparedText prepared_text { glyph_run, physical_alignment, { 0, 0, static_cast<int>(glyph_run->width()), static_cast<int>(height) } };
// 9. Return result, physical alignment, and the inline box.
return prepared_text;