mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:07:45 +00:00
LibWeb: Teach line layout to collapse whitespace across fragments
This kind of HTML now produces a single piece of whitespace: <span> </span> <span> </span> <span> </span> We achieve this by checking if the last fragment on the last line ends in whitespace. If so, we either don't add a fragment at all (for the current chunk) or we simply skip over all whitespace at the head of the current chunk (instead of collapsing it to a single ' '.)
This commit is contained in:
parent
4ab1b0b436
commit
07ccaa1934
5 changed files with 46 additions and 15 deletions
|
@ -30,6 +30,7 @@
|
|||
#include <LibWeb/Layout/LayoutText.h>
|
||||
#include <LibWeb/Layout/LineBoxFragment.h>
|
||||
#include <LibWeb/RenderingContext.h>
|
||||
#include <ctype.h>
|
||||
|
||||
namespace Web {
|
||||
|
||||
|
@ -45,6 +46,14 @@ void LineBoxFragment::render(RenderingContext& context)
|
|||
}
|
||||
}
|
||||
|
||||
bool LineBoxFragment::ends_in_whitespace() const
|
||||
{
|
||||
auto text = this->text();
|
||||
if (text.is_empty())
|
||||
return false;
|
||||
return isspace(text[text.length() - 1]);
|
||||
}
|
||||
|
||||
bool LineBoxFragment::is_justifiable_whitespace() const
|
||||
{
|
||||
return text() == " ";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue