Browse Source

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.
Sam Atkins 2 năm trước cách đây
mục cha
commit
98eaa4b044
1 tập tin đã thay đổi với 30 bổ sung0 xóa
  1. 30 0
      Userland/Libraries/LibGfx/Font/FontStyleMapping.h

+ 30 - 0
Userland/Libraries/LibGfx/Font/FontStyleMapping.h

@@ -36,6 +36,18 @@ static constexpr Array<FontStyleMapping, 4> font_slope_names = { {
     { 3, "Reclined"sv },
 } };
 
+static constexpr Array<FontStyleMapping, 9> 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 {};
+}
+
 }