diff --git a/Userland/Libraries/LibGfx/Font/OpenType/Cmap.cpp b/Userland/Libraries/LibGfx/Font/OpenType/Cmap.cpp index bf134a2eb6..a754062acd 100644 --- a/Userland/Libraries/LibGfx/Font/OpenType/Cmap.cpp +++ b/Userland/Libraries/LibGfx/Font/OpenType/Cmap.cpp @@ -75,10 +75,12 @@ Optional Cmap::subtable(u32 index) const return Subtable(subtable_slice, platform_id, encoding_id); } -// FIXME: This only handles formats 4 (SegmentToDelta) and 12 (SegmentedCoverage) for now. +// FIXME: Implement the missing formats. u32 Cmap::Subtable::glyph_id_for_code_point(u32 code_point) const { switch (format()) { + case Format::ByteEncoding: + return glyph_id_for_code_point_table_0(code_point); case Format::SegmentToDelta: return glyph_id_for_code_point_table_4(code_point); case Format::SegmentedCoverage: @@ -88,6 +90,14 @@ u32 Cmap::Subtable::glyph_id_for_code_point(u32 code_point) const } } +u32 Cmap::Subtable::glyph_id_for_code_point_table_0(u32 code_point) const +{ + if (code_point > 255) + return 0; + + return m_slice.at((u32)Table0Offsets::GlyphIdArray + code_point); +} + u32 Cmap::Subtable::glyph_id_for_code_point_table_4(u32 code_point) const { u32 segcount_x2 = be_u16(m_slice.offset_pointer((u32)Table4Offsets::SegCountX2)); diff --git a/Userland/Libraries/LibGfx/Font/OpenType/Cmap.h b/Userland/Libraries/LibGfx/Font/OpenType/Cmap.h index 7f29b0d9a8..19660e30e7 100644 --- a/Userland/Libraries/LibGfx/Font/OpenType/Cmap.h +++ b/Userland/Libraries/LibGfx/Font/OpenType/Cmap.h @@ -52,6 +52,9 @@ public: Format format() const; private: + enum class Table0Offsets { + GlyphIdArray = 6 + }; enum class Table4Offsets { SegCountX2 = 6, EndConstBase = 14, @@ -75,6 +78,7 @@ public: Record = 12, }; + u32 glyph_id_for_code_point_table_0(u32 code_point) const; u32 glyph_id_for_code_point_table_4(u32 code_point) const; u32 glyph_id_for_code_point_table_12(u32 code_point) const;