1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:07:45 +00:00

LibWeb: Remove glyph run allocation in paint_text_fragment()

Instead of allocating a new glyph run to scale glyph positions and
fonts, a scale factor could be encoded in a paint command and applied
later during command execution.
This commit is contained in:
Aliaksandr Kalenik 2024-03-01 14:14:47 +01:00 committed by Andreas Kling
parent aeb5a0d9e8
commit cf6999f5f3
11 changed files with 25 additions and 27 deletions

View file

@ -48,10 +48,12 @@ void CommandList::execute(CommandExecutor& executor)
for (auto& command_with_scroll_id : m_commands) {
auto& command = command_with_scroll_id.command;
if (command.has<DrawGlyphRun>()) {
auto scale = command.get<DrawGlyphRun>().scale;
for (auto const& glyph_or_emoji : command.get<DrawGlyphRun>().glyph_run) {
if (glyph_or_emoji.has<Gfx::DrawGlyph>()) {
auto const& glyph = glyph_or_emoji.get<Gfx::DrawGlyph>();
unique_glyphs.ensure(glyph.font, [] { return HashTable<u32> {}; }).set(glyph.code_point);
auto const& font = *glyph.font->with_size(glyph.font->point_size() * static_cast<float>(scale));
unique_glyphs.ensure(&font, [] { return HashTable<u32> {}; }).set(glyph.code_point);
}
}
}
@ -87,7 +89,7 @@ void CommandList::execute(CommandExecutor& executor)
auto result = command.visit(
[&](DrawGlyphRun const& command) {
return executor.draw_glyph_run(command.glyph_run, command.color, command.translation);
return executor.draw_glyph_run(command.glyph_run, command.color, command.translation, command.scale);
},
[&](DrawText const& command) {
return executor.draw_text(command.rect, command.raw_text, command.alignment, command.color,