From b09ff326d11b1fb1afa126b6a478416db78e4dcb Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Sat, 22 Oct 2022 22:14:28 +0200 Subject: [PATCH] Clear the font cache on locale change --- src/text.cxx | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/text.cxx b/src/text.cxx index fc0495a..aed4449 100644 --- a/src/text.cxx +++ b/src/text.cxx @@ -77,6 +77,7 @@ struct TexText { class Cache { private: + std::string locale; std::unordered_map> list; public: @@ -91,12 +92,21 @@ public: return nullptr; } - void - Insert (const std::string & text, std::shared_ptr texText) + void Insert ( + const std::string & text, std::shared_ptr texText, + const std::string & locale) { + if (locale != this->locale) + { + this->Clear (); + this->locale = locale; + } + this->list.insert ( std::pair> (text, texText)); } + + void Clear () { this->list.clear (); } }; class Font @@ -174,9 +184,11 @@ public: int baseW = texText ? texText->baseW : 0; int baseH = texText ? texText->baseH : 0; - if (GetLocale () == "ar") + const auto locale = GetLocale (); + + if (locale == "ar") pos.y -= 2; - else if (GetLocale () == "he") + else if (locale == "he") pos.y -= 1; if (this->outline) @@ -242,7 +254,7 @@ public: std::shared_ptr _texText = std::make_shared ( texOutline, outlineW, outlineH, texBase, baseW, baseH, texOver); - this->cache.Insert (pText, _texText); + this->cache.Insert (pText, _texText, locale); } } };