Prevents the setlocale system call from being called repeatedly.
Change-Id: Ibd00d7e0f8145a4a6aa305a3ba4997c351acbd18
Signed-off-by: Bowon Ryu <bowon.ryu@samsung.com>
Internal::FontClient::JoinFontThreads();
}
+void EnsureLocale()
+{
+ Internal::FontClient::EnsureLocale();
+}
+
+const std::string& GetLocale()
+{
+ return Internal::FontClient::GetLocale();
+}
+
+const std::string& GetLocaleFull()
+{
+ return Internal::FontClient::GetLocaleFull();
+}
+
+void SetLocale(const std::string& locale)
+{
+ Internal::FontClient::SetLocale(locale);
+}
+
} // namespace TextAbstraction
} // namespace Dali
DALI_ADAPTOR_API void FontClientFontPreLoad(const FontPathList& fontPathList, const FontPathList& memoryFontPathList, bool useThread, bool syncCreation);
/**
- * @brief Joins font threads, waiting for their execution to complete.
- */
+ * @brief Joins font threads, waiting for their execution to complete.
+ */
DALI_ADAPTOR_API void FontClientJoinFontThreads();
+/**
+ * @brief Ensure the locale of the font client.
+ * @note If there is no locale information, update it using setlocale().
+ */
+DALI_ADAPTOR_API void EnsureLocale();
+
+/**
+ * @brief Gets the current language.
+ *
+ * @note Returns the language code. (e.g., "en")
+ * @return The current language.
+ */
+DALI_ADAPTOR_API const std::string& GetLocale();
+
+/**
+ * @brief Gets the current locale identifier.
+ *
+ * @note Returns the locale identifier. (e.g., "en_US")
+ * @return The current locale identifier.
+ */
+DALI_ADAPTOR_API const std::string& GetLocaleFull();
+
+/**
+ * @brief Sets the current locale.
+ *
+ * @note Update language and locale identifier.
+ * @param[in] locale The current locale.
+ */
+DALI_ADAPTOR_API void SetLocale(const std::string& locale);
+
} // namespace TextAbstraction
} // namespace Dali
mCore->Initialize();
SetupSystemInformation();
+ TextAbstraction::EnsureLocale();
// Start the callback manager
mCallbackManager->Start();
Adaptor* adaptor = static_cast<Adaptor*>(data);
if(adaptor != NULL)
{
+ TextAbstraction::SetLocale(locale);
TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
fontClient.ClearCacheOnLocaleChanged();
fontClient.InitDefaultFontDescription();
std::thread mThread;
};
+std::string gLocale; // The current language. (e.g., "en")
+std::string gLocaleFull; // The current locale identifier. (e.g., "en_US")
+
Dali::TextAbstraction::FontClient FontClient::gPreCreatedFontClient(NULL);
FontThread gPreCacheThread;
}
}
+void FontClient::EnsureLocale()
+{
+ if(gLocale.empty() || gLocaleFull.empty())
+ {
+ const char *locale;
+ locale = setlocale(LC_MESSAGES, NULL);
+ if(locale)
+ {
+ SetLocale(locale);
+ }
+ }
+}
+
+const std::string& FontClient::GetLocale()
+{
+ return gLocale;
+}
+
+const std::string& FontClient::GetLocaleFull()
+{
+ return gLocaleFull;
+}
+
+void FontClient::SetLocale(const std::string& locale)
+{
+ std::scoped_lock lock(gMutex);
+
+ // To unify the tizen system locale and format, remove the string after the dot.
+ std::istringstream stringStreamFull(locale);
+ std::getline(stringStreamFull, gLocaleFull, '.');
+ std::istringstream stringStream(locale);
+ std::getline(stringStream, gLocale, '_');
+}
+
void FontClient::ClearCache()
{
if(mPlugin)
*/
static void JoinFontThreads();
+ /**
+ * @brief Ensure the locale of the font client.
+ * @note If there is no locale information, update it using setlocale().
+ */
+ static void EnsureLocale();
+
+ /**
+ * @brief Gets the current language. (e.g., "en")
+ */
+ static const std::string& GetLocale();
+
+ /**
+ * @brief Gets the current locale identifier. (e.g., "en_US")
+ */
+ static const std::string& GetLocaleFull();
+
+ /**
+ * @brief Update language and locale identifier.
+ */
+ static void SetLocale(const std::string& locale);
+
/**
* @copydoc Dali::TextAbstraction::FontClient::ClearCache()
*/
hb_buffer_set_script(harfBuzzBuffer,
SCRIPT_TO_HARFBUZZ[script]); /* see hb-unicode.h */
- char* currentLocale = setlocale(LC_MESSAGES, NULL);
-
- std::istringstream stringStream(currentLocale);
- std::string localeString;
- std::getline(stringStream, localeString, '_');
+ const std::string& localeString = TextAbstraction::GetLocale();
hb_buffer_set_language(harfBuzzBuffer, hb_language_from_string(localeString.c_str(), localeString.size()));
/* Layout the text */