-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LibWeb: Improve parsing and serialization of some font properties #3482
Open
AtkinsSJ
wants to merge
8
commits into
LadybirdBrowser:master
Choose a base branch
from
AtkinsSJ:fonts
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+6,514
−609
Open
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7becbea
LibWeb/CSS: Make `font` implicitly reset some properties
AtkinsSJ 633a255
Tests: Import some font-parsing tests
AtkinsSJ 7b10fa6
LibWeb/CSS: Serialize font property more correctly
AtkinsSJ 9fc9756
LibWeb/CSS: Support nested shorthands in CSSStyleDeclaration
AtkinsSJ 5ed4591
LibWeb/CSS: Reject trailing unparseable tokens in property values
AtkinsSJ 056e825
LibWeb/CSS: Parse font-variant properties closer to spec
AtkinsSJ 86ab513
LibWeb/CSS: Serialize font-variant property closer to spec
AtkinsSJ 2eb8c59
LibWeb/CSS: Inline CSSStyleValue::to_font_variant_foo() methods
AtkinsSJ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
/* | ||
* Copyright (c) 2023, Ali Mohammad Pur <[email protected]> | ||
* Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org> | ||
* Copyright (c) 2023-2025, Sam Atkins <sam@ladybird.org> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
||
#include "ShorthandStyleValue.h" | ||
#include <LibGfx/Font/FontWeight.h> | ||
#include <LibWeb/CSS/PropertyID.h> | ||
#include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h> | ||
#include <LibWeb/CSS/StyleValues/CSSKeywordValue.h> | ||
|
@@ -165,15 +166,36 @@ String ShorthandStyleValue::to_string(SerializationMode mode) const | |
return MUST(String::formatted("{} {} {}", longhand(PropertyID::FlexGrow)->to_string(mode), longhand(PropertyID::FlexShrink)->to_string(mode), longhand(PropertyID::FlexBasis)->to_string(mode))); | ||
case PropertyID::FlexFlow: | ||
return MUST(String::formatted("{} {}", longhand(PropertyID::FlexDirection)->to_string(mode), longhand(PropertyID::FlexWrap)->to_string(mode))); | ||
case PropertyID::Font: | ||
return MUST(String::formatted("{} {} {} {} {} / {} {}", | ||
longhand(PropertyID::FontStyle)->to_string(mode), | ||
longhand(PropertyID::FontVariant)->to_string(mode), | ||
longhand(PropertyID::FontWeight)->to_string(mode), | ||
longhand(PropertyID::FontWidth)->to_string(mode), | ||
longhand(PropertyID::FontSize)->to_string(mode), | ||
longhand(PropertyID::LineHeight)->to_string(mode), | ||
longhand(PropertyID::FontFamily)->to_string(mode))); | ||
case PropertyID::Font: { | ||
auto font_style = longhand(PropertyID::FontStyle); | ||
auto font_variant = longhand(PropertyID::FontVariant); | ||
auto font_weight = longhand(PropertyID::FontWeight); | ||
auto font_width = longhand(PropertyID::FontWidth); | ||
auto font_size = longhand(PropertyID::FontSize); | ||
auto line_height = longhand(PropertyID::LineHeight); | ||
auto font_family = longhand(PropertyID::FontFamily); | ||
|
||
StringBuilder builder; | ||
auto append = [&](auto const& string) { | ||
if (!builder.is_empty()) | ||
builder.append(' '); | ||
builder.append(string); | ||
}; | ||
if (font_style->to_keyword() != Keyword::Normal && font_style->to_keyword() != Keyword::Initial) | ||
append(font_style->to_string(mode)); | ||
if (auto variant_string = font_variant->to_string(mode); variant_string != "normal"sv && variant_string != "initial"sv) | ||
append(variant_string); | ||
if (font_weight->to_font_weight() != Gfx::FontWeight::Regular && font_weight->to_keyword() != Keyword::Initial) | ||
append(font_weight->to_string(mode)); | ||
if (font_width->to_keyword() != Keyword::Normal && font_width->to_keyword() != Keyword::Initial) | ||
append(font_width->to_string(mode)); | ||
append(font_size->to_string(mode)); | ||
if (line_height->to_keyword() != Keyword::Normal && line_height->to_keyword() != Keyword::Initial) | ||
append(MUST(String::formatted("/ {}", line_height->to_string(mode)))); | ||
append(font_family->to_string(mode)); | ||
|
||
return builder.to_string_without_validation(); | ||
} | ||
case PropertyID::FontVariant: { | ||
Vector<StringView> values; | ||
auto ligatures_or_null = longhand(PropertyID::FontVariantLigatures)->to_font_variant_ligatures(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
Tests/LibWeb/Text/expected/css/font-implicitly-reset-properties.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
font-feature-settings: normal | ||
font-kerning: undefined | ||
font-language-override: normal | ||
font-optical-sizing: undefined | ||
font-size-adjust: undefined | ||
font-variant-alternates: normal | ||
font-variant-caps: normal | ||
font-variant-east-asian: normal | ||
font-variant-emoji: normal | ||
font-variant-ligatures: normal | ||
font-variant-numeric: normal | ||
font-variant-position: normal | ||
font-variation-settings: normal |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this part includes too many font-variant properties, since https://drafts.csswg.org/css-fonts/#font-prop mentions:
Values for the font-variant property can also be included but only those supported in CSS 2.1; none of the font-variant values added in CSS Fonts Levels 3 or 4 can be used in the font shorthand
[<font-variant-css2>] = normal || small-caps
Perhaps a FIXME at least?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah good catch! I'll take a look.