mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:27:35 +00:00
LibWeb: Use a switch instead of HashMap
to get absolute size mappings
A `HashMap` is unnecessary complexity for such a small set of possible keys, let's let the optimizer actually understand what's happening.
This commit is contained in:
parent
f57c42fad7
commit
c9849aeadd
1 changed files with 26 additions and 13 deletions
|
@ -1941,17 +1941,31 @@ RefPtr<Gfx::Font const> StyleComputer::compute_font_for_style_values(DOM::Elemen
|
||||||
|
|
||||||
if (font_size.is_identifier()) {
|
if (font_size.is_identifier()) {
|
||||||
// https://w3c.github.io/csswg-drafts/css-fonts/#absolute-size-mapping
|
// https://w3c.github.io/csswg-drafts/css-fonts/#absolute-size-mapping
|
||||||
AK::HashMap<Web::CSS::ValueID, float> absolute_size_mapping = {
|
constexpr auto get_absolute_size_mapping = [](Web::CSS::ValueID identifier) {
|
||||||
{ CSS::ValueID::XxSmall, 0.6 },
|
switch (identifier) {
|
||||||
{ CSS::ValueID::XSmall, 0.75 },
|
case CSS::ValueID::XxSmall:
|
||||||
{ CSS::ValueID::Small, 8.0 / 9.0 },
|
return 0.6f;
|
||||||
{ CSS::ValueID::Medium, 1.0 },
|
case CSS::ValueID::XSmall:
|
||||||
{ CSS::ValueID::Large, 1.2 },
|
return 0.75f;
|
||||||
{ CSS::ValueID::XLarge, 1.5 },
|
case CSS::ValueID::Small:
|
||||||
{ CSS::ValueID::XxLarge, 2.0 },
|
return 8.0f / 9.0f;
|
||||||
{ CSS::ValueID::XxxLarge, 3.0 },
|
case CSS::ValueID::Medium:
|
||||||
{ CSS::ValueID::Smaller, 0.8 },
|
return 1.0f;
|
||||||
{ CSS::ValueID::Larger, 1.25 },
|
case CSS::ValueID::Large:
|
||||||
|
return 1.2f;
|
||||||
|
case CSS::ValueID::XLarge:
|
||||||
|
return 1.5f;
|
||||||
|
case CSS::ValueID::XxLarge:
|
||||||
|
return 2.0f;
|
||||||
|
case CSS::ValueID::XxxLarge:
|
||||||
|
return 3.0f;
|
||||||
|
case CSS::ValueID::Smaller:
|
||||||
|
return 0.8f;
|
||||||
|
case CSS::ValueID::Larger:
|
||||||
|
return 1.25f;
|
||||||
|
default:
|
||||||
|
return 1.0f;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
auto const identifier = static_cast<IdentifierStyleValue const&>(font_size).id();
|
auto const identifier = static_cast<IdentifierStyleValue const&>(font_size).id();
|
||||||
|
@ -1965,8 +1979,7 @@ RefPtr<Gfx::Font const> StyleComputer::compute_font_for_style_values(DOM::Elemen
|
||||||
font_size_in_px = CSSPixels::nearest_value_for(parent_element->computed_css_values()->computed_font().pixel_metrics().size);
|
font_size_in_px = CSSPixels::nearest_value_for(parent_element->computed_css_values()->computed_font().pixel_metrics().size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto const multiplier = absolute_size_mapping.get(identifier).value_or(1.0);
|
font_size_in_px.scale_by(get_absolute_size_mapping(identifier));
|
||||||
font_size_in_px.scale_by(multiplier);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Length::ResolutionContext const length_resolution_context {
|
Length::ResolutionContext const length_resolution_context {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue