mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:57:45 +00:00
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. :^)
This commit is contained in:
parent
b08bb0bdc3
commit
fa4eeca0ac
1 changed files with 11 additions and 7 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue