1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:27:43 +00:00

LibWeb: Apply CSS text-transform during layout

Previously we were doing this at the painting stage, which meant that
layout potentially used the wrong glyphs when measuring text.

This would lead to incorrect layout metrics and was visible on the
HTML5Test score display, for example. :^)
This commit is contained in:
Andreas Kling 2022-12-23 19:57:52 +01:00
parent cf47c850e7
commit 32e35a02f9
2 changed files with 11 additions and 7 deletions

View file

@ -7,6 +7,7 @@
#include <AK/CharacterTypes.h>
#include <AK/StringBuilder.h>
#include <LibUnicode/CharacterTypes.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/Layout/BlockContainer.h>
#include <LibWeb/Layout/InlineFormattingContext.h>
@ -31,10 +32,19 @@ static bool is_all_whitespace(StringView string)
return true;
}
static DeprecatedString apply_text_transform(DeprecatedString const& string, CSS::TextTransform text_transform)
{
if (text_transform == CSS::TextTransform::Uppercase)
return Unicode::to_unicode_uppercase_full(string);
if (text_transform == CSS::TextTransform::Lowercase)
return Unicode::to_unicode_lowercase_full(string);
return string;
}
// NOTE: This collapses whitespace into a single ASCII space if collapse is true.
void TextNode::compute_text_for_rendering(bool collapse)
{
auto& data = dom_node().data();
auto data = apply_text_transform(dom_node().data(), computed_values().text_transform());
if (dom_node().is_password_input()) {
m_text_for_rendering = DeprecatedString::repeated('*', data.length());