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.
This commit is contained in:
Andreas Kling 2023-07-04 15:13:33 +02:00 committed by Jelle Raaijmakers
parent 793c2ff65a
commit 6b3b056476
3 changed files with 41 additions and 1 deletions

View file

@ -0,0 +1,30 @@
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
BlockContainer <html> at (0,0) content-size 800x216 [BFC] children: not-inline
BlockContainer <body> 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 <span.one>
TextNode <#text>
TextNode <#text>
InlineNode <span.two>
TextNode <#text>
TextNode <#text>
InlineNode <span.three>
TextNode <#text>
TextNode <#text>
InlineNode <span.four>
TextNode <#text>
TextNode <#text>

View file

@ -0,0 +1,10 @@
<!doctype html><style>
.one { font: normal 200px/1 SerenitySans; }
.two { font: normal normal 200px/1 SerenitySans; }
.three { font: normal normal normal 200px/1 SerenitySans; }
.four { font: normal normal normal normal 200px/1 SerenitySans; }
</style>
<span class=one>1</span>
<span class=two>2</span>
<span class=three>3</span>
<span class=four>4</span>

View file

@ -6587,7 +6587,7 @@ ErrorOr<RefPtr<StyleValue>> Parser::parse_font_value(Vector<ComponentValue> 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;