1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 16:47: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

@ -24,12 +24,15 @@ CommandExecutorCPU::CommandExecutorCPU(Gfx::Bitmap& bitmap)
.scaling_mode = {} });
}
CommandResult CommandExecutorCPU::draw_glyph_run(Vector<Gfx::DrawGlyphOrEmoji> const& glyph_run, Color const& color, Gfx::FloatPoint translation)
CommandResult CommandExecutorCPU::draw_glyph_run(Vector<Gfx::DrawGlyphOrEmoji> const& glyph_run, Color const& color, Gfx::FloatPoint translation, double scale)
{
auto& painter = this->painter();
for (auto& glyph_or_emoji : glyph_run) {
auto transformed_glyph = glyph_or_emoji;
transformed_glyph.visit([&](auto& glyph) { glyph.position.translate_by(translation); });
transformed_glyph.visit([&](auto& glyph) {
glyph.position = glyph.position.scaled(scale).translated(translation);
glyph.font = *glyph.font->with_size(glyph.font->point_size() * static_cast<float>(scale));
});
if (glyph_or_emoji.has<Gfx::DrawGlyph>()) {
auto& glyph = transformed_glyph.get<Gfx::DrawGlyph>();
painter.draw_glyph(glyph.position, glyph.code_point, *glyph.font, color);