LibWeb: Compute font properties the same as other properties

Previously we computed font properties separately from other properties
for two reasons:
  1) These font properties were computed using a different length
     resolution context than the rest of the properties.
  2) These properties were required to be computed before creating the
     length resolution context for the rest of the properties.

The first issue was solved in the previous commit by introducing a
generic method to get the computation context for a property, and
the second is solved in this commit by computing properties in the
required order.

This simplifies the code a bit and opens up some opportunities for
optimization.
This commit is contained in:
Callum Law
2026-01-03 01:58:38 +13:00
committed by Andreas Kling
parent 5b635a2135
commit 32da7edf5e
Notes: github-actions[bot] 2026-02-13 20:56:30 +00:00
6 changed files with 137 additions and 161 deletions

View File

@@ -289,6 +289,7 @@ Vector<PropertyID> const& longhands_for_shorthand(PropertyID);
Vector<PropertyID> const& expanded_longhands_for_shorthand(PropertyID);
bool property_maps_to_shorthand(PropertyID);
Vector<PropertyID> const& shorthands_for_longhand(PropertyID);
Vector<PropertyID> const& property_computation_order();
bool property_is_positional_value_list_shorthand(PropertyID);
size_t property_maximum_value_count(PropertyID);
@@ -1512,6 +1513,73 @@ Vector<PropertyID> const& shorthands_for_longhand(PropertyID property_id)
}
}
}
)~~~");
Vector<StringView> manually_specified_computation_order = {
// math-depth is required to compute font-size
"MathDepth"sv,
// Font properties are required to absolutize font-relative units used in other properties, including line-height.
"FontFamily"sv,
"FontFeatureSettings"sv,
"FontKerning"sv,
"FontOpticalSizing"sv,
"FontSize"sv,
"FontStyle"sv,
"FontVariantAlternates"sv,
"FontVariantCaps"sv,
"FontVariantEastAsian"sv,
"FontVariantEmoji"sv,
"FontVariantLigatures"sv,
"FontVariantNumeric"sv,
"FontVariantPosition"sv,
"FontVariationSettings"sv,
"FontWeight"sv,
"FontWidth"sv,
"TextRendering"sv,
// line-height is required to absolutize `lh` units used in other properties.
"LineHeight"sv,
// color-scheme is included in the generic computation context in order to compute light-dark() color functions
"ColorScheme"sv,
// background-image is required to compute the other background-* properties
"BackgroundImage"sv,
};
generator.append(R"~~~(
Vector<PropertyID> const& property_computation_order() {
static Vector<PropertyID> order = {
)~~~");
for (auto const& property_name : manually_specified_computation_order) {
auto property_generator = generator.fork();
property_generator.set("name:titlecase", property_name);
property_generator.appendln(" PropertyID::@name:titlecase@,");
}
properties.for_each_member([&](auto& name, auto& value) {
VERIFY(value.is_object());
if (is_legacy_alias(value.as_object()))
return;
if (value.as_object().has("longhands"sv))
return;
if (manually_specified_computation_order.contains_slow(title_casify(name)))
return;
auto property_generator = generator.fork();
property_generator.set("name:titlecase", title_casify(name));
property_generator.appendln(" PropertyID::@name:titlecase@,");
});
generator.append(R"~~~(
};
return order;
}
)~~~");
generator.append(R"~~~(