mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibWeb/CSS: Make font-stretch a legacy alias for new font-width
CSS Fonts level 4 renames font-stretch to font-width, with font-stretch being left as a legacy alias. Unfortunately the other specs have not yet been updated, so both terms are used in different places.
This commit is contained in:
parent
7c50a31402
commit
4a67b28600
Notes:
github-actions[bot]
2024-09-28 12:43:39 +00:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/LadybirdBrowser/ladybird/commit/4a67b286004 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1554
10 changed files with 47 additions and 41 deletions
|
@ -12,10 +12,10 @@ fill-opacity: 1
|
|||
fill-rule: nonzero
|
||||
font-family: serif
|
||||
font-size: 16px
|
||||
font-stretch: normal
|
||||
font-style: normal
|
||||
font-variant: normal
|
||||
font-weight: 400
|
||||
font-width: normal
|
||||
image-rendering: auto
|
||||
letter-spacing: normal
|
||||
line-height: normal
|
||||
|
|
|
@ -407,7 +407,7 @@ int CSSStyleValue::to_font_slope() const
|
|||
return normal_slope;
|
||||
}
|
||||
|
||||
int CSSStyleValue::to_font_stretch_width() const
|
||||
int CSSStyleValue::to_font_width() const
|
||||
{
|
||||
int width = Gfx::FontWidth::Normal;
|
||||
if (is_keyword()) {
|
||||
|
|
|
@ -344,7 +344,7 @@ public:
|
|||
|
||||
[[nodiscard]] int to_font_weight() const;
|
||||
[[nodiscard]] int to_font_slope() const;
|
||||
[[nodiscard]] int to_font_stretch_width() const;
|
||||
[[nodiscard]] int to_font_width() const;
|
||||
|
||||
virtual bool equals(CSSStyleValue const& other) const = 0;
|
||||
|
||||
|
|
|
@ -223,6 +223,17 @@
|
|||
"normal",
|
||||
"small-caps"
|
||||
],
|
||||
"font-width": [
|
||||
"ultra-condensed",
|
||||
"extra-condensed",
|
||||
"condensed",
|
||||
"semi-condensed",
|
||||
"normal",
|
||||
"semi-expanded",
|
||||
"expanded",
|
||||
"extra-expanded",
|
||||
"ultra-expanded"
|
||||
],
|
||||
"image-rendering": [
|
||||
"auto",
|
||||
"crisp-edges",
|
||||
|
|
|
@ -261,12 +261,13 @@ WebIDL::ExceptionOr<void> FontFace::set_weight(String const& string)
|
|||
// https://drafts.csswg.org/css-font-loading/#dom-fontface-stretch
|
||||
WebIDL::ExceptionOr<void> FontFace::set_stretch(String const& string)
|
||||
{
|
||||
auto property = parse_property_string<CSS::PropertyID::FontStretch>(realm(), string);
|
||||
// NOTE: font-stretch is now an alias for font-width
|
||||
auto property = parse_property_string<CSS::PropertyID::FontWidth>(realm(), string);
|
||||
if (!property)
|
||||
return WebIDL::SyntaxError::create(realm(), "FontFace.stretch setter: Invalid font descriptor"_fly_string);
|
||||
|
||||
if (m_is_css_connected) {
|
||||
// FIXME: Propagate to the CSSFontFaceRule and update the font-stretch property
|
||||
// FIXME: Propagate to the CSSFontFaceRule and update the font-width property
|
||||
}
|
||||
|
||||
m_stretch = property->to_string();
|
||||
|
|
|
@ -5261,7 +5261,7 @@ static bool is_generic_font_family(Keyword keyword)
|
|||
|
||||
RefPtr<CSSStyleValue> Parser::parse_font_value(TokenStream<ComponentValue>& tokens)
|
||||
{
|
||||
RefPtr<CSSStyleValue> font_stretch;
|
||||
RefPtr<CSSStyleValue> font_width;
|
||||
RefPtr<CSSStyleValue> font_style;
|
||||
RefPtr<CSSStyleValue> font_weight;
|
||||
RefPtr<CSSStyleValue> font_size;
|
||||
|
@ -5275,7 +5275,9 @@ RefPtr<CSSStyleValue> Parser::parse_font_value(TokenStream<ComponentValue>& toke
|
|||
// So, we have to handle that separately.
|
||||
int normal_count = 0;
|
||||
|
||||
auto remaining_longhands = Vector { PropertyID::FontSize, PropertyID::FontStretch, PropertyID::FontStyle, PropertyID::FontVariant, PropertyID::FontWeight };
|
||||
// FIXME: `font-variant` allows a lot of different values which aren't allowed in the `font` shorthand.
|
||||
// FIXME: `font-width` allows <percentage> values, which aren't allowed in the `font` shorthand.
|
||||
auto remaining_longhands = Vector { PropertyID::FontSize, PropertyID::FontStyle, PropertyID::FontVariant, PropertyID::FontWeight, PropertyID::FontWidth };
|
||||
auto transaction = tokens.begin_transaction();
|
||||
|
||||
while (tokens.has_next_token()) {
|
||||
|
@ -5314,13 +5316,12 @@ RefPtr<CSSStyleValue> Parser::parse_font_value(TokenStream<ComponentValue>& toke
|
|||
font_families = maybe_font_families.release_nonnull();
|
||||
continue;
|
||||
}
|
||||
case PropertyID::FontStretch: {
|
||||
VERIFY(!font_stretch);
|
||||
font_stretch = value.release_nonnull();
|
||||
case PropertyID::FontWidth: {
|
||||
VERIFY(!font_width);
|
||||
font_width = value.release_nonnull();
|
||||
continue;
|
||||
}
|
||||
case PropertyID::FontStyle: {
|
||||
// FIXME: Handle angle parameter to `oblique`: https://www.w3.org/TR/css-fonts-4/#font-style-prop
|
||||
VERIFY(!font_style);
|
||||
font_style = value.release_nonnull();
|
||||
continue;
|
||||
|
@ -5345,7 +5346,7 @@ RefPtr<CSSStyleValue> Parser::parse_font_value(TokenStream<ComponentValue>& toke
|
|||
// 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 ShorthandStyleValue 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) + (font_variant ? 0 : 1) + (font_stretch ? 0 : 1);
|
||||
int unset_value_count = (font_style ? 0 : 1) + (font_weight ? 0 : 1) + (font_variant ? 0 : 1) + (font_width ? 0 : 1);
|
||||
if (unset_value_count < normal_count)
|
||||
return nullptr;
|
||||
|
||||
|
@ -5358,15 +5359,15 @@ RefPtr<CSSStyleValue> Parser::parse_font_value(TokenStream<ComponentValue>& toke
|
|||
font_variant = property_initial_value(m_context.realm(), PropertyID::FontVariant);
|
||||
if (!font_weight)
|
||||
font_weight = property_initial_value(m_context.realm(), PropertyID::FontWeight);
|
||||
if (!font_stretch)
|
||||
font_stretch = property_initial_value(m_context.realm(), PropertyID::FontStretch);
|
||||
if (!font_width)
|
||||
font_width = property_initial_value(m_context.realm(), PropertyID::FontWidth);
|
||||
if (!line_height)
|
||||
line_height = property_initial_value(m_context.realm(), PropertyID::LineHeight);
|
||||
|
||||
transaction.commit();
|
||||
return ShorthandStyleValue::create(PropertyID::Font,
|
||||
{ PropertyID::FontStyle, PropertyID::FontVariant, PropertyID::FontWeight, PropertyID::FontStretch, PropertyID::FontSize, PropertyID::LineHeight, PropertyID::FontFamily },
|
||||
{ font_style.release_nonnull(), font_variant.release_nonnull(), font_weight.release_nonnull(), font_stretch.release_nonnull(), font_size.release_nonnull(), line_height.release_nonnull(), font_families.release_nonnull() });
|
||||
{ PropertyID::FontStyle, PropertyID::FontVariant, PropertyID::FontWeight, PropertyID::FontWidth, PropertyID::FontSize, PropertyID::LineHeight, PropertyID::FontFamily },
|
||||
{ font_style.release_nonnull(), font_variant.release_nonnull(), font_weight.release_nonnull(), font_width.release_nonnull(), font_size.release_nonnull(), line_height.release_nonnull(), font_families.release_nonnull() });
|
||||
}
|
||||
|
||||
RefPtr<CSSStyleValue> Parser::parse_font_family_value(TokenStream<ComponentValue>& tokens)
|
||||
|
|
|
@ -1148,7 +1148,7 @@
|
|||
"longhands": [
|
||||
"font-family",
|
||||
"font-size",
|
||||
"font-stretch",
|
||||
"font-width",
|
||||
"font-style",
|
||||
"font-variant",
|
||||
"font-weight",
|
||||
|
@ -1191,23 +1191,7 @@
|
|||
]
|
||||
},
|
||||
"font-stretch": {
|
||||
"animation-type": "custom",
|
||||
"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"
|
||||
]
|
||||
"legacy-alias-for": "font-width"
|
||||
},
|
||||
"font-style": {
|
||||
"animation-type": "custom",
|
||||
|
@ -1241,6 +1225,15 @@
|
|||
"normal"
|
||||
]
|
||||
},
|
||||
"font-width": {
|
||||
"animation-type": "by-computed-value",
|
||||
"inherited": true,
|
||||
"initial": "normal",
|
||||
"valid-types": [
|
||||
"percentage [0,∞]",
|
||||
"font-width"
|
||||
]
|
||||
},
|
||||
"gap": {
|
||||
"inherited": false,
|
||||
"initial": "auto",
|
||||
|
|
|
@ -1791,7 +1791,7 @@ RefPtr<Gfx::FontCascadeList const> StyleComputer::compute_font_for_style_values(
|
|||
{
|
||||
auto* parent_element = element_to_inherit_style_from(element, pseudo_element);
|
||||
|
||||
auto width = font_stretch.to_font_stretch_width();
|
||||
auto width = font_stretch.to_font_width();
|
||||
|
||||
auto weight = font_weight.to_font_weight();
|
||||
bool bold = weight > Gfx::FontWeight::Regular;
|
||||
|
@ -2043,7 +2043,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::FontWidth, 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::LineHeight, pseudo_element);
|
||||
|
@ -2052,9 +2052,9 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele
|
|||
auto font_size = style.property(CSS::PropertyID::FontSize);
|
||||
auto font_style = style.property(CSS::PropertyID::FontStyle);
|
||||
auto font_weight = style.property(CSS::PropertyID::FontWeight);
|
||||
auto font_stretch = style.property(CSS::PropertyID::FontStretch);
|
||||
auto font_width = style.property(CSS::PropertyID::FontWidth);
|
||||
|
||||
auto font_list = compute_font_for_style_values(element, pseudo_element, font_family, font_size, font_style, font_weight, font_stretch, style.math_depth());
|
||||
auto font_list = compute_font_for_style_values(element, pseudo_element, font_family, font_size, font_style, font_weight, font_width, style.math_depth());
|
||||
VERIFY(font_list);
|
||||
VERIFY(!font_list->is_empty());
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ String ShorthandStyleValue::to_string() const
|
|||
longhand(PropertyID::FontStyle)->to_string(),
|
||||
longhand(PropertyID::FontVariant)->to_string(),
|
||||
longhand(PropertyID::FontWeight)->to_string(),
|
||||
longhand(PropertyID::FontStretch)->to_string(),
|
||||
longhand(PropertyID::FontWidth)->to_string(),
|
||||
longhand(PropertyID::FontSize)->to_string(),
|
||||
longhand(PropertyID::LineHeight)->to_string(),
|
||||
longhand(PropertyID::FontFamily)->to_string()));
|
||||
|
|
|
@ -58,10 +58,10 @@ public:
|
|||
auto& canvas_element = reinterpret_cast<IncludingClass&>(*this).canvas_element();
|
||||
auto& font_style = *font_style_value.longhand(CSS::PropertyID::FontStyle);
|
||||
auto& font_weight = *font_style_value.longhand(CSS::PropertyID::FontWeight);
|
||||
auto& font_stretch = *font_style_value.longhand(CSS::PropertyID::FontStretch);
|
||||
auto& font_width = *font_style_value.longhand(CSS::PropertyID::FontWidth);
|
||||
auto& font_size = *font_style_value.longhand(CSS::PropertyID::FontSize);
|
||||
auto& font_family = *font_style_value.longhand(CSS::PropertyID::FontFamily);
|
||||
auto font_list = canvas_element.document().style_computer().compute_font_for_style_values(&canvas_element, {}, font_family, font_size, font_style, font_weight, font_stretch);
|
||||
auto font_list = canvas_element.document().style_computer().compute_font_for_style_values(&canvas_element, {}, font_family, font_size, font_style, font_weight, font_width);
|
||||
my_drawing_state().current_font = font_list->first();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue