From 0d03257e696c41942845ddd3e44dcdd4858cf290 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Sat, 9 Dec 2023 23:14:07 +0100 Subject: [PATCH] LibGfx+LibAccelGfx+LibWeb: Use RefPtr for font in DrawGlyphOrEmoji --- Userland/Libraries/LibAccelGfx/Painter.cpp | 6 +++--- Userland/Libraries/LibGfx/TextLayout.cpp | 8 ++++---- Userland/Libraries/LibGfx/TextLayout.h | 4 ++-- Userland/Libraries/LibWeb/Painting/PaintableBox.cpp | 2 +- Userland/Libraries/LibWeb/Painting/ShadowPainting.cpp | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Userland/Libraries/LibAccelGfx/Painter.cpp b/Userland/Libraries/LibAccelGfx/Painter.cpp index 690e527a12e..05b2ff825ca 100644 --- a/Userland/Libraries/LibAccelGfx/Painter.cpp +++ b/Userland/Libraries/LibAccelGfx/Painter.cpp @@ -399,18 +399,18 @@ void Painter::draw_glyph_run(Span glyph_run, Color if (glyph_or_emoji.has()) { auto const& glyph = glyph_or_emoji.get(); - auto const* font = glyph.font; + auto const& font = *glyph.font; auto code_point = glyph.code_point; auto point = glyph.position; - auto maybe_texture_rect = glyph_atlas.get_glyph_rect(font, code_point); + auto maybe_texture_rect = glyph_atlas.get_glyph_rect(&font, code_point); if (!maybe_texture_rect.has_value()) { continue; } auto texture_rect = to_texture_space(maybe_texture_rect.value().to_type(), *glyph_atlas.texture().size); - auto glyph_position = point + Gfx::FloatPoint(font->glyph_left_bearing(code_point), 0); + auto glyph_position = point + Gfx::FloatPoint(font.glyph_left_bearing(code_point), 0); auto glyph_size = maybe_texture_rect->size().to_type(); auto glyph_rect = transform().map(Gfx::FloatRect { glyph_position, glyph_size }); auto rect_in_clip_space = to_clip_space(glyph_rect); diff --git a/Userland/Libraries/LibGfx/TextLayout.cpp b/Userland/Libraries/LibGfx/TextLayout.cpp index 9ba2c9b6014..41e79f0878c 100644 --- a/Userland/Libraries/LibGfx/TextLayout.cpp +++ b/Userland/Libraries/LibGfx/TextLayout.cpp @@ -224,7 +224,7 @@ DrawGlyphOrEmoji prepare_draw_glyph_or_emoji(FloatPoint point, Utf8CodePointIter return DrawGlyph { .position = point, .code_point = code_point, - .font = &font, + .font = font, }; } @@ -233,7 +233,7 @@ DrawGlyphOrEmoji prepare_draw_glyph_or_emoji(FloatPoint point, Utf8CodePointIter return DrawEmoji { .position = point, .emoji = emoji, - .font = &font, + .font = font, }; } @@ -242,7 +242,7 @@ DrawGlyphOrEmoji prepare_draw_glyph_or_emoji(FloatPoint point, Utf8CodePointIter return DrawGlyph { .position = point, .code_point = code_point, - .font = &font, + .font = font, }; } @@ -251,7 +251,7 @@ DrawGlyphOrEmoji prepare_draw_glyph_or_emoji(FloatPoint point, Utf8CodePointIter return DrawGlyph { .position = point, .code_point = 0xFFFD, - .font = &font, + .font = font, }; } diff --git a/Userland/Libraries/LibGfx/TextLayout.h b/Userland/Libraries/LibGfx/TextLayout.h index a694cad1a5d..0d7ecf83c8f 100644 --- a/Userland/Libraries/LibGfx/TextLayout.h +++ b/Userland/Libraries/LibGfx/TextLayout.h @@ -78,13 +78,13 @@ enum class IncludeLeftBearing { struct DrawGlyph { FloatPoint position; u32 code_point; - Font const* font; + NonnullRefPtr font; }; struct DrawEmoji { FloatPoint position; Gfx::Bitmap const* emoji; - Font const* font; + NonnullRefPtr font; }; using DrawGlyphOrEmoji = Variant; diff --git a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp index 34474357c45..cc775fd12f3 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp +++ b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp @@ -643,7 +643,7 @@ static void paint_text_fragment(PaintContext& context, Layout::TextNode const& t scaled_glyph_run.ensure_capacity(fragment.glyph_run().size()); for (auto glyph : fragment.glyph_run()) { glyph.visit([&](auto& glyph) { - glyph.font = &scaled_font; + glyph.font = scaled_font; glyph.position = glyph.position.scaled(context.device_pixels_per_css_pixel()); }); scaled_glyph_run.append(move(glyph)); diff --git a/Userland/Libraries/LibWeb/Painting/ShadowPainting.cpp b/Userland/Libraries/LibWeb/Painting/ShadowPainting.cpp index d021612f04a..65e461b26b9 100644 --- a/Userland/Libraries/LibWeb/Painting/ShadowPainting.cpp +++ b/Userland/Libraries/LibWeb/Painting/ShadowPainting.cpp @@ -593,7 +593,7 @@ void paint_text_shadow(PaintContext& context, Layout::LineBoxFragment const& fra scaled_glyph_run.ensure_capacity(fragment.glyph_run().size()); for (auto glyph : fragment.glyph_run()) { glyph.visit([&](auto& glyph) { - glyph.font = &scaled_font; + glyph.font = scaled_font; glyph.position = glyph.position.scaled(context.device_pixels_per_css_pixel()); }); scaled_glyph_run.append(move(glyph));