From 6b3b056476bf86db2eea3e0a164eaae2b2a70b0f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 4 Jul 2023 15:13:33 +0200 Subject: [PATCH] LibWeb: Support CSS font shorthand with up to 4 consecutive `normal` All of the following properties in the font shorthand can be `normal`: - font-style - font-variant - font-weight - font-stretch This means that we must allow up to four consecutive `normal` at the start of a font shorthand value. --- .../expected/font-with-many-normal-values.txt | 30 +++++++++++++++++++ .../input/font-with-many-normal-values.html | 10 +++++++ .../Libraries/LibWeb/CSS/Parser/Parser.cpp | 2 +- 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Layout/expected/font-with-many-normal-values.txt create mode 100644 Tests/LibWeb/Layout/input/font-with-many-normal-values.html diff --git a/Tests/LibWeb/Layout/expected/font-with-many-normal-values.txt b/Tests/LibWeb/Layout/expected/font-with-many-normal-values.txt new file mode 100644 index 0000000000..562646b660 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/font-with-many-normal-values.txt @@ -0,0 +1,30 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x216 [BFC] children: not-inline + BlockContainer at (8,8) content-size 784x200 children: inline + line 0 width: 424, height: 200, bottom: 200, baseline: 159.960937 + frag 0 from TextNode start: 0, length: 1, rect: [8,8 79.296875x200] + "1" + frag 1 from TextNode start: 0, length: 1, rect: [87,154 8x17.46875] + " " + frag 2 from TextNode start: 0, length: 1, rect: [95,8 110.15625x200] + "2" + frag 3 from TextNode start: 0, length: 1, rect: [205,154 8x17.46875] + " " + frag 4 from TextNode start: 0, length: 1, rect: [213,8 113.671875x200] + "3" + frag 5 from TextNode start: 0, length: 1, rect: [327,154 8x17.46875] + " " + frag 6 from TextNode start: 0, length: 1, rect: [335,8 96.875x200] + "4" + InlineNode + TextNode <#text> + TextNode <#text> + InlineNode + TextNode <#text> + TextNode <#text> + InlineNode + TextNode <#text> + TextNode <#text> + InlineNode + TextNode <#text> + TextNode <#text> diff --git a/Tests/LibWeb/Layout/input/font-with-many-normal-values.html b/Tests/LibWeb/Layout/input/font-with-many-normal-values.html new file mode 100644 index 0000000000..d681be02f2 --- /dev/null +++ b/Tests/LibWeb/Layout/input/font-with-many-normal-values.html @@ -0,0 +1,10 @@ + +1 +2 +3 +4 diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 965ba5b17f..e619d112b5 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -6587,7 +6587,7 @@ ErrorOr> Parser::parse_font_value(Vector cons // Since normal is the default value for all the properties that can have it, we don't have to actually // set anything to normal here. It'll be set when we create the FontStyleValue below. // We just need to make sure we were not given more normals than will fit. - int unset_value_count = (font_style ? 0 : 1) + (font_weight ? 0 : 1); + int unset_value_count = (font_style ? 0 : 1) + (font_weight ? 0 : 1) + (font_variant ? 0 : 1) + (font_stretch ? 0 : 1); if (unset_value_count < normal_count) return nullptr;