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

LibGfx+LibWeb: Move Gfx::ScaledFont caching from LibWeb into LibGfx

Before this change, we would only cache and reuse Gfx::ScaledFont
instances for downloaded CSS fonts.

By moving it into Gfx::VectorFont, we get caching for all vector fonts,
including local system TTFs etc.

This avoids a *lot* of style invalidations in LibWeb, since we now vend
the same Gfx::Font pointer for the same font when used repeatedly.
This commit is contained in:
Andreas Kling 2023-12-25 12:45:18 +01:00
parent bf8107b247
commit f900957d26
16 changed files with 54 additions and 137 deletions

View file

@ -5,7 +5,6 @@
*/
#include <LibGUI/Event.h>
#include <LibWeb/FontCache.h>
#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/HTML/HTMLImageElement.h>
#include <LibWeb/Layout/ButtonBox.h>
@ -65,7 +64,7 @@ void ButtonPaintable::paint(PaintContext& context, PaintPhase phase) const
painter.draw_text(
text_rect.to_type<int>(),
static_cast<HTML::HTMLInputElement const&>(dom_node).value(),
document().style_computer().font_cache().scaled_font(layout_box().first_available_font(), context.device_pixels_per_css_pixel()),
layout_box().scaled_font(context.device_pixels_per_css_pixel()),
Gfx::TextAlignment::Center,
computed_values().color());
painter.restore();

View file

@ -618,10 +618,9 @@ static void paint_text_fragment(PaintContext& context, Layout::TextNode const& t
DevicePixelPoint baseline_start { fragment_absolute_device_rect.x(), fragment_absolute_device_rect.y() + context.rounded_device_pixels(fragment.baseline()) };
Vector<Gfx::DrawGlyphOrEmoji> scaled_glyph_run;
scaled_glyph_run.ensure_capacity(fragment.glyph_run().size());
auto& font_cache = text_node.document().style_computer().font_cache();
for (auto glyph : fragment.glyph_run()) {
glyph.visit([&](auto& glyph) {
glyph.font = font_cache.scaled_font(*glyph.font, context.device_pixels_per_css_pixel());
glyph.font = *glyph.font->with_size(glyph.font->point_size() * static_cast<float>(context.device_pixels_per_css_pixel()));
glyph.position = glyph.position.scaled(context.device_pixels_per_css_pixel());
});
scaled_glyph_run.append(move(glyph));