1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 17:08:12 +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", "collapse",
"column", "column",
"column-reverse", "column-reverse",
"condensed",
"contain", "contain",
"content", "content",
"content-box", "content-box",
@ -111,6 +112,9 @@
"enabled", "enabled",
"end", "end",
"ew-resize", "ew-resize",
"expanded",
"extra-condensed",
"extra-expanded",
"fantasy", "fantasy",
"fast", "fast",
"fine", "fine",
@ -235,6 +239,8 @@
"se-resize", "se-resize",
"self-end", "self-end",
"self-start", "self-start",
"semi-condensed",
"semi-expanded",
"separate", "separate",
"serif", "serif",
"slow", "slow",
@ -282,6 +288,8 @@
"ui-rounded", "ui-rounded",
"ui-sans-serif", "ui-sans-serif",
"ui-serif", "ui-serif",
"ultra-condensed",
"ultra-expanded",
"underline", "underline",
"unsafe", "unsafe",
"upper-alpha", "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> Parser::parse_font_value(Vector<ComponentValue> const& component_values)
{ {
RefPtr<StyleValue> font_stretch;
RefPtr<StyleValue> font_style; RefPtr<StyleValue> font_style;
RefPtr<StyleValue> font_weight; RefPtr<StyleValue> font_weight;
RefPtr<StyleValue> font_size; RefPtr<StyleValue> font_size;
RefPtr<StyleValue> line_height; RefPtr<StyleValue> line_height;
RefPtr<StyleValue> font_families; RefPtr<StyleValue> font_families;
RefPtr<StyleValue> font_variant; RefPtr<StyleValue> font_variant;
// FIXME: Implement font-stretch.
// FIXME: Handle system fonts. (caption, icon, menu, message-box, small-caption, status-bar) // 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(); font_families = maybe_font_families.release_nonnull();
break; break;
} }
if (property_accepts_value(PropertyID::FontStretch, *value)) {
if (font_stretch)
return nullptr;
font_stretch = value.release_nonnull();
continue;
}
return nullptr; return nullptr;
} }
@ -5202,6 +5208,8 @@ RefPtr<StyleValue> Parser::parse_font_value(Vector<ComponentValue> const& compon
if (!font_size || !font_families) if (!font_size || !font_families)
return nullptr; return nullptr;
if (!font_stretch)
font_stretch = property_initial_value(PropertyID::FontStretch);
if (!font_style) if (!font_style)
font_style = property_initial_value(PropertyID::FontStyle); font_style = property_initial_value(PropertyID::FontStyle);
if (!font_weight) if (!font_weight)
@ -5209,7 +5217,7 @@ RefPtr<StyleValue> Parser::parse_font_value(Vector<ComponentValue> const& compon
if (!line_height) if (!line_height)
line_height = property_initial_value(PropertyID::LineHeight); 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) RefPtr<StyleValue> Parser::parse_font_family_value(Vector<ComponentValue> const& component_values, size_t start_index)

View file

@ -692,6 +692,24 @@
"unitless-length" "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": { "font-style": {
"inherited": true, "inherited": true,
"initial": "normal", "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(); auto const& font_shorthand = value.as_font();
style.set_property(CSS::PropertyID::FontSize, font_shorthand.font_size()); 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::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::FontStyle, font_shorthand.font_style());
style.set_property(CSS::PropertyID::FontWeight, font_shorthand.font_weight()); style.set_property(CSS::PropertyID::FontWeight, font_shorthand.font_weight());
style.set_property(CSS::PropertyID::LineHeight, font_shorthand.line_height()); style.set_property(CSS::PropertyID::LineHeight, font_shorthand.line_height());
// FIXME: Implement font-stretch and font-variant // FIXME: Implement font-variant
return; return;
} }
style.set_property(CSS::PropertyID::FontStretch, value);
style.set_property(CSS::PropertyID::FontSize, value); style.set_property(CSS::PropertyID::FontSize, value);
style.set_property(CSS::PropertyID::FontFamily, value); style.set_property(CSS::PropertyID::FontFamily, value);
style.set_property(CSS::PropertyID::FontStyle, value); style.set_property(CSS::PropertyID::FontStyle, value);
style.set_property(CSS::PropertyID::FontWeight, value); style.set_property(CSS::PropertyID::FontWeight, value);
style.set_property(CSS::PropertyID::LineHeight, value); style.set_property(CSS::PropertyID::LineHeight, value);
// FIXME: Implement font-stretch and font-variant // FIXME: Implement font-variant
return; return;
} }
@ -986,6 +988,7 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele
// FIXME: This should be more sophisticated. // 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::FontFamily, pseudo_element);
compute_defaulted_property_value(style, element, CSS::PropertyID::FontSize, 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::FontStyle, pseudo_element);
compute_defaulted_property_value(style, element, CSS::PropertyID::FontWeight, 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 { class FontStyleValue final : public StyleValue {
public: 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; 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_style() const { return m_font_style; }
NonnullRefPtr<StyleValue> font_weight() const { return m_font_weight; } NonnullRefPtr<StyleValue> font_weight() const { return m_font_weight; }
NonnullRefPtr<StyleValue> font_size() const { return m_font_size; } NonnullRefPtr<StyleValue> font_size() const { return m_font_size; }
@ -1019,8 +1020,9 @@ public:
virtual bool equals(StyleValue const& other) const override; virtual bool equals(StyleValue const& other) const override;
private: 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) : StyleValue(Type::Font)
, m_font_stretch(font_stretch)
, m_font_style(font_style) , m_font_style(font_style)
, m_font_weight(font_weight) , m_font_weight(font_weight)
, m_font_size(font_size) , m_font_size(font_size)
@ -1029,12 +1031,13 @@ private:
{ {
} }
NonnullRefPtr<StyleValue> m_font_stretch;
NonnullRefPtr<StyleValue> m_font_style; NonnullRefPtr<StyleValue> m_font_style;
NonnullRefPtr<StyleValue> m_font_weight; NonnullRefPtr<StyleValue> m_font_weight;
NonnullRefPtr<StyleValue> m_font_size; NonnullRefPtr<StyleValue> m_font_size;
NonnullRefPtr<StyleValue> m_line_height; NonnullRefPtr<StyleValue> m_line_height;
NonnullRefPtr<StyleValue> m_font_families; NonnullRefPtr<StyleValue> m_font_families;
// FIXME: Implement font-stretch and font-variant. // FIXME: Implement font-variant.
}; };
class FrequencyStyleValue : public StyleValue { class FrequencyStyleValue : public StyleValue {