From d94db1900ea815926db35f160232070d318ecdc9 Mon Sep 17 00:00:00 2001 From: thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> Date: Thu, 24 Feb 2022 08:52:31 -0500 Subject: LibGUI+LibGfx: Defer to fonts when setting Editor line height Fonts now provide their preferred line height based on maximum height and requested line gap. TTFs provide a preferred line gap from table metrics while BitmapFonts are hardcoded at the previous default for now. --- Userland/Libraries/LibGfx/BitmapFont.h | 2 ++ Userland/Libraries/LibGfx/Font.h | 1 + Userland/Libraries/LibGfx/TrueTypeFont/Font.h | 1 + 3 files changed, 4 insertions(+) (limited to 'Userland/Libraries/LibGfx') diff --git a/Userland/Libraries/LibGfx/BitmapFont.h b/Userland/Libraries/LibGfx/BitmapFont.h index e2b04ce096..b4db8142df 100644 --- a/Userland/Libraries/LibGfx/BitmapFont.h +++ b/Userland/Libraries/LibGfx/BitmapFont.h @@ -53,6 +53,7 @@ public: } 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; } u8 glyph_width(u32 code_point) const override; u8 raw_glyph_width(u32 code_point) const { return m_glyph_widths[code_point]; } @@ -143,6 +144,7 @@ private: u8 m_presentation_size { 0 }; u16 m_weight { 0 }; u8 m_slope { 0 }; + u8 m_line_gap { 4 }; bool m_fixed_width { false }; bool m_owns_arrays { false }; diff --git a/Userland/Libraries/LibGfx/Font.h b/Userland/Libraries/LibGfx/Font.h index a7be32e9de..e9264de823 100644 --- a/Userland/Libraries/LibGfx/Font.h +++ b/Userland/Libraries/LibGfx/Font.h @@ -111,6 +111,7 @@ public: virtual int glyph_or_emoji_width(u32 code_point) const = 0; virtual u8 glyph_height() const = 0; virtual int x_height() const = 0; + virtual int preferred_line_height() const = 0; virtual u8 min_glyph_width() const = 0; virtual u8 max_glyph_width() const = 0; diff --git a/Userland/Libraries/LibGfx/TrueTypeFont/Font.h b/Userland/Libraries/LibGfx/TrueTypeFont/Font.h index c85c8caf5b..657c9d2930 100644 --- a/Userland/Libraries/LibGfx/TrueTypeFont/Font.h +++ b/Userland/Libraries/LibGfx/TrueTypeFont/Font.h @@ -129,6 +129,7 @@ public: virtual bool contains_glyph(u32 code_point) const override { return m_font->glyph_id_for_code_point(code_point) > 0; } virtual u8 glyph_width(u32 code_point) const override; virtual int glyph_or_emoji_width(u32 code_point) const override; + virtual int 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 -- cgit v1.2.3