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

LibGfx: Make Font::preferred_line_height() more correct

Return a float, and fix a bogus calculation of ascender + descender.
This commit is contained in:
Andreas Kling 2023-01-05 17:13:55 +01:00
parent 43a10674d0
commit 2a61d66b0a
8 changed files with 10 additions and 10 deletions

View file

@ -69,7 +69,7 @@ public:
float glyphs_horizontal_kerning(u32, u32) const override { return 0.f; }
u8 glyph_height() const override { return m_glyph_height; }
int x_height() const override { return m_x_height; }
int preferred_line_height() const override { return glyph_height() + m_line_gap; }
virtual float preferred_line_height() const override { return glyph_height() + m_line_gap; }
virtual float glyph_width(u32 code_point) const override;
u8 raw_glyph_width(u32 code_point) const { return m_glyph_widths[code_point]; }

View file

@ -156,7 +156,7 @@ public:
virtual float glyphs_horizontal_kerning(u32 left_code_point, u32 right_code_point) const = 0;
virtual u8 glyph_height() const = 0;
virtual int x_height() const = 0;
virtual int preferred_line_height() const = 0;
virtual float preferred_line_height() const = 0;
virtual u8 min_glyph_width() const = 0;
virtual u8 max_glyph_width() const = 0;

View file

@ -534,7 +534,7 @@ Gfx::ScaledFontMetrics Font::metrics([[maybe_unused]] float x_scale, float y_sca
return Gfx::ScaledFontMetrics {
.ascender = static_cast<float>(raw_ascender) * y_scale,
.descender = static_cast<float>(raw_descender) * y_scale,
.descender = -static_cast<float>(raw_descender) * y_scale,
.line_gap = static_cast<float>(raw_line_gap) * y_scale,
};
}

View file

@ -111,7 +111,7 @@ Gfx::FontPixelMetrics ScaledFont::pixel_metrics() const
.advance_of_ascii_zero = (float)glyph_width('0'),
.glyph_spacing = (float)glyph_spacing(),
.ascent = metrics.ascender,
.descent = -metrics.descender,
.descent = metrics.descender,
.line_gap = metrics.line_gap,
};
}

View file

@ -55,7 +55,7 @@ public:
virtual float glyph_width(u32 code_point) const override;
virtual float glyph_or_emoji_width(u32 code_point) const override;
virtual float glyphs_horizontal_kerning(u32 left_code_point, u32 right_code_point) const override;
virtual int preferred_line_height() const override { return metrics().height() + metrics().line_gap; }
virtual float preferred_line_height() const override { return metrics().height() + metrics().line_gap; }
virtual u8 glyph_height() const override { return m_point_height; }
virtual int x_height() const override { return m_point_height; } // FIXME: Read from font
virtual u8 min_glyph_width() const override { return 1; } // FIXME: Read from font

View file

@ -18,9 +18,9 @@ struct ScaledFontMetrics {
float descender { 0 };
float line_gap { 0 };
int height() const
float height() const
{
return ascender - descender;
return ascender + descender;
}
};