LibWeb/CSS: Implement the font-kerning property

This sets whether the kerning information stored on the current font is
used.
This commit is contained in:
Tim Ledbetter 2025-06-22 18:59:42 +01:00 committed by Sam Atkins
commit 9b6da84fff
Notes: github-actions[bot] 2025-06-23 12:28:02 +00:00
17 changed files with 108 additions and 20 deletions

View file

@ -1252,6 +1252,12 @@ Variant<VerticalAlign, LengthPercentage> ComputedProperties::vertical_align() co
VERIFY_NOT_REACHED();
}
FontKerning ComputedProperties::font_kerning() const
{
auto const& value = property(PropertyID::FontKerning);
return keyword_to_font_kerning(value.to_keyword()).release_value();
}
Optional<FlyString> ComputedProperties::font_language_override() const
{
auto const& value = property(PropertyID::FontLanguageOverride);

View file

@ -146,6 +146,7 @@ public:
Optional<Gfx::FontVariantLigatures> font_variant_ligatures() const;
Optional<Gfx::FontVariantNumeric> font_variant_numeric() const;
FontVariantPosition font_variant_position() const;
FontKerning font_kerning() const;
Optional<FlyString> font_language_override() const;
Optional<HashMap<FlyString, IntegerOrCalculated>> font_feature_settings() const;
Optional<HashMap<FlyString, NumberOrCalculated>> font_variation_settings() const;

View file

@ -94,6 +94,7 @@ class InitialValues {
public:
static AspectRatio aspect_ratio() { return AspectRatio { true, {} }; }
static CSSPixels font_size() { return 16; }
static FontKerning font_kerning() { return FontKerning::Auto; }
static int font_weight() { return 400; }
static CSSPixels line_height() { return 0; }
static CSS::Float float_() { return CSS::Float::None; }
@ -577,6 +578,7 @@ public:
Optional<Gfx::FontVariantLigatures> font_variant_ligatures() const { return m_inherited.font_variant_ligatures; }
Optional<Gfx::FontVariantNumeric> font_variant_numeric() const { return m_inherited.font_variant_numeric; }
FontVariantPosition font_variant_position() const { return m_inherited.font_variant_position; }
FontKerning font_kerning() const { return m_inherited.font_kerning; }
Optional<FlyString> font_language_override() const { return m_inherited.font_language_override; }
Optional<HashMap<FlyString, IntegerOrCalculated>> font_feature_settings() const { return m_inherited.font_feature_settings; }
Optional<HashMap<FlyString, NumberOrCalculated>> font_variation_settings() const { return m_inherited.font_variation_settings; }
@ -619,6 +621,7 @@ protected:
Optional<Gfx::FontVariantLigatures> font_variant_ligatures;
Optional<Gfx::FontVariantNumeric> font_variant_numeric;
FontVariantPosition font_variant_position { FontVariantPosition::Normal };
FontKerning font_kerning { InitialValues::font_kerning() };
Optional<FlyString> font_language_override;
Optional<HashMap<FlyString, IntegerOrCalculated>> font_feature_settings;
Optional<HashMap<FlyString, NumberOrCalculated>> font_variation_settings;
@ -815,6 +818,7 @@ public:
void set_font_variant_ligatures(Optional<Gfx::FontVariantLigatures> font_variant_ligatures) { m_inherited.font_variant_ligatures = font_variant_ligatures; }
void set_font_variant_numeric(Optional<Gfx::FontVariantNumeric> font_variant_numeric) { m_inherited.font_variant_numeric = font_variant_numeric; }
void set_font_variant_position(FontVariantPosition font_variant_position) { m_inherited.font_variant_position = font_variant_position; }
void set_font_kerning(FontKerning font_kerning) { m_inherited.font_kerning = font_kerning; }
void set_font_language_override(Optional<FlyString> font_language_override) { m_inherited.font_language_override = font_language_override; }
void set_font_feature_settings(Optional<HashMap<FlyString, IntegerOrCalculated>> value) { m_inherited.font_feature_settings = move(value); }
void set_font_variation_settings(Optional<HashMap<FlyString, NumberOrCalculated>> value) { m_inherited.font_variation_settings = move(value); }

View file

@ -257,6 +257,11 @@
"fallback",
"optional"
],
"font-kerning": [
"auto",
"normal",
"none"
],
"font-style": [
"normal",
"italic",

View file

@ -2543,7 +2543,7 @@ RefPtr<CSSStyleValue const> Parser::parse_font_value(TokenStream<ComponentValue>
// Reset implicitly https://drafts.csswg.org/css-fonts/#reset-implicitly
PropertyID::FontFeatureSettings,
// FIXME: PropertyID::FontKerning,
PropertyID::FontKerning,
PropertyID::FontLanguageOverride,
// FIXME: PropertyID::FontOpticalSizing,
// FIXME: PropertyID::FontSizeAdjust,
@ -2560,12 +2560,12 @@ RefPtr<CSSStyleValue const> Parser::parse_font_value(TokenStream<ComponentValue>
line_height.release_nonnull(),
// Reset implicitly
initial_value, // font-feature-settings
// FIXME: font-kerning,
initial_value, // font-language-override
// FIXME: font-optical-sizing,
// FIXME: font-size-adjust,
initial_value, // font-variation-settings
initial_value, // font-feature-settings
property_initial_value(PropertyID::FontKerning), // font-kerning,
initial_value, // font-language-override
// FIXME: font-optical-sizing,
// FIXME: font-size-adjust,
initial_value, // font-variation-settings
});
}

View file

@ -1425,6 +1425,14 @@
"off"
]
},
"font-kerning": {
"animation-type": "discrete",
"inherited": true,
"initial": "auto",
"valid-types": [
"font-kerning"
]
},
"font-language-override": {
"animation-type": "discrete",
"inherited": true,