From 980dcaac6e7654a6146306ef00834e19b22696ab Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Tue, 14 May 2024 21:13:26 +0100 Subject: [PATCH] Cleanup: Remove GetFontTable from FontCache. (#12677) This interface is no longer used, so does not need to be implemented. Removes manual memory management with malloc/free. --- src/fontcache.h | 8 -------- src/fontcache/freetypefontcache.cpp | 17 ----------------- src/fontcache/spritefontcache.h | 1 - src/fontcache/truetypefontcache.cpp | 18 ------------------ src/fontcache/truetypefontcache.h | 5 ----- src/os/macosx/font_osx.cpp | 12 ------------ src/os/macosx/font_osx.h | 1 - src/os/windows/font_win32.cpp | 14 -------------- src/os/windows/font_win32.h | 1 - src/tests/mock_fontcache.h | 1 - 10 files changed, 78 deletions(-) diff --git a/src/fontcache.h b/src/fontcache.h index 648fe4caa4..769bc66ac7 100644 --- a/src/fontcache.h +++ b/src/fontcache.h @@ -106,14 +106,6 @@ public: */ virtual GlyphID MapCharToGlyph(char32_t key, bool fallback = true) = 0; - /** - * Read a font table from the font. - * @param tag The of the table to load. - * @param length The length of the read data. - * @return The loaded table data. - */ - virtual const void *GetFontTable(uint32_t tag, size_t &length) = 0; - /** * Get the native OS font handle, if there is one. * @return Opaque OS font handle. diff --git a/src/fontcache/freetypefontcache.cpp b/src/fontcache/freetypefontcache.cpp index a16e76b055..e0fc7a2b61 100644 --- a/src/fontcache/freetypefontcache.cpp +++ b/src/fontcache/freetypefontcache.cpp @@ -34,7 +34,6 @@ private: FT_Face face; ///< The font face associated with this font. void SetFontSize(int pixels); - const void *InternalGetFontTable(uint32_t tag, size_t &length) override; const Sprite *InternalGetGlyph(GlyphID key, bool aa) override; public: @@ -324,22 +323,6 @@ GlyphID FreeTypeFontCache::MapCharToGlyph(char32_t key, bool allow_fallback) return glyph; } -const void *FreeTypeFontCache::InternalGetFontTable(uint32_t tag, size_t &length) -{ - FT_ULong len = 0; - FT_Byte *result = nullptr; - - FT_Load_Sfnt_Table(this->face, tag, 0, nullptr, &len); - - if (len > 0) { - result = MallocT(len); - FT_Load_Sfnt_Table(this->face, tag, 0, result, &len); - } - - length = len; - return result; -} - /** * Free everything allocated w.r.t. freetype. */ diff --git a/src/fontcache/spritefontcache.h b/src/fontcache/spritefontcache.h index e35cb1a5d6..e176aeb9b1 100644 --- a/src/fontcache/spritefontcache.h +++ b/src/fontcache/spritefontcache.h @@ -30,7 +30,6 @@ public: uint GetGlyphWidth(GlyphID key) override; bool GetDrawGlyphShadow() override; GlyphID MapCharToGlyph(char32_t key, [[maybe_unused]] bool allow_fallback = true) override { assert(IsPrintable(key)); return SPRITE_GLYPH | key; } - const void *GetFontTable(uint32_t, size_t &length) override { length = 0; return nullptr; } std::string GetFontName() override { return "sprite"; } bool IsBuiltInFont() override { return true; } }; diff --git a/src/fontcache/truetypefontcache.cpp b/src/fontcache/truetypefontcache.cpp index 9e16c363c1..462eac249e 100644 --- a/src/fontcache/truetypefontcache.cpp +++ b/src/fontcache/truetypefontcache.cpp @@ -33,10 +33,6 @@ TrueTypeFontCache::~TrueTypeFontCache() { /* Virtual functions get called statically in destructors, so make it explicit to remove any confusion. */ this->TrueTypeFontCache::ClearFontCache(); - - for (auto &iter : this->font_tables) { - free(iter.second.second); - } } /** @@ -164,17 +160,3 @@ const Sprite *TrueTypeFontCache::GetGlyph(GlyphID key) return this->InternalGetGlyph(key, GetFontAAState()); } - -const void *TrueTypeFontCache::GetFontTable(uint32_t tag, size_t &length) -{ - const auto iter = this->font_tables.find(tag); - if (iter != this->font_tables.end()) { - length = iter->second.first; - return iter->second.second; - } - - const void *result = this->InternalGetFontTable(tag, length); - - this->font_tables[tag] = std::pair(length, result); - return result; -} diff --git a/src/fontcache/truetypefontcache.h b/src/fontcache/truetypefontcache.h index 53f1965816..8433e6ddbd 100644 --- a/src/fontcache/truetypefontcache.h +++ b/src/fontcache/truetypefontcache.h @@ -27,9 +27,6 @@ protected: int req_size; ///< Requested font size. int used_size; ///< Used font size. - using FontTable = std::map>; ///< Table with font table cache - FontTable font_tables; ///< Cached font tables. - /** Container for information about a glyph. */ struct GlyphEntry { Sprite *sprite; ///< The loaded sprite. @@ -55,7 +52,6 @@ protected: GlyphEntry *GetGlyphPtr(GlyphID key); void SetGlyphPtr(GlyphID key, const GlyphEntry *glyph, bool duplicate = false); - virtual const void *InternalGetFontTable(uint32_t tag, size_t &length) = 0; virtual const Sprite *InternalGetGlyph(GlyphID key, bool aa) = 0; public: @@ -65,7 +61,6 @@ public: void SetUnicodeGlyph(char32_t key, SpriteID sprite) override { this->parent->SetUnicodeGlyph(key, sprite); } void InitializeUnicodeGlyphMap() override { this->parent->InitializeUnicodeGlyphMap(); } const Sprite *GetGlyph(GlyphID key) override; - const void *GetFontTable(uint32_t tag, size_t &length) override; void ClearFontCache() override; uint GetGlyphWidth(GlyphID key) override; bool GetDrawGlyphShadow() override; diff --git a/src/os/macosx/font_osx.cpp b/src/os/macosx/font_osx.cpp index 7cb557fed3..2bd290f4e6 100644 --- a/src/os/macosx/font_osx.cpp +++ b/src/os/macosx/font_osx.cpp @@ -204,18 +204,6 @@ GlyphID CoreTextFontCache::MapCharToGlyph(char32_t key, bool allow_fallback) return 0; } -const void *CoreTextFontCache::InternalGetFontTable(uint32_t tag, size_t &length) -{ - CFAutoRelease data(CTFontCopyTable(this->font.get(), (CTFontTableTag)tag, kCTFontTableOptionNoOptions)); - if (!data) return nullptr; - - length = CFDataGetLength(data.get()); - auto buf = MallocT(length); - - CFDataGetBytes(data.get(), CFRangeMake(0, (CFIndex)length), buf); - return buf; -} - const Sprite *CoreTextFontCache::InternalGetGlyph(GlyphID key, bool use_aa) { /* Get glyph size. */ diff --git a/src/os/macosx/font_osx.h b/src/os/macosx/font_osx.h index ca2ac1d5e9..3ef86fba99 100644 --- a/src/os/macosx/font_osx.h +++ b/src/os/macosx/font_osx.h @@ -23,7 +23,6 @@ class CoreTextFontCache : public TrueTypeFontCache { void SetFontSize(int pixels); const Sprite *InternalGetGlyph(GlyphID key, bool use_aa) override; - const void *InternalGetFontTable(uint32_t tag, size_t &length) override; public: CoreTextFontCache(FontSize fs, CFAutoRelease &&font, int pixels); ~CoreTextFontCache() {} diff --git a/src/os/windows/font_win32.cpp b/src/os/windows/font_win32.cpp index 767dfb83ab..cb82b2b794 100644 --- a/src/os/windows/font_win32.cpp +++ b/src/os/windows/font_win32.cpp @@ -284,20 +284,6 @@ void Win32FontCache::ClearFontCache() return allow_fallback && key >= SCC_SPRITE_START && key <= SCC_SPRITE_END ? this->parent->MapCharToGlyph(key) : 0; } -/* virtual */ const void *Win32FontCache::InternalGetFontTable(uint32_t tag, size_t &length) -{ - DWORD len = GetFontData(this->dc, tag, 0, nullptr, 0); - - void *result = nullptr; - if (len != GDI_ERROR && len > 0) { - result = MallocT(len); - GetFontData(this->dc, tag, 0, result, len); - } - - length = len; - return result; -} - static bool TryLoadFontFromFile(const std::string &font_name, LOGFONT &logfont) { diff --git a/src/os/windows/font_win32.h b/src/os/windows/font_win32.h index bdb2cc9a9b..5d5555341c 100644 --- a/src/os/windows/font_win32.h +++ b/src/os/windows/font_win32.h @@ -28,7 +28,6 @@ private: void SetFontSize(int pixels); protected: - const void *InternalGetFontTable(uint32_t tag, size_t &length) override; const Sprite *InternalGetGlyph(GlyphID key, bool aa) override; public: diff --git a/src/tests/mock_fontcache.h b/src/tests/mock_fontcache.h index e6cee2d022..1a43cd1821 100644 --- a/src/tests/mock_fontcache.h +++ b/src/tests/mock_fontcache.h @@ -30,7 +30,6 @@ public: uint GetGlyphWidth(GlyphID) override { return this->height / 2; } bool GetDrawGlyphShadow() override { return false; } GlyphID MapCharToGlyph(char32_t key, [[maybe_unused]] bool allow_fallback = true) override { return key; } - const void *GetFontTable(uint32_t, size_t &length) override { length = 0; return nullptr; } std::string GetFontName() override { return "mock"; } bool IsBuiltInFont() override { return true; }