mirror of https://github.com/OpenTTD/OpenTTD
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.pull/12684/head
parent
ed67aedabf
commit
980dcaac6e
|
@ -106,14 +106,6 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual GlyphID MapCharToGlyph(char32_t key, bool fallback = true) = 0;
|
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.
|
* Get the native OS font handle, if there is one.
|
||||||
* @return Opaque OS font handle.
|
* @return Opaque OS font handle.
|
||||||
|
|
|
@ -34,7 +34,6 @@ private:
|
||||||
FT_Face face; ///< The font face associated with this font.
|
FT_Face face; ///< The font face associated with this font.
|
||||||
|
|
||||||
void SetFontSize(int pixels);
|
void SetFontSize(int pixels);
|
||||||
const void *InternalGetFontTable(uint32_t tag, size_t &length) override;
|
|
||||||
const Sprite *InternalGetGlyph(GlyphID key, bool aa) override;
|
const Sprite *InternalGetGlyph(GlyphID key, bool aa) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -324,22 +323,6 @@ GlyphID FreeTypeFontCache::MapCharToGlyph(char32_t key, bool allow_fallback)
|
||||||
return glyph;
|
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<FT_Byte>(len);
|
|
||||||
FT_Load_Sfnt_Table(this->face, tag, 0, result, &len);
|
|
||||||
}
|
|
||||||
|
|
||||||
length = len;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free everything allocated w.r.t. freetype.
|
* Free everything allocated w.r.t. freetype.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -30,7 +30,6 @@ public:
|
||||||
uint GetGlyphWidth(GlyphID key) override;
|
uint GetGlyphWidth(GlyphID key) override;
|
||||||
bool GetDrawGlyphShadow() override;
|
bool GetDrawGlyphShadow() override;
|
||||||
GlyphID MapCharToGlyph(char32_t key, [[maybe_unused]] bool allow_fallback = true) override { assert(IsPrintable(key)); return SPRITE_GLYPH | key; }
|
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"; }
|
std::string GetFontName() override { return "sprite"; }
|
||||||
bool IsBuiltInFont() override { return true; }
|
bool IsBuiltInFont() override { return true; }
|
||||||
};
|
};
|
||||||
|
|
|
@ -33,10 +33,6 @@ TrueTypeFontCache::~TrueTypeFontCache()
|
||||||
{
|
{
|
||||||
/* Virtual functions get called statically in destructors, so make it explicit to remove any confusion. */
|
/* Virtual functions get called statically in destructors, so make it explicit to remove any confusion. */
|
||||||
this->TrueTypeFontCache::ClearFontCache();
|
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());
|
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<size_t, const void *>(length, result);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
|
@ -27,9 +27,6 @@ protected:
|
||||||
int req_size; ///< Requested font size.
|
int req_size; ///< Requested font size.
|
||||||
int used_size; ///< Used font size.
|
int used_size; ///< Used font size.
|
||||||
|
|
||||||
using FontTable = std::map<uint32_t, std::pair<size_t, const void *>>; ///< Table with font table cache
|
|
||||||
FontTable font_tables; ///< Cached font tables.
|
|
||||||
|
|
||||||
/** Container for information about a glyph. */
|
/** Container for information about a glyph. */
|
||||||
struct GlyphEntry {
|
struct GlyphEntry {
|
||||||
Sprite *sprite; ///< The loaded sprite.
|
Sprite *sprite; ///< The loaded sprite.
|
||||||
|
@ -55,7 +52,6 @@ protected:
|
||||||
GlyphEntry *GetGlyphPtr(GlyphID key);
|
GlyphEntry *GetGlyphPtr(GlyphID key);
|
||||||
void SetGlyphPtr(GlyphID key, const GlyphEntry *glyph, bool duplicate = false);
|
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;
|
virtual const Sprite *InternalGetGlyph(GlyphID key, bool aa) = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -65,7 +61,6 @@ public:
|
||||||
void SetUnicodeGlyph(char32_t key, SpriteID sprite) override { this->parent->SetUnicodeGlyph(key, sprite); }
|
void SetUnicodeGlyph(char32_t key, SpriteID sprite) override { this->parent->SetUnicodeGlyph(key, sprite); }
|
||||||
void InitializeUnicodeGlyphMap() override { this->parent->InitializeUnicodeGlyphMap(); }
|
void InitializeUnicodeGlyphMap() override { this->parent->InitializeUnicodeGlyphMap(); }
|
||||||
const Sprite *GetGlyph(GlyphID key) override;
|
const Sprite *GetGlyph(GlyphID key) override;
|
||||||
const void *GetFontTable(uint32_t tag, size_t &length) override;
|
|
||||||
void ClearFontCache() override;
|
void ClearFontCache() override;
|
||||||
uint GetGlyphWidth(GlyphID key) override;
|
uint GetGlyphWidth(GlyphID key) override;
|
||||||
bool GetDrawGlyphShadow() override;
|
bool GetDrawGlyphShadow() override;
|
||||||
|
|
|
@ -204,18 +204,6 @@ GlyphID CoreTextFontCache::MapCharToGlyph(char32_t key, bool allow_fallback)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const void *CoreTextFontCache::InternalGetFontTable(uint32_t tag, size_t &length)
|
|
||||||
{
|
|
||||||
CFAutoRelease<CFDataRef> data(CTFontCopyTable(this->font.get(), (CTFontTableTag)tag, kCTFontTableOptionNoOptions));
|
|
||||||
if (!data) return nullptr;
|
|
||||||
|
|
||||||
length = CFDataGetLength(data.get());
|
|
||||||
auto buf = MallocT<UInt8>(length);
|
|
||||||
|
|
||||||
CFDataGetBytes(data.get(), CFRangeMake(0, (CFIndex)length), buf);
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Sprite *CoreTextFontCache::InternalGetGlyph(GlyphID key, bool use_aa)
|
const Sprite *CoreTextFontCache::InternalGetGlyph(GlyphID key, bool use_aa)
|
||||||
{
|
{
|
||||||
/* Get glyph size. */
|
/* Get glyph size. */
|
||||||
|
|
|
@ -23,7 +23,6 @@ class CoreTextFontCache : public TrueTypeFontCache {
|
||||||
|
|
||||||
void SetFontSize(int pixels);
|
void SetFontSize(int pixels);
|
||||||
const Sprite *InternalGetGlyph(GlyphID key, bool use_aa) override;
|
const Sprite *InternalGetGlyph(GlyphID key, bool use_aa) override;
|
||||||
const void *InternalGetFontTable(uint32_t tag, size_t &length) override;
|
|
||||||
public:
|
public:
|
||||||
CoreTextFontCache(FontSize fs, CFAutoRelease<CTFontDescriptorRef> &&font, int pixels);
|
CoreTextFontCache(FontSize fs, CFAutoRelease<CTFontDescriptorRef> &&font, int pixels);
|
||||||
~CoreTextFontCache() {}
|
~CoreTextFontCache() {}
|
||||||
|
|
|
@ -284,20 +284,6 @@ void Win32FontCache::ClearFontCache()
|
||||||
return allow_fallback && key >= SCC_SPRITE_START && key <= SCC_SPRITE_END ? this->parent->MapCharToGlyph(key) : 0;
|
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<BYTE>(len);
|
|
||||||
GetFontData(this->dc, tag, 0, result, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
length = len;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static bool TryLoadFontFromFile(const std::string &font_name, LOGFONT &logfont)
|
static bool TryLoadFontFromFile(const std::string &font_name, LOGFONT &logfont)
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,7 +28,6 @@ private:
|
||||||
void SetFontSize(int pixels);
|
void SetFontSize(int pixels);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const void *InternalGetFontTable(uint32_t tag, size_t &length) override;
|
|
||||||
const Sprite *InternalGetGlyph(GlyphID key, bool aa) override;
|
const Sprite *InternalGetGlyph(GlyphID key, bool aa) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -30,7 +30,6 @@ public:
|
||||||
uint GetGlyphWidth(GlyphID) override { return this->height / 2; }
|
uint GetGlyphWidth(GlyphID) override { return this->height / 2; }
|
||||||
bool GetDrawGlyphShadow() override { return false; }
|
bool GetDrawGlyphShadow() override { return false; }
|
||||||
GlyphID MapCharToGlyph(char32_t key, [[maybe_unused]] bool allow_fallback = true) override { return key; }
|
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"; }
|
std::string GetFontName() override { return "mock"; }
|
||||||
bool IsBuiltInFont() override { return true; }
|
bool IsBuiltInFont() override { return true; }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue