summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorFalseHonesty <thefalsehonesty@gmail.com>2023-06-01 20:42:41 -0400
committerAndreas Kling <kling@serenityos.org>2023-06-02 05:21:22 +0200
commitde9604212f7c4a9bc2607608ffd28c88e5b02072 (patch)
tree9f7cd87838ab1527edd99c348ed7a8d24e70383f /Userland
parent54fb9477a4d69efa15c65f62dfbd4a13feec3af9 (diff)
downloadserenity-de9604212f7c4a9bc2607608ffd28c88e5b02072.zip
LibWeb: Avoid text-aligning content that is too long for its line box
Previously, we would always respect the `text-align` property, even if the text being aligned was too long for its line box and would be clipped. This led to seeing the clipped middle/end of strings when we should instead always see the beginning of the text.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/Layout/LineBuilder.cpp28
1 files changed, 16 insertions, 12 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp b/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp
index beba5659ac..80e199c610 100644
--- a/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp
+++ b/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp
@@ -170,18 +170,22 @@ void LineBuilder::update_last_line()
CSSPixels excess_horizontal_space = m_available_width_for_current_line - line_box.width();
- switch (text_align) {
- case CSS::TextAlign::Center:
- case CSS::TextAlign::LibwebCenter:
- x_offset += excess_horizontal_space / 2;
- break;
- case CSS::TextAlign::Right:
- x_offset += excess_horizontal_space;
- break;
- case CSS::TextAlign::Left:
- case CSS::TextAlign::Justify:
- default:
- break;
+ // If (after justification, if any) the inline contents of a line box are too long to fit within it,
+ // then the contents are start-aligned: any content that doesn't fit overflows the line box’s end edge.
+ if (excess_horizontal_space > 0) {
+ switch (text_align) {
+ case CSS::TextAlign::Center:
+ case CSS::TextAlign::LibwebCenter:
+ x_offset += excess_horizontal_space / 2;
+ break;
+ case CSS::TextAlign::Right:
+ x_offset += excess_horizontal_space;
+ break;
+ case CSS::TextAlign::Left:
+ case CSS::TextAlign::Justify:
+ default:
+ break;
+ }
}
auto strut_baseline = [&] {