Skip to content

Commit

Permalink
LibWeb: Support CSS font shorthand with up to 4 consecutive normal
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
awesomekling committed Jul 4, 2023
1 parent f33baa3 commit a5b1c50
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
30 changes: 30 additions & 0 deletions Tests/LibWeb/Layout/expected/font-with-many-normal-values.txt
Original file line number Diff line number Diff line change
@@ -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>
10 changes: 10 additions & 0 deletions Tests/LibWeb/Layout/input/font-with-many-normal-values.html
Original file line number Diff line number Diff line change
@@ -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>
2 changes: 1 addition & 1 deletion Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit a5b1c50

Please sign in to comment.