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

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.
This commit is contained in:
thankyouverycool 2022-02-24 08:52:31 -05:00 committed by Andreas Kling
parent 07910c12e3
commit d94db1900e
5 changed files with 7 additions and 5 deletions

View file

@ -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

View file

@ -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;