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

LibGfx: Add Font::pixel_size_rounded_up()

This returns the font's size (distance between ascender and descender)
in pixels, rounded up to the nearest integer.

This is the number we want to use in a lot of UI code, so let's have
a friendly API for it instead of ceil'ing the pixel_size() in a million
random places.
This commit is contained in:
Andreas Kling 2023-03-03 19:30:55 +01:00
parent 6c8e9fa1b3
commit 93c9344e35
4 changed files with 25 additions and 2 deletions

View file

@ -22,6 +22,9 @@ ScaledFont::ScaledFont(NonnullRefPtr<VectorFont> font, float point_width, float
auto metrics = m_font->metrics(m_x_scale, m_y_scale);
m_pixel_size = m_point_height * 1.33333333f;
m_pixel_size_rounded_up = static_cast<int>(ceilf(m_pixel_size));
m_pixel_metrics = Gfx::FontPixelMetrics {
.size = (float)pixel_size(),
.x_height = (float)x_height(),
@ -148,4 +151,14 @@ Gfx::FontPixelMetrics ScaledFont::pixel_metrics() const
return m_pixel_metrics;
}
float ScaledFont::pixel_size() const
{
return m_pixel_size;
}
int ScaledFont::pixel_size_rounded_up() const
{
return m_pixel_size_rounded_up;
}
}