From 0ed75153552aa3a7279d27656a52ab4e6fef09e2 Mon Sep 17 00:00:00 2001 From: Aleksander Guryanov Date: Thu, 22 Jun 2017 16:10:34 +0700 Subject: [PATCH] Support custom fonts --- cocos2dx/platform/CCCommon.h | 9 ++++++- .../platform/emscripten/CCApplication.cpp | 7 +++++- cocos2dx/platform/emscripten/CCImage.cpp | 3 ++- cocos2dx/platform/linux/CCApplication.cpp | 25 +++++++++++++++++++ 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/cocos2dx/platform/CCCommon.h b/cocos2dx/platform/CCCommon.h index b83b83efb..7ea224c56 100644 --- a/cocos2dx/platform/CCCommon.h +++ b/cocos2dx/platform/CCCommon.h @@ -70,7 +70,14 @@ enum class LanguageType PORTUGUESE, ARABIC, NORWEGIAN, - POLISH + POLISH, + // I don't know from where this codes + AFRIKAANS, + HINDI, + INDONESIAN, + SWAHILI, + THAI, + VIETNAMESE }; // END of platform group diff --git a/cocos2dx/platform/emscripten/CCApplication.cpp b/cocos2dx/platform/emscripten/CCApplication.cpp index 9c25570a0..058bf4962 100644 --- a/cocos2dx/platform/emscripten/CCApplication.cpp +++ b/cocos2dx/platform/emscripten/CCApplication.cpp @@ -99,7 +99,12 @@ LanguageType Application::getCurrentLanguage() char pLanguageName[16]; EM_ASM_ARGS({ - stringToUTF8(window.navigator.language.replace(/-.*/,''), $0, 16); + var lang = localStorage.getItem('localization_language'); + if (lang == null) { + stringToUTF8(window.navigator.language.replace(/-.*/,''), $0, 16); + } else { + stringToUTF8(lang, $0, 16); + } }, pLanguageName); if (0 == strcmp("zh", pLanguageName)) diff --git a/cocos2dx/platform/emscripten/CCImage.cpp b/cocos2dx/platform/emscripten/CCImage.cpp index a3cfda0d6..2776c274b 100644 --- a/cocos2dx/platform/emscripten/CCImage.cpp +++ b/cocos2dx/platform/emscripten/CCImage.cpp @@ -209,7 +209,8 @@ class BitmapDC const char* pText = text; int pxSize = (int)(fontSize); - TTF_Font *face = TTF_OpenFont("sans-serif", pxSize); + std::string fontName = std::string("\"") + pFontName + "\""; + TTF_Font *face = TTF_OpenFont(fontName.c_str(), pxSize); if(!face) { return false; diff --git a/cocos2dx/platform/linux/CCApplication.cpp b/cocos2dx/platform/linux/CCApplication.cpp index 47d249ad5..c59815594 100644 --- a/cocos2dx/platform/linux/CCApplication.cpp +++ b/cocos2dx/platform/linux/CCApplication.cpp @@ -174,6 +174,31 @@ LanguageType Application::getCurrentLanguage() { ret = LanguageType::POLISH; } + else if (0 == strcmp("vi", pLanguageName)) + { + ret = LanguageType::VIETNAMESE; + } + else if (0 == strcmp("th", pLanguageName)) + { + ret = LanguageType::THAI; + } + else if (0 == strcmp("hi", pLanguageName)) + { + ret = LanguageType::HINDI; + } + else if (0 == strcmp("sw", pLanguageName)) + { + ret = LanguageType::SWAHILI; + } + else if (0 == strcmp("id", pLanguageName)) + { + ret = LanguageType::INDONESIAN; + } + else if (0 == strcmp("af", pLanguageName)) + { + ret = LanguageType::AFRIKAANS; + } + return ret; }