mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +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:
parent
07910c12e3
commit
d94db1900e
Notes:
sideshowbarker
2024-07-18 03:35:30 +09:00
Author: https://github.com/thankyouverycool Commit: https://github.com/SerenityOS/serenity/commit/d94db1900e Pull-request: https://github.com/SerenityOS/serenity/pull/12750 Reviewed-by: https://github.com/awesomekling
5 changed files with 7 additions and 5 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue