1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 20:17:44 +00:00

LibGfx: Make text painting better at aligning vector fonts vertically

This is achieved by simplifying the logic in TextLayout. We get rid
of all the various ways that the layout bounding rect can get cropped.
Then we make sure to use the right pixel metrics.

Finally we use the font's own line gap metrics instead of hard-coding 4.

The end result is that text painted with vector fonts now gets pretty
reasonable vertical alignment in most cases.
This commit is contained in:
Andreas Kling 2023-01-06 11:55:23 +01:00
parent f5e18dda2b
commit b2d3ceaec5
4 changed files with 22 additions and 58 deletions

View file

@ -20,11 +20,6 @@
namespace Gfx {
enum class FitWithinRect {
Yes,
No
};
// FIXME: This currently isn't an ideal way of doing things; ideally, TextLayout
// would be doing the rendering by painting individual glyphs. However, this
// would regress our Unicode bidirectional text support. Therefore, fixing this
@ -46,23 +41,25 @@ class TextLayout {
public:
TextLayout(Gfx::Font const& font, Utf8View const& text, FloatRect const& rect)
: m_font(font)
, m_font_metrics(font.pixel_metrics())
, m_text(text)
, m_rect(rect)
{
}
Vector<DeprecatedString, 32> lines(TextElision elision, TextWrapping wrapping, int line_spacing) const
Vector<DeprecatedString, 32> lines(TextElision elision, TextWrapping wrapping) const
{
return wrap_lines(elision, wrapping, line_spacing, FitWithinRect::Yes);
return wrap_lines(elision, wrapping);
}
FloatRect bounding_rect(TextWrapping wrapping, int line_spacing) const;
FloatRect bounding_rect(TextWrapping) const;
private:
Vector<DeprecatedString, 32> wrap_lines(TextElision, TextWrapping, int line_spacing, FitWithinRect) const;
DeprecatedString elide_text_from_right(Utf8View, bool force_elision) const;
Vector<DeprecatedString, 32> wrap_lines(TextElision, TextWrapping) const;
DeprecatedString elide_text_from_right(Utf8View) const;
Font const& m_font;
FontPixelMetrics m_font_metrics;
Utf8View m_text;
FloatRect m_rect;
};