diff options
author | thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> | 2022-02-24 08:52:31 -0500 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-24 18:09:22 +0100 |
commit | d94db1900ea815926db35f160232070d318ecdc9 (patch) | |
tree | 2ac6f4c66b0f5e4ec14c155e87287c5a3628db89 /Userland | |
parent | 07910c12e316a20297ce56f9fc333a42755f3005 (diff) | |
download | serenity-d94db1900ea815926db35f160232070d318ecdc9.zip |
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.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibGUI/TextEditor.cpp | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/TextEditor.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/BitmapFont.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/Font.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/TrueTypeFont/Font.h | 1 |
5 files changed, 7 insertions, 5 deletions
diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp index 240b0833ee..b1ad773e62 100644 --- a/Userland/Libraries/LibGUI/TextEditor.cpp +++ b/Userland/Libraries/LibGUI/TextEditor.cpp @@ -465,10 +465,10 @@ void TextEditor::paint_event(PaintEvent& event) auto ruler_line_rect = ruler_content_rect(i); // NOTE: Use Painter::draw_text() directly here, as we want to always draw the line numbers in clear text. painter.draw_text( - ruler_line_rect.shrunken(2, 0).translated(0, m_line_spacing / 2), + ruler_line_rect.shrunken(2, 0), String::number(i + 1), is_current_line ? font().bold_variant() : font(), - Gfx::TextAlignment::TopRight, + Gfx::TextAlignment::CenterRight, is_current_line ? palette().ruler_active_text() : palette().ruler_inactive_text()); } } @@ -1977,7 +1977,7 @@ void TextEditor::set_editing_engine(OwnPtr<EditingEngine> editing_engine) int TextEditor::line_height() const { - return font().glyph_height() + m_line_spacing; + return font().preferred_line_height(); } int TextEditor::fixed_glyph_width() const diff --git a/Userland/Libraries/LibGUI/TextEditor.h b/Userland/Libraries/LibGUI/TextEditor.h index e42e00b228..ba3e46a97e 100644 --- a/Userland/Libraries/LibGUI/TextEditor.h +++ b/Userland/Libraries/LibGUI/TextEditor.h @@ -116,7 +116,6 @@ public: TextDocumentLine const& line(size_t index) const { return document().line(index); } NonnullOwnPtrVector<TextDocumentLine>& lines() { return document().lines(); } NonnullOwnPtrVector<TextDocumentLine> const& lines() const { return document().lines(); } - int line_spacing() const { return m_line_spacing; } int line_height() const; TextPosition cursor() const { return m_cursor; } TextRange normalized_selection() const { return m_selection.normalized(); } @@ -351,7 +350,6 @@ private: bool m_visualize_trailing_whitespace { true }; bool m_visualize_leading_whitespace { false }; bool m_cursor_line_highlighting { true }; - int m_line_spacing { 4 }; size_t m_soft_tab_width { 4 }; int m_horizontal_content_padding { 3 }; TextRange m_selection; 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 |