Browse Source

LibGfx: Make BitmapFont::variant() report a complete typeface

thankyouverycool 3 years ago
parent
commit
84ce923850
2 changed files with 16 additions and 1 deletions
  1. 15 0
      Userland/Libraries/LibGfx/BitmapFont.cpp
  2. 1 1
      Userland/Libraries/LibGfx/BitmapFont.h

+ 15 - 0
Userland/Libraries/LibGfx/BitmapFont.cpp

@@ -10,6 +10,7 @@
 #include <AK/Utf8View.h>
 #include <LibCore/FileStream.h>
 #include <LibGfx/FontDatabase.h>
+#include <LibGfx/FontStyleMapping.h>
 
 namespace Gfx {
 
@@ -348,6 +349,20 @@ String BitmapFont::qualified_name() const
     return String::formatted("{} {} {}", family(), presentation_size(), weight());
 }
 
+String BitmapFont::variant() const
+{
+    StringBuilder builder;
+    builder.append(weight_to_name(weight()));
+    if (slope()) {
+        if (builder.string_view() == "Regular"sv)
+            builder.clear();
+        else
+            builder.append(" ");
+        builder.append(slope_to_name(slope()));
+    }
+    return builder.to_string();
+}
+
 Font const& Font::bold_variant() const
 {
     if (m_bold_variant)

+ 1 - 1
Userland/Libraries/LibGfx/BitmapFont.h

@@ -100,7 +100,7 @@ public:
 
     String family() const override { return m_family; }
     void set_family(String family) { m_family = move(family); }
-    String variant() const override { return String::number(weight()); }
+    String variant() const override;
 
     String qualified_name() const override;