From 98eaa4b044c19cd58570ec5132737faebb40dd8c Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 27 Jun 2023 18:54:39 +0100 Subject: [PATCH] LibGfx: Add functions to convert font widths to/from strings This isn't a "width" in the sense of a fixed-width font, but of the OS/2 width class defined in some font formats. --- .../Libraries/LibGfx/Font/FontStyleMapping.h | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Userland/Libraries/LibGfx/Font/FontStyleMapping.h b/Userland/Libraries/LibGfx/Font/FontStyleMapping.h index 8d82e7dbbb..f4394099c7 100644 --- a/Userland/Libraries/LibGfx/Font/FontStyleMapping.h +++ b/Userland/Libraries/LibGfx/Font/FontStyleMapping.h @@ -36,6 +36,18 @@ static constexpr Array font_slope_names = { { { 3, "Reclined"sv }, } }; +static constexpr Array font_width_names = { { + { 1, "Ultra Condensed"sv }, + { 2, "Extra Condensed"sv }, + { 3, "Condensed"sv }, + { 4, "Semi Condensed"sv }, + { 5, "Normal"sv }, + { 6, "Semi Expanded"sv }, + { 7, "Expanded"sv }, + { 8, "Extra Expanded"sv }, + { 9, "Ultra Expanded"sv }, +} }; + static constexpr StringView weight_to_name(int weight) { for (auto& it : font_weight_names) { @@ -72,4 +84,22 @@ static constexpr int name_to_slope(StringView name) return {}; } +static constexpr StringView width_to_name(int width) +{ + for (auto& it : font_width_names) { + if (it.style == width) + return it.name; + } + return {}; +} + +static constexpr int name_to_width(StringView name) +{ + for (auto& it : font_width_names) { + if (it.name == name) + return it.style; + } + return {}; +} + }