mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:17:35 +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:
parent
0538dc4e28
commit
085696ea39
3 changed files with 14 additions and 1 deletions
|
@ -5,4 +5,4 @@ set(SOURCES
|
||||||
)
|
)
|
||||||
|
|
||||||
serenity_lib(LibTTF ttf)
|
serenity_lib(LibTTF ttf)
|
||||||
target_link_libraries(LibTTF LibM LibCore)
|
target_link_libraries(LibTTF LibM LibCore LibTextCodec)
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include <LibTTF/Font.h>
|
#include <LibTTF/Font.h>
|
||||||
#include <LibTTF/Glyf.h>
|
#include <LibTTF/Glyf.h>
|
||||||
#include <LibTTF/Tables.h>
|
#include <LibTTF/Tables.h>
|
||||||
|
#include <LibTextCodec/Decoder.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
namespace TTF {
|
namespace TTF {
|
||||||
|
@ -189,8 +190,15 @@ String Name::string_for_id(NameId id) const
|
||||||
if (this_id != (u16)id)
|
if (this_id != (u16)id)
|
||||||
continue;
|
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 length = be_u16(m_slice.offset_pointer(6 + i * 12 + 8));
|
||||||
auto offset = be_u16(m_slice.offset_pointer(6 + i * 12 + 10));
|
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);
|
return String((const char*)m_slice.offset_pointer(string_offset + offset), length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -148,6 +148,11 @@ private:
|
||||||
|
|
||||||
class Name {
|
class Name {
|
||||||
public:
|
public:
|
||||||
|
enum class Platform {
|
||||||
|
Unicode = 0,
|
||||||
|
Macintosh = 1,
|
||||||
|
Windows = 3,
|
||||||
|
};
|
||||||
static Optional<Name> from_slice(const ReadonlyBytes&);
|
static Optional<Name> from_slice(const ReadonlyBytes&);
|
||||||
|
|
||||||
String family_name() const { return string_for_id(NameId::FamilyName); }
|
String family_name() const { return string_for_id(NameId::FamilyName); }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue