mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use unique_ptr for text layout font mapping.
This must stay a pointer as the value passed to other structures.pull/10839/head
parent
c38df2d589
commit
bf8f24f9a8
|
@ -297,10 +297,10 @@ ptrdiff_t Layouter::GetCharAtPosition(int x) const
|
||||||
Font *Layouter::GetFont(FontSize size, TextColour colour)
|
Font *Layouter::GetFont(FontSize size, TextColour colour)
|
||||||
{
|
{
|
||||||
FontColourMap::iterator it = fonts[size].find(colour);
|
FontColourMap::iterator it = fonts[size].find(colour);
|
||||||
if (it != fonts[size].end()) return it->second;
|
if (it != fonts[size].end()) return it->second.get();
|
||||||
|
|
||||||
fonts[size][colour] = new Font(size, colour);
|
fonts[size][colour] = std::make_unique<Font>(size, colour);
|
||||||
return fonts[size][colour];
|
return fonts[size][colour].get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -309,9 +309,6 @@ Font *Layouter::GetFont(FontSize size, TextColour colour)
|
||||||
*/
|
*/
|
||||||
void Layouter::ResetFontCache(FontSize size)
|
void Layouter::ResetFontCache(FontSize size)
|
||||||
{
|
{
|
||||||
for (auto &pair : fonts[size]) {
|
|
||||||
delete pair.second;
|
|
||||||
}
|
|
||||||
fonts[size].clear();
|
fonts[size].clear();
|
||||||
|
|
||||||
/* We must reset the linecache since it references the just freed fonts */
|
/* We must reset the linecache since it references the just freed fonts */
|
||||||
|
|
|
@ -80,7 +80,7 @@ public:
|
||||||
Font(FontSize size, TextColour colour);
|
Font(FontSize size, TextColour colour);
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Mapping from index to font. */
|
/** Mapping from index to font. The pointer is owned by FontColourMap. */
|
||||||
using FontMap = std::map<int, Font *>;
|
using FontMap = std::map<int, Font *>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -169,7 +169,7 @@ private:
|
||||||
|
|
||||||
static LineCacheItem &GetCachedParagraphLayout(std::string_view str, const FontState &state);
|
static LineCacheItem &GetCachedParagraphLayout(std::string_view str, const FontState &state);
|
||||||
|
|
||||||
using FontColourMap = std::map<TextColour, Font *>;
|
using FontColourMap = std::map<TextColour, std::unique_ptr<Font>>;
|
||||||
static FontColourMap fonts[FS_END];
|
static FontColourMap fonts[FS_END];
|
||||||
public:
|
public:
|
||||||
static Font *GetFont(FontSize size, TextColour colour);
|
static Font *GetFont(FontSize size, TextColour colour);
|
||||||
|
|
Loading…
Reference in New Issue