summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibTTF
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-02-16 17:31:42 +0100
committerAndreas Kling <kling@serenityos.org>2021-02-16 17:32:42 +0100
commit085696ea3907efd0357a55197218a8979946a722 (patch)
treece3fa19cd854a7e4b49652b5bab7c9f7d5c09be1 /Userland/Libraries/LibTTF
parent0538dc4e28966fb789dd028f6e34d06525169ed3 (diff)
downloadserenity-085696ea3907efd0357a55197218a8979946a722.zip
LibTTF: Interpret font names from Windows platform as UTF-16BE
This turns the admittedly aesthetic "T a h o m a" into "Tahoma" :^)
Diffstat (limited to 'Userland/Libraries/LibTTF')
-rw-r--r--Userland/Libraries/LibTTF/CMakeLists.txt2
-rw-r--r--Userland/Libraries/LibTTF/Font.cpp8
-rw-r--r--Userland/Libraries/LibTTF/Tables.h5
3 files changed, 14 insertions, 1 deletions
diff --git a/Userland/Libraries/LibTTF/CMakeLists.txt b/Userland/Libraries/LibTTF/CMakeLists.txt
index 2fe3d94647..fa9daa9d5f 100644
--- a/Userland/Libraries/LibTTF/CMakeLists.txt
+++ b/Userland/Libraries/LibTTF/CMakeLists.txt
@@ -5,4 +5,4 @@ set(SOURCES
)
serenity_lib(LibTTF ttf)
-target_link_libraries(LibTTF LibM LibCore)
+target_link_libraries(LibTTF LibM LibCore LibTextCodec)
diff --git a/Userland/Libraries/LibTTF/Font.cpp b/Userland/Libraries/LibTTF/Font.cpp
index 2cdfec272b..be649dc171 100644
--- a/Userland/Libraries/LibTTF/Font.cpp
+++ b/Userland/Libraries/LibTTF/Font.cpp
@@ -34,6 +34,7 @@
#include <LibTTF/Font.h>
#include <LibTTF/Glyf.h>
#include <LibTTF/Tables.h>
+#include <LibTextCodec/Decoder.h>
#include <math.h>
namespace TTF {
@@ -189,8 +190,15 @@ String Name::string_for_id(NameId id) const
if (this_id != (u16)id)
continue;
+ auto platform = be_u16(m_slice.offset_pointer(6 + i * 12 + 0));
auto length = be_u16(m_slice.offset_pointer(6 + i * 12 + 8));
auto offset = be_u16(m_slice.offset_pointer(6 + i * 12 + 10));
+
+ if (platform == (u16)Platform::Windows) {
+ static auto& decoder = *TextCodec::decoder_for("utf-16be");
+ return decoder.to_utf8(StringView { (const char*)m_slice.offset_pointer(string_offset + offset), length });
+ }
+
return String((const char*)m_slice.offset_pointer(string_offset + offset), length);
}
diff --git a/Userland/Libraries/LibTTF/Tables.h b/Userland/Libraries/LibTTF/Tables.h
index d5f5014bd4..a0aff9f230 100644
--- a/Userland/Libraries/LibTTF/Tables.h
+++ b/Userland/Libraries/LibTTF/Tables.h
@@ -148,6 +148,11 @@ private:
class Name {
public:
+ enum class Platform {
+ Unicode = 0,
+ Macintosh = 1,
+ Windows = 3,
+ };
static Optional<Name> from_slice(const ReadonlyBytes&);
String family_name() const { return string_for_id(NameId::FamilyName); }