1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:37:35 +00:00

LibWeb: Handle <absolute-size> values in the font-size CSS property

This commit is contained in:
Mateusz Górzyński 2022-11-30 16:17:57 +01:00 committed by Sam Atkins
parent 31d315001c
commit a551e02e5e

View file

@ -7,6 +7,7 @@
*/ */
#include <AK/Debug.h> #include <AK/Debug.h>
#include <AK/HashMap.h>
#include <AK/QuickSort.h> #include <AK/QuickSort.h>
#include <AK/TemporaryChange.h> #include <AK/TemporaryChange.h>
#include <LibGfx/Font/Font.h> #include <LibGfx/Font/Font.h>
@ -1007,30 +1008,27 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele
bool bold = weight > Gfx::FontWeight::Regular; bool bold = weight > Gfx::FontWeight::Regular;
// FIXME: Should be based on "user's default font size"
float font_size_in_px = 16; float font_size_in_px = 16;
if (font_size->is_identifier()) { if (font_size->is_identifier()) {
switch (static_cast<IdentifierStyleValue const&>(*font_size).id()) { // https://w3c.github.io/csswg-drafts/css-fonts/#absolute-size-mapping
case CSS::ValueID::XxSmall: AK::HashMap<Web::CSS::ValueID, float> absolute_size_mapping = {
case CSS::ValueID::XSmall: { CSS::ValueID::XxSmall, 0.6 },
case CSS::ValueID::Small: { CSS::ValueID::XSmall, 0.75 },
case CSS::ValueID::Medium: { CSS::ValueID::Small, 8.0 / 9.0 },
// FIXME: Should be based on "user's default font size" { CSS::ValueID::Medium, 1.0 },
font_size_in_px = 16; { CSS::ValueID::Large, 1.2 },
break; { CSS::ValueID::XLarge, 1.5 },
case CSS::ValueID::Large: { CSS::ValueID::XxLarge, 2.0 },
case CSS::ValueID::XLarge: { CSS::ValueID::XxxLarge, 3.0 },
case CSS::ValueID::XxLarge: };
case CSS::ValueID::XxxLarge: auto const identifier = static_cast<IdentifierStyleValue const&>(*font_size).id();
// FIXME: Should be based on "user's default font size" if (identifier == CSS::ValueID::Smaller || identifier == CSS::ValueID::Larger) {
font_size_in_px = 12;
break;
case CSS::ValueID::Smaller:
case CSS::ValueID::Larger:
// FIXME: Should be based on parent element // FIXME: Should be based on parent element
break; } else {
default: auto const multiplier = absolute_size_mapping.get(identifier).value_or(1.0);
break; font_size_in_px *= multiplier;
} }
} else { } else {
float root_font_size = root_element_font_size(); float root_font_size = root_element_font_size();