diff --git a/libraries/ZWidget/src/core/truetypefont.cpp b/libraries/ZWidget/src/core/truetypefont.cpp index 07b599e286..a151c4ad2c 100644 --- a/libraries/ZWidget/src/core/truetypefont.cpp +++ b/libraries/ZWidget/src/core/truetypefont.cpp @@ -5,17 +5,32 @@ #include "core/pathfill.h" #include #include +#include #ifdef DUMP_GLYPH #include #endif -TrueTypeFont::TrueTypeFont(std::vector initdata) : data(std::move(initdata)) +TrueTypeFont::TrueTypeFont(std::vector initdata, int ttcFontIndex) : data(std::move(initdata)) { if (data.size() > 0x7fffffff) throw std::runtime_error("TTF file is larger than 2 gigabytes!"); TrueTypeFileReader reader(data.data(), data.size()); + ttf_Tag versionTag = reader.ReadTag(); + + if (memcmp(versionTag.data(), "ttcf", 4) == 0) // TTC header + { + ttcHeader.Load(reader); + if (ttcFontIndex >= ttcHeader.numFonts) + throw std::runtime_error("TTC font index out of bounds"); + reader.Seek(ttcHeader.tableDirectoryOffsets[ttcFontIndex]); + } + else + { + reader.Seek(0); + } + directory.Load(reader); if (!directory.ContainsTTFOutlines()) diff --git a/libraries/ZWidget/src/core/truetypefont.h b/libraries/ZWidget/src/core/truetypefont.h index 40d62adba4..bfe310846d 100644 --- a/libraries/ZWidget/src/core/truetypefont.h +++ b/libraries/ZWidget/src/core/truetypefont.h @@ -431,7 +431,7 @@ public: class TrueTypeFont { public: - TrueTypeFont(std::vector data); + TrueTypeFont(std::vector data, int ttcFontIndex = 0); TrueTypeTextMetrics GetTextMetrics(double height) const; uint32_t GetGlyphIndex(uint32_t codepoint) const; @@ -443,7 +443,8 @@ private: static float F2DOT14_ToFloat(ttf_F2DOT14 v); std::vector data; - + + TTC_Header ttcHeader; TTF_TableDirectory directory; // Required for all OpenType fonts: