Skip to content

Commit f9452b7

Browse files
tcl3AtkinsSJ
authored andcommitted
LibWeb: Implement interpolation of font-variation-settings values
1 parent 83ad5ce commit f9452b7

File tree

3 files changed

+551
-0
lines changed

3 files changed

+551
-0
lines changed

Libraries/LibWeb/CSS/Interpolation.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <LibWeb/CSS/StyleValues/KeywordStyleValue.h>
2525
#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
2626
#include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
27+
#include <LibWeb/CSS/StyleValues/OpenTypeTaggedStyleValue.h>
2728
#include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
2829
#include <LibWeb/CSS/StyleValues/RatioStyleValue.h>
2930
#include <LibWeb/CSS/StyleValues/RectStyleValue.h>
@@ -635,6 +636,21 @@ ValueComparingRefPtr<StyleValue const> interpolate_property(DOM::Element& elemen
635636
return interpolate_value(element, calculation_context, from_value, to_value, delta, allow_discrete);
636637
}
637638

639+
if (property_id == PropertyID::FontVariationSettings) {
640+
// https://drafts.csswg.org/css-fonts/#font-variation-settings-def
641+
// Two declarations of font-feature-settings can be animated between if they are "like". "Like" declarations
642+
// are ones where the same set of properties appear (in any order). Because successive duplicate properties
643+
// are applied instead of prior duplicate properties, two declarations can be "like" even if they have
644+
// differing number of properties. If two declarations are "like" then animation occurs pairwise between
645+
// corresponding values in the declarations. Otherwise, animation is not possible.
646+
if (!from->is_value_list() || !to->is_value_list())
647+
return interpolate_discrete(from, to, delta, allow_discrete);
648+
649+
// The values in these lists have already been deduplicated and sorted at this point, so we can use
650+
// interpolate_value() to interpolate them pairwise.
651+
return interpolate_value(element, calculation_context, from, to, delta, allow_discrete);
652+
}
653+
638654
// https://drafts.csswg.org/web-animations-1/#animating-visibility
639655
if (property_id == PropertyID::Visibility) {
640656
// For the visibility property, visible is interpolated as a discrete step where values of p between 0 and 1 map to visible and other values of p map to the closer endpoint.
@@ -1574,6 +1590,16 @@ static RefPtr<StyleValue const> interpolate_value_impl(DOM::Element& element, Ca
15741590
auto interpolated_value = interpolate_raw(from.as_number().number(), to.as_number().number(), delta, calculation_context.accepted_type_ranges.get(ValueType::Number));
15751591
return NumberStyleValue::create(interpolated_value);
15761592
}
1593+
case StyleValue::Type::OpenTypeTagged: {
1594+
auto& from_open_type_tagged = from.as_open_type_tagged();
1595+
auto& to_open_type_tagged = to.as_open_type_tagged();
1596+
if (from_open_type_tagged.tag() != to_open_type_tagged.tag())
1597+
return {};
1598+
auto interpolated_value = interpolate_value(element, calculation_context, from_open_type_tagged.value(), to_open_type_tagged.value(), delta, allow_discrete);
1599+
if (!interpolated_value)
1600+
return {};
1601+
return OpenTypeTaggedStyleValue::create(OpenTypeTaggedStyleValue::Mode::FontVariationSettings, from_open_type_tagged.tag(), interpolated_value.release_nonnull());
1602+
}
15771603
case StyleValue::Type::Percentage: {
15781604
auto interpolated_value = interpolate_raw(from.as_percentage().percentage().value(), to.as_percentage().percentage().value(), delta, calculation_context.accepted_type_ranges.get(ValueType::Percentage));
15791605
return PercentageStyleValue::create(Percentage(interpolated_value));

0 commit comments

Comments
 (0)