1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 15:18:11 +00:00

LibWeb: Parse font-stretch CSS property

This commit is contained in:
Aliaksandr Kalenik 2023-02-03 14:27:09 +03:00 committed by Sam Atkins
parent 968481c7cd
commit ab99e95549
5 changed files with 47 additions and 7 deletions

View file

@ -85,6 +85,7 @@
"collapse",
"column",
"column-reverse",
"condensed",
"contain",
"content",
"content-box",
@ -111,6 +112,9 @@
"enabled",
"end",
"ew-resize",
"expanded",
"extra-condensed",
"extra-expanded",
"fantasy",
"fast",
"fine",
@ -235,6 +239,8 @@
"se-resize",
"self-end",
"self-start",
"semi-condensed",
"semi-expanded",
"separate",
"serif",
"slow",
@ -282,6 +288,8 @@
"ui-rounded",
"ui-sans-serif",
"ui-serif",
"ultra-condensed",
"ultra-expanded",
"underline",
"unsafe",
"upper-alpha",

View file

@ -5123,13 +5123,13 @@ static bool is_generic_font_family(ValueID identifier)
RefPtr<StyleValue> Parser::parse_font_value(Vector<ComponentValue> const& component_values)
{
RefPtr<StyleValue> font_stretch;
RefPtr<StyleValue> font_style;
RefPtr<StyleValue> font_weight;
RefPtr<StyleValue> font_size;
RefPtr<StyleValue> line_height;
RefPtr<StyleValue> font_families;
RefPtr<StyleValue> font_variant;
// FIXME: Implement font-stretch.
// FIXME: Handle system fonts. (caption, icon, menu, message-box, small-caption, status-bar)
@ -5189,6 +5189,12 @@ RefPtr<StyleValue> Parser::parse_font_value(Vector<ComponentValue> const& compon
font_families = maybe_font_families.release_nonnull();
break;
}
if (property_accepts_value(PropertyID::FontStretch, *value)) {
if (font_stretch)
return nullptr;
font_stretch = value.release_nonnull();
continue;
}
return nullptr;
}
@ -5202,6 +5208,8 @@ RefPtr<StyleValue> Parser::parse_font_value(Vector<ComponentValue> const& compon
if (!font_size || !font_families)
return nullptr;
if (!font_stretch)
font_stretch = property_initial_value(PropertyID::FontStretch);
if (!font_style)
font_style = property_initial_value(PropertyID::FontStyle);
if (!font_weight)
@ -5209,7 +5217,7 @@ RefPtr<StyleValue> Parser::parse_font_value(Vector<ComponentValue> const& compon
if (!line_height)
line_height = property_initial_value(PropertyID::LineHeight);
return FontStyleValue::create(font_style.release_nonnull(), font_weight.release_nonnull(), font_size.release_nonnull(), line_height.release_nonnull(), font_families.release_nonnull());
return FontStyleValue::create(font_stretch.release_nonnull(), font_style.release_nonnull(), font_weight.release_nonnull(), font_size.release_nonnull(), line_height.release_nonnull(), font_families.release_nonnull());
}
RefPtr<StyleValue> Parser::parse_font_family_value(Vector<ComponentValue> const& component_values, size_t start_index)

View file

@ -692,6 +692,24 @@
"unitless-length"
]
},
"font-stretch": {
"inherited": true,
"initial": "normal",
"valid-types": [
"percentage [0,∞]"
],
"valid-identifiers": [
"normal",
"ultra-condensed",
"extra-condensed",
"condensed",
"semi-condensed",
"semi-expanded",
"expanded",
"extra-expanded",
"ultra-expanded"
]
},
"font-style": {
"inherited": true,
"initial": "normal",

View file

@ -476,19 +476,21 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
auto const& font_shorthand = value.as_font();
style.set_property(CSS::PropertyID::FontSize, font_shorthand.font_size());
style.set_property(CSS::PropertyID::FontFamily, font_shorthand.font_families());
style.set_property(CSS::PropertyID::FontStretch, font_shorthand.font_stretch());
style.set_property(CSS::PropertyID::FontStyle, font_shorthand.font_style());
style.set_property(CSS::PropertyID::FontWeight, font_shorthand.font_weight());
style.set_property(CSS::PropertyID::LineHeight, font_shorthand.line_height());
// FIXME: Implement font-stretch and font-variant
// FIXME: Implement font-variant
return;
}
style.set_property(CSS::PropertyID::FontStretch, value);
style.set_property(CSS::PropertyID::FontSize, value);
style.set_property(CSS::PropertyID::FontFamily, value);
style.set_property(CSS::PropertyID::FontStyle, value);
style.set_property(CSS::PropertyID::FontWeight, value);
style.set_property(CSS::PropertyID::LineHeight, value);
// FIXME: Implement font-stretch and font-variant
// FIXME: Implement font-variant
return;
}
@ -986,6 +988,7 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele
// FIXME: This should be more sophisticated.
compute_defaulted_property_value(style, element, CSS::PropertyID::FontFamily, pseudo_element);
compute_defaulted_property_value(style, element, CSS::PropertyID::FontSize, pseudo_element);
compute_defaulted_property_value(style, element, CSS::PropertyID::FontStretch, pseudo_element);
compute_defaulted_property_value(style, element, CSS::PropertyID::FontStyle, pseudo_element);
compute_defaulted_property_value(style, element, CSS::PropertyID::FontWeight, pseudo_element);

View file

@ -1006,9 +1006,10 @@ private:
class FontStyleValue final : public StyleValue {
public:
static NonnullRefPtr<FontStyleValue> create(NonnullRefPtr<StyleValue> font_style, NonnullRefPtr<StyleValue> font_weight, NonnullRefPtr<StyleValue> font_size, NonnullRefPtr<StyleValue> line_height, NonnullRefPtr<StyleValue> font_families) { return adopt_ref(*new FontStyleValue(font_style, font_weight, font_size, line_height, font_families)); }
static NonnullRefPtr<FontStyleValue> create(NonnullRefPtr<StyleValue> font_stretch, NonnullRefPtr<StyleValue> font_style, NonnullRefPtr<StyleValue> font_weight, NonnullRefPtr<StyleValue> font_size, NonnullRefPtr<StyleValue> line_height, NonnullRefPtr<StyleValue> font_families) { return adopt_ref(*new FontStyleValue(font_stretch, font_style, font_weight, font_size, line_height, font_families)); }
virtual ~FontStyleValue() override = default;
NonnullRefPtr<StyleValue> font_stretch() const { return m_font_stretch; }
NonnullRefPtr<StyleValue> font_style() const { return m_font_style; }
NonnullRefPtr<StyleValue> font_weight() const { return m_font_weight; }
NonnullRefPtr<StyleValue> font_size() const { return m_font_size; }
@ -1019,8 +1020,9 @@ public:
virtual bool equals(StyleValue const& other) const override;
private:
FontStyleValue(NonnullRefPtr<StyleValue> font_style, NonnullRefPtr<StyleValue> font_weight, NonnullRefPtr<StyleValue> font_size, NonnullRefPtr<StyleValue> line_height, NonnullRefPtr<StyleValue> font_families)
FontStyleValue(NonnullRefPtr<StyleValue> font_stretch, NonnullRefPtr<StyleValue> font_style, NonnullRefPtr<StyleValue> font_weight, NonnullRefPtr<StyleValue> font_size, NonnullRefPtr<StyleValue> line_height, NonnullRefPtr<StyleValue> font_families)
: StyleValue(Type::Font)
, m_font_stretch(font_stretch)
, m_font_style(font_style)
, m_font_weight(font_weight)
, m_font_size(font_size)
@ -1029,12 +1031,13 @@ private:
{
}
NonnullRefPtr<StyleValue> m_font_stretch;
NonnullRefPtr<StyleValue> m_font_style;
NonnullRefPtr<StyleValue> m_font_weight;
NonnullRefPtr<StyleValue> m_font_size;
NonnullRefPtr<StyleValue> m_line_height;
NonnullRefPtr<StyleValue> m_font_families;
// FIXME: Implement font-stretch and font-variant.
// FIXME: Implement font-variant.
};
class FrequencyStyleValue : public StyleValue {