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

LibGfx: Use Font::pixel_size() instead of glyph_height() when painting

This gives us correct height metrics for both bitmap and scalable fonts.
This commit is contained in:
Andreas Kling 2022-03-27 00:55:08 +01:00
parent ff951c89fe
commit 65629d26fe
2 changed files with 7 additions and 7 deletions

View file

@ -1267,8 +1267,8 @@ void Painter::draw_emoji(IntPoint const& point, Gfx::Bitmap const& emoji, Font c
IntRect dst_rect { IntRect dst_rect {
point.x(), point.x(),
point.y(), point.y(),
font.glyph_height() * emoji.width() / emoji.height(), font.pixel_size() * emoji.width() / emoji.height(),
font.glyph_height() font.pixel_size()
}; };
draw_scaled_bitmap(dst_rect, emoji, emoji.rect()); draw_scaled_bitmap(dst_rect, emoji, emoji.rect());
} }
@ -1366,7 +1366,7 @@ void draw_text_line(IntRect const& a_rect, Utf8View const& text, Font const& fon
} }
if (is_vertically_centered_text_alignment(alignment)) { if (is_vertically_centered_text_alignment(alignment)) {
int distance_from_baseline_to_bottom = (font.glyph_height() - 1) - font.baseline(); int distance_from_baseline_to_bottom = (font.pixel_size() - 1) - font.baseline();
rect.translate_by(0, distance_from_baseline_to_bottom / 2); rect.translate_by(0, distance_from_baseline_to_bottom / 2);
} }
@ -1391,7 +1391,7 @@ void draw_text_line(IntRect const& a_rect, Utf8View const& text, Font const& fon
if (kerning != 0) if (kerning != 0)
point.translate_by(direction == TextDirection::LTR ? kerning : -kerning, 0); point.translate_by(direction == TextDirection::LTR ? kerning : -kerning, 0);
IntSize glyph_size(font.glyph_or_emoji_width(code_point) + font.glyph_spacing(), font.glyph_height()); IntSize glyph_size(font.glyph_or_emoji_width(code_point) + font.glyph_spacing(), font.pixel_size());
if (direction == TextDirection::RTL) if (direction == TextDirection::RTL)
point.translate_by(-glyph_size.width(), 0); // If we are drawing right to left, we have to move backwards before drawing the glyph point.translate_by(-glyph_size.width(), 0); // If we are drawing right to left, we have to move backwards before drawing the glyph
draw_glyph({ point, glyph_size }, it); draw_glyph({ point, glyph_size }, it);
@ -1574,7 +1574,7 @@ void Painter::do_draw_text(IntRect const& rect, Utf8View const& text, Font const
TextLayout layout(&font, text, rect); TextLayout layout(&font, text, rect);
static int const line_spacing = 4; static int const line_spacing = 4;
int line_height = font.glyph_height() + line_spacing; int line_height = font.pixel_size() + line_spacing;
auto lines = layout.lines(elision, wrapping, line_spacing); auto lines = layout.lines(elision, wrapping, line_spacing);
auto bounding_rect = layout.bounding_rect(wrapping, line_spacing); auto bounding_rect = layout.bounding_rect(wrapping, line_spacing);
@ -2294,7 +2294,7 @@ void Gfx::Painter::draw_ui_text(Gfx::IntRect const& rect, StringView text, Gfx::
Optional<size_t> underline_offset; Optional<size_t> underline_offset;
auto name_to_draw = parse_ampersand_string(text, &underline_offset); auto name_to_draw = parse_ampersand_string(text, &underline_offset);
Gfx::IntRect text_rect { 0, 0, font.width(name_to_draw), font.glyph_height() }; Gfx::IntRect text_rect { 0, 0, font.width(name_to_draw), font.pixel_size() };
text_rect.align_within(rect, text_alignment); text_rect.align_within(rect, text_alignment);
draw_text(text_rect, name_to_draw, font, text_alignment, color); draw_text(text_rect, name_to_draw, font, text_alignment, color);

View file

@ -28,7 +28,7 @@ IntRect TextLayout::bounding_rect(TextWrapping wrapping, int line_spacing) const
} }
IntRect bounding_rect = { IntRect bounding_rect = {
0, 0, 0, static_cast<int>((lines.size() * (m_font->glyph_height() + line_spacing)) - line_spacing) 0, 0, 0, static_cast<int>((lines.size() * (m_font->pixel_size() + line_spacing)) - line_spacing)
}; };
for (auto& line : lines) { for (auto& line : lines) {