LibGfx+LibAccelGfx+LibWeb: Use RefPtr for font in DrawGlyphOrEmoji

This commit is contained in:
Aliaksandr Kalenik 2023-12-09 23:14:07 +01:00 committed by Andreas Kling
parent 451df70275
commit 0d03257e69
Notes: sideshowbarker 2024-07-17 09:49:33 +09:00
5 changed files with 11 additions and 11 deletions

View File

@ -399,18 +399,18 @@ void Painter::draw_glyph_run(Span<Gfx::DrawGlyphOrEmoji const> glyph_run, Color
if (glyph_or_emoji.has<Gfx::DrawGlyph>()) { if (glyph_or_emoji.has<Gfx::DrawGlyph>()) {
auto const& glyph = glyph_or_emoji.get<Gfx::DrawGlyph>(); auto const& glyph = glyph_or_emoji.get<Gfx::DrawGlyph>();
auto const* font = glyph.font; auto const& font = *glyph.font;
auto code_point = glyph.code_point; auto code_point = glyph.code_point;
auto point = glyph.position; 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()) { if (!maybe_texture_rect.has_value()) {
continue; continue;
} }
auto texture_rect = to_texture_space(maybe_texture_rect.value().to_type<float>(), *glyph_atlas.texture().size); auto texture_rect = to_texture_space(maybe_texture_rect.value().to_type<float>(), *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<float>(); auto glyph_size = maybe_texture_rect->size().to_type<float>();
auto glyph_rect = transform().map(Gfx::FloatRect { glyph_position, glyph_size }); auto glyph_rect = transform().map(Gfx::FloatRect { glyph_position, glyph_size });
auto rect_in_clip_space = to_clip_space(glyph_rect); auto rect_in_clip_space = to_clip_space(glyph_rect);

View File

@ -224,7 +224,7 @@ DrawGlyphOrEmoji prepare_draw_glyph_or_emoji(FloatPoint point, Utf8CodePointIter
return DrawGlyph { return DrawGlyph {
.position = point, .position = point,
.code_point = code_point, .code_point = code_point,
.font = &font, .font = font,
}; };
} }
@ -233,7 +233,7 @@ DrawGlyphOrEmoji prepare_draw_glyph_or_emoji(FloatPoint point, Utf8CodePointIter
return DrawEmoji { return DrawEmoji {
.position = point, .position = point,
.emoji = emoji, .emoji = emoji,
.font = &font, .font = font,
}; };
} }
@ -242,7 +242,7 @@ DrawGlyphOrEmoji prepare_draw_glyph_or_emoji(FloatPoint point, Utf8CodePointIter
return DrawGlyph { return DrawGlyph {
.position = point, .position = point,
.code_point = code_point, .code_point = code_point,
.font = &font, .font = font,
}; };
} }
@ -251,7 +251,7 @@ DrawGlyphOrEmoji prepare_draw_glyph_or_emoji(FloatPoint point, Utf8CodePointIter
return DrawGlyph { return DrawGlyph {
.position = point, .position = point,
.code_point = 0xFFFD, .code_point = 0xFFFD,
.font = &font, .font = font,
}; };
} }

View File

@ -78,13 +78,13 @@ enum class IncludeLeftBearing {
struct DrawGlyph { struct DrawGlyph {
FloatPoint position; FloatPoint position;
u32 code_point; u32 code_point;
Font const* font; NonnullRefPtr<Font const> font;
}; };
struct DrawEmoji { struct DrawEmoji {
FloatPoint position; FloatPoint position;
Gfx::Bitmap const* emoji; Gfx::Bitmap const* emoji;
Font const* font; NonnullRefPtr<Font const> font;
}; };
using DrawGlyphOrEmoji = Variant<DrawGlyph, DrawEmoji>; using DrawGlyphOrEmoji = Variant<DrawGlyph, DrawEmoji>;

View File

@ -643,7 +643,7 @@ static void paint_text_fragment(PaintContext& context, Layout::TextNode const& t
scaled_glyph_run.ensure_capacity(fragment.glyph_run().size()); scaled_glyph_run.ensure_capacity(fragment.glyph_run().size());
for (auto glyph : fragment.glyph_run()) { for (auto glyph : fragment.glyph_run()) {
glyph.visit([&](auto& glyph) { glyph.visit([&](auto& glyph) {
glyph.font = &scaled_font; glyph.font = scaled_font;
glyph.position = glyph.position.scaled(context.device_pixels_per_css_pixel()); glyph.position = glyph.position.scaled(context.device_pixels_per_css_pixel());
}); });
scaled_glyph_run.append(move(glyph)); scaled_glyph_run.append(move(glyph));

View File

@ -593,7 +593,7 @@ void paint_text_shadow(PaintContext& context, Layout::LineBoxFragment const& fra
scaled_glyph_run.ensure_capacity(fragment.glyph_run().size()); scaled_glyph_run.ensure_capacity(fragment.glyph_run().size());
for (auto glyph : fragment.glyph_run()) { for (auto glyph : fragment.glyph_run()) {
glyph.visit([&](auto& glyph) { glyph.visit([&](auto& glyph) {
glyph.font = &scaled_font; glyph.font = scaled_font;
glyph.position = glyph.position.scaled(context.device_pixels_per_css_pixel()); glyph.position = glyph.position.scaled(context.device_pixels_per_css_pixel());
}); });
scaled_glyph_run.append(move(glyph)); scaled_glyph_run.append(move(glyph));