diff options
author | Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com> | 2023-02-04 23:08:48 +0300 |
---|---|---|
committer | Sam Atkins <atkinssj@gmail.com> | 2023-02-05 08:06:06 +0000 |
commit | f58668031db222b2b4a2e8c5897745d0158b4bab (patch) | |
tree | e692fdc7f2aa076040bdb2f0d2596d33bd538d19 /Userland/Libraries | |
parent | 1f4106842d3a828eb47925d98abe227432549a22 (diff) | |
download | serenity-f58668031db222b2b4a2e8c5897745d0158b4bab.zip |
LibWeb: Respect `font-stretch` in `StyleComputer::compute_font`
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleComputer.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 0a766d26ba..d752220e51 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -997,8 +997,63 @@ 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); int width = Gfx::FontWidth::Normal; + if (font_stretch->is_identifier()) { + switch (static_cast<IdentifierStyleValue const&>(*font_stretch).id()) { + case CSS::ValueID::UltraCondensed: + width = Gfx::FontWidth::UltraCondensed; + break; + case CSS::ValueID::ExtraCondensed: + width = Gfx::FontWidth::ExtraCondensed; + break; + case CSS::ValueID::Condensed: + width = Gfx::FontWidth::Condensed; + break; + case CSS::ValueID::SemiCondensed: + width = Gfx::FontWidth::SemiCondensed; + break; + case CSS::ValueID::Normal: + width = Gfx::FontWidth::Normal; + break; + case CSS::ValueID::SemiExpanded: + width = Gfx::FontWidth::SemiExpanded; + break; + case CSS::ValueID::Expanded: + width = Gfx::FontWidth::Expanded; + break; + case CSS::ValueID::ExtraExpanded: + width = Gfx::FontWidth::ExtraExpanded; + break; + case CSS::ValueID::UltraExpanded: + width = Gfx::FontWidth::UltraExpanded; + break; + default: + break; + } + } else if (font_stretch->is_percentage()) { + float percentage = font_stretch->as_percentage().percentage().value(); + if (percentage <= 50) { + width = Gfx::FontWidth::UltraCondensed; + } else if (percentage <= 62.5f) { + width = Gfx::FontWidth::ExtraCondensed; + } else if (percentage <= 75.0f) { + width = Gfx::FontWidth::Condensed; + } else if (percentage <= 87.5f) { + width = Gfx::FontWidth::SemiCondensed; + } else if (percentage <= 100.0f) { + width = Gfx::FontWidth::Normal; + } else if (percentage <= 112.5f) { + width = Gfx::FontWidth::SemiExpanded; + } else if (percentage <= 125.0f) { + width = Gfx::FontWidth::Expanded; + } else if (percentage <= 150.0f) { + width = Gfx::FontWidth::ExtraExpanded; + } else { + width = Gfx::FontWidth::UltraExpanded; + } + } int weight = Gfx::FontWeight::Regular; if (font_weight->is_identifier()) { |