1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:07:36 +00:00

LibTTF: Interpret font names from Windows platform as UTF-16BE

This turns the admittedly aesthetic "T a h o m a" into "Tahoma" :^)
This commit is contained in:
Andreas Kling 2021-02-16 17:31:42 +01:00
parent 0538dc4e28
commit 085696ea39
3 changed files with 14 additions and 1 deletions

View file

@ -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);
}