From 3ae1a80576e2d10fb87e328ed86325db8f043014 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Fri, 26 May 2023 19:32:41 +0100 Subject: [PATCH] Codechange: Return fontcache font name as std::string. --- src/fontcache.h | 2 +- src/fontcache/freetypefontcache.cpp | 12 ++++++------ src/fontcache/spritefontcache.h | 2 +- src/os/macosx/font_osx.h | 2 +- src/os/macosx/string_osx.cpp | 2 +- src/os/windows/font_win32.h | 2 +- src/os/windows/string_uniscribe.cpp | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/fontcache.h b/src/fontcache.h index efc1496304..2a74de2cd4 100644 --- a/src/fontcache.h +++ b/src/fontcache.h @@ -132,7 +132,7 @@ public: * Get the name of this font. * @return The name of the font. */ - virtual const char *GetFontName() = 0; + virtual std::string GetFontName() = 0; /** * Get the font cache of a given font size. diff --git a/src/fontcache/freetypefontcache.cpp b/src/fontcache/freetypefontcache.cpp index 621b33fa9d..1bde653f94 100644 --- a/src/fontcache/freetypefontcache.cpp +++ b/src/fontcache/freetypefontcache.cpp @@ -33,16 +33,16 @@ private: FT_Face face; ///< The font face associated with this font. void SetFontSize(FontSize fs, FT_Face face, int pixels); - virtual const void *InternalGetFontTable(uint32 tag, size_t &length); - virtual const Sprite *InternalGetGlyph(GlyphID key, bool aa); + const void *InternalGetFontTable(uint32 tag, size_t &length) override; + const Sprite *InternalGetGlyph(GlyphID key, bool aa) override; public: FreeTypeFontCache(FontSize fs, FT_Face face, int pixels); ~FreeTypeFontCache(); - virtual void ClearFontCache(); - virtual GlyphID MapCharToGlyph(WChar key); - virtual const char *GetFontName() { return face->family_name; } - virtual bool IsBuiltInFont() { return false; } + void ClearFontCache() override; + GlyphID MapCharToGlyph(WChar key) override; + std::string GetFontName() override { return face->family_name; } + bool IsBuiltInFont() override { return false; } }; FT_Library _library = nullptr; diff --git a/src/fontcache/spritefontcache.h b/src/fontcache/spritefontcache.h index a47b4ac18f..ce74972b3e 100644 --- a/src/fontcache/spritefontcache.h +++ b/src/fontcache/spritefontcache.h @@ -31,7 +31,7 @@ public: virtual bool GetDrawGlyphShadow(); virtual GlyphID MapCharToGlyph(WChar key) { assert(IsPrintable(key)); return SPRITE_GLYPH | key; } virtual const void *GetFontTable(uint32 tag, size_t &length) { length = 0; return nullptr; } - virtual const char *GetFontName() { return "sprite"; } + virtual std::string GetFontName() { return "sprite"; } virtual bool IsBuiltInFont() { return true; } }; diff --git a/src/os/macosx/font_osx.h b/src/os/macosx/font_osx.h index 7b58bc772c..72518c5676 100644 --- a/src/os/macosx/font_osx.h +++ b/src/os/macosx/font_osx.h @@ -30,7 +30,7 @@ public: void ClearFontCache() override; GlyphID MapCharToGlyph(WChar key) override; - const char *GetFontName() override { return font_name.c_str(); } + std::string GetFontName() override { return font_name; } bool IsBuiltInFont() override { return false; } const void *GetOSHandle() override { return font.get(); } }; diff --git a/src/os/macosx/string_osx.cpp b/src/os/macosx/string_osx.cpp index c96c541994..af91fbba7b 100644 --- a/src/os/macosx/string_osx.cpp +++ b/src/os/macosx/string_osx.cpp @@ -180,7 +180,7 @@ static CTRunDelegateCallbacks _sprite_font_callback = { if (font == nullptr) { if (!_font_cache[i.second->fc->GetSize()]) { /* Cache font information. */ - CFAutoRelease font_name(CFStringCreateWithCString(kCFAllocatorDefault, i.second->fc->GetFontName(), kCFStringEncodingUTF8)); + CFAutoRelease font_name(CFStringCreateWithCString(kCFAllocatorDefault, i.second->fc->GetFontName().c_str(), kCFStringEncodingUTF8)); _font_cache[i.second->fc->GetSize()].reset(CTFontCreateWithName(font_name.get(), i.second->fc->GetFontSize(), nullptr)); } font = _font_cache[i.second->fc->GetSize()].get(); diff --git a/src/os/windows/font_win32.h b/src/os/windows/font_win32.h index b83b2c5f35..7f5f62a7f2 100644 --- a/src/os/windows/font_win32.h +++ b/src/os/windows/font_win32.h @@ -34,7 +34,7 @@ public: ~Win32FontCache(); void ClearFontCache() override; GlyphID MapCharToGlyph(WChar key) override; - const char *GetFontName() override { return this->fontname.c_str(); } + std::string GetFontName() override { return this->fontname; } const void *GetOSHandle() override { return &this->logfont; } }; diff --git a/src/os/windows/string_uniscribe.cpp b/src/os/windows/string_uniscribe.cpp index 672c2dcd3d..1447d7ac2e 100644 --- a/src/os/windows/string_uniscribe.cpp +++ b/src/os/windows/string_uniscribe.cpp @@ -152,7 +152,7 @@ static HFONT HFontFromFont(Font *font) logfont.lfHeight = font->fc->GetHeight(); logfont.lfWeight = FW_NORMAL; logfont.lfCharSet = DEFAULT_CHARSET; - convert_to_fs(font->fc->GetFontName(), logfont.lfFaceName, lengthof(logfont.lfFaceName)); + convert_to_fs(font->fc->GetFontName().c_str(), logfont.lfFaceName, lengthof(logfont.lfFaceName)); return CreateFontIndirect(&logfont); }