LibWeb: Use compute_font_width for font-width descriptor

This allows us to remove `StyleValue::to_font_width`
This commit is contained in:
Callum Law 2025-09-02 21:23:31 +12:00 committed by Sam Atkins
commit 425b7de44a
Notes: github-actions[bot] 2025-09-19 09:07:59 +00:00
3 changed files with 10 additions and 63 deletions

View file

@ -172,64 +172,4 @@ int StyleValue::to_font_slope() const
return normal_slope;
}
int StyleValue::to_font_width() const
{
int width = Gfx::FontWidth::Normal;
if (is_keyword()) {
switch (as_keyword().keyword()) {
case Keyword::UltraCondensed:
width = Gfx::FontWidth::UltraCondensed;
break;
case Keyword::ExtraCondensed:
width = Gfx::FontWidth::ExtraCondensed;
break;
case Keyword::Condensed:
width = Gfx::FontWidth::Condensed;
break;
case Keyword::SemiCondensed:
width = Gfx::FontWidth::SemiCondensed;
break;
case Keyword::Normal:
width = Gfx::FontWidth::Normal;
break;
case Keyword::SemiExpanded:
width = Gfx::FontWidth::SemiExpanded;
break;
case Keyword::Expanded:
width = Gfx::FontWidth::Expanded;
break;
case Keyword::ExtraExpanded:
width = Gfx::FontWidth::ExtraExpanded;
break;
case Keyword::UltraExpanded:
width = Gfx::FontWidth::UltraExpanded;
break;
default:
break;
}
} else if (is_percentage()) {
float percentage = 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;
}
}
return width;
}
}