1
0
mirror of https://github.com/blupi-games/planetblupi synced 2024-12-30 10:15:36 +01:00

Clear the font cache on locale change

This commit is contained in:
Mathieu Schroeter 2022-10-22 22:14:28 +02:00
parent 745f3c3cd0
commit b09ff326d1
No known key found for this signature in database
GPG Key ID: 8B9145A5FA9DA8A8

View File

@ -77,6 +77,7 @@ struct TexText {
class Cache class Cache
{ {
private: private:
std::string locale;
std::unordered_map<std::string, std::shared_ptr<struct TexText>> list; std::unordered_map<std::string, std::shared_ptr<struct TexText>> list;
public: public:
@ -91,12 +92,21 @@ public:
return nullptr; return nullptr;
} }
void void Insert (
Insert (const std::string & text, std::shared_ptr<struct TexText> texText) const std::string & text, std::shared_ptr<struct TexText> texText,
const std::string & locale)
{ {
if (locale != this->locale)
{
this->Clear ();
this->locale = locale;
}
this->list.insert ( this->list.insert (
std::pair<std::string, std::shared_ptr<struct TexText>> (text, texText)); std::pair<std::string, std::shared_ptr<struct TexText>> (text, texText));
} }
void Clear () { this->list.clear (); }
}; };
class Font class Font
@ -174,9 +184,11 @@ public:
int baseW = texText ? texText->baseW : 0; int baseW = texText ? texText->baseW : 0;
int baseH = texText ? texText->baseH : 0; int baseH = texText ? texText->baseH : 0;
if (GetLocale () == "ar") const auto locale = GetLocale ();
if (locale == "ar")
pos.y -= 2; pos.y -= 2;
else if (GetLocale () == "he") else if (locale == "he")
pos.y -= 1; pos.y -= 1;
if (this->outline) if (this->outline)
@ -242,7 +254,7 @@ public:
std::shared_ptr<struct TexText> _texText = std::shared_ptr<struct TexText> _texText =
std::make_shared<struct TexText> ( std::make_shared<struct TexText> (
texOutline, outlineW, outlineH, texBase, baseW, baseH, texOver); texOutline, outlineW, outlineH, texBase, baseW, baseH, texOver);
this->cache.Insert (pText, _texText); this->cache.Insert (pText, _texText, locale);
} }
} }
}; };