summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorsin-ack <sin-ack@users.noreply.github.com>2021-08-28 02:08:15 +0000
committerAndreas Kling <kling@serenityos.org>2021-08-29 01:43:09 +0200
commitfa4eeca0ac3330ba6fee226b315ca06652a7ea11 (patch)
tree990c88813e3954cb7e4c1aaa96ad3d6fcb9e2533 /Userland/Libraries
parentb08bb0bdc35ad2400086000ff2c63d5926480c84 (diff)
downloadserenity-fa4eeca0ac3330ba6fee226b315ca06652a7ea11.zip
LibWeb: Properly handle newlines at the end of LineBoxes
This always subtracted the glyph width of a space, despite isspace also accepting newlines and a few other characters. It now also uses AK/CharacterTypes.h. :^)
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibWeb/Layout/LineBox.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/LineBox.cpp b/Userland/Libraries/LibWeb/Layout/LineBox.cpp
index 5f2a342dd9..894344fe5c 100644
--- a/Userland/Libraries/LibWeb/Layout/LineBox.cpp
+++ b/Userland/Libraries/LibWeb/Layout/LineBox.cpp
@@ -4,12 +4,12 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <AK/CharacterTypes.h>
#include <AK/Utf8View.h>
#include <LibWeb/Layout/Box.h>
#include <LibWeb/Layout/LineBox.h>
#include <LibWeb/Layout/Node.h>
#include <LibWeb/Layout/TextNode.h>
-#include <ctype.h>
namespace Web::Layout {
@@ -40,16 +40,20 @@ void LineBox::trim_trailing_whitespace()
if (m_fragments.is_empty())
return;
- auto last_text = m_fragments.last().text();
+ auto& last_fragment = m_fragments.last();
+ auto last_text = last_fragment.text();
if (last_text.is_null())
return;
- auto& last_fragment = m_fragments.last();
- int space_width = last_fragment.layout_node().font().glyph_width(' ');
- while (last_fragment.length() && isspace(last_text[last_fragment.length() - 1])) {
+ while (last_fragment.length()) {
+ auto last_character = last_text[last_fragment.length() - 1];
+ if (!is_ascii_space(last_character))
+ break;
+
+ int last_character_width = last_fragment.layout_node().font().glyph_width(last_character);
last_fragment.m_length -= 1;
- last_fragment.set_width(last_fragment.width() - space_width);
- m_width -= space_width;
+ last_fragment.set_width(last_fragment.width() - last_character_width);
+ m_width -= last_character_width;
}
}