summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp
diff options
context:
space:
mode:
authorsin-ack <sin-ack@users.noreply.github.com>2022-03-12 17:01:06 +0000
committerAndreas Kling <kling@serenityos.org>2022-03-12 21:51:38 +0100
commit7fe3f2d970304207bf22c7ea8db9bfe425281926 (patch)
tree171aae040c548617b8ba36b95879696ff1b718ac /Userland/Libraries/LibWeb/Layout/LineBuilder.cpp
parentf0a1ab6f84ab433fdadab1350cb04722e7775e19 (diff)
downloadserenity-7fe3f2d970304207bf22c7ea8db9bfe425281926.zip
LibWeb: Refactor text justification code + only justify below threshold
All the justification-related code is now in InlineFormattingContext::apply_justification_to_fragments and is performed after all the line boxes have been added. Text justification now only happens on the last line if the excess space including whitespace is below a certain threshold. 10% seemed reasonable since it prevents the "over-justification" of text. Note that fragments in line boxes before the last one are always justified.
Diffstat (limited to 'Userland/Libraries/LibWeb/Layout/LineBuilder.cpp')
-rw-r--r--Userland/Libraries/LibWeb/Layout/LineBuilder.cpp26
1 files changed, 0 insertions, 26 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp b/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp
index 65c4db3880..750b73c89b 100644
--- a/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp
+++ b/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp
@@ -125,19 +125,6 @@ void LineBuilder::update_last_line()
break;
}
- float excess_horizontal_space_including_whitespace = excess_horizontal_space;
- size_t whitespace_count = 0;
- if (text_align == CSS::TextAlign::Justify) {
- for (auto& fragment : line_box.fragments()) {
- if (fragment.is_justifiable_whitespace()) {
- ++whitespace_count;
- excess_horizontal_space_including_whitespace += fragment.width();
- }
- }
- }
-
- float justified_space_width = whitespace_count > 0 ? (excess_horizontal_space_including_whitespace / static_cast<float>(whitespace_count)) : 0;
-
auto fragment_baseline = [&](auto const& fragment) -> float {
if (fragment.layout_node().is_text_node())
return fragment.layout_node().font().baseline();
@@ -193,19 +180,6 @@ void LineBuilder::update_last_line()
fragment.set_offset({ new_fragment_x, new_fragment_y });
bottom = max(bottom, new_fragment_y + fragment.height() + fragment.border_box_bottom());
-
- if (text_align == CSS::TextAlign::Justify
- && fragment.is_justifiable_whitespace()
- && fragment.width() != justified_space_width) {
- float diff = justified_space_width - fragment.width();
- fragment.set_width(justified_space_width);
- // Shift subsequent sibling fragments to the right to adjust for change in width.
- for (size_t j = i + 1; j < line_box.fragments().size(); ++j) {
- auto offset = line_box.fragments()[j].offset();
- offset.translate_by(diff, 0);
- line_box.fragments()[j].set_offset(offset);
- }
- }
}
line_box.m_bottom = bottom;