LibGfx: Add dummy Font::x_height() getter

Right now we just guess that the x-height is glyph_height/2, which is
obviously not accurate. We currently don't store the x-height in fonts,
so that's something we'll need to fix.
This commit is contained in:
Andreas Kling 2020-08-07 20:29:32 +02:00
parent fae9c9f81f
commit 0bbced444b
2 changed files with 7 additions and 0 deletions

View file

@ -137,6 +137,9 @@ Font::Font(const StringView& name, unsigned* rows, u8* widths, bool is_fixed_wid
, m_glyph_spacing(glyph_spacing)
, m_fixed_width(is_fixed_width)
{
// FIXME: This is just a dumb guess. It would be cool to know the actual x-height of the font!
m_x_height = glyph_height / 2;
m_glyph_count = glyph_count_by_type(m_type);
if (!m_fixed_width) {

View file

@ -94,6 +94,8 @@ public:
u8 glyph_width(size_t ch) const { return m_fixed_width ? m_glyph_width : m_glyph_widths[ch]; }
int glyph_or_emoji_width(u32 code_point) const;
u8 glyph_height() const { return m_glyph_height; }
int x_height() const { return m_x_height; }
u8 min_glyph_width() const { return m_min_glyph_width; }
u8 max_glyph_width() const { return m_max_glyph_width; }
u8 glyph_fixed_width() const { return m_glyph_width; }
@ -121,6 +123,7 @@ public:
FontTypes type() { return m_type; }
void set_type(FontTypes type);
private:
Font(const StringView& name, unsigned* rows, u8* widths, bool is_fixed_width, u8 glyph_width, u8 glyph_height, u8 glyph_spacing, FontTypes type);
@ -137,6 +140,7 @@ private:
u8 m_glyph_width { 0 };
u8 m_glyph_height { 0 };
u8 m_x_height { 0 };
u8 m_min_glyph_width { 0 };
u8 m_max_glyph_width { 0 };
u8 m_glyph_spacing { 0 };