Skip to content

Commit

Permalink
Support custom fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
caiiiycuk committed Jun 22, 2017
1 parent e4e285f commit 0ed7515
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
9 changes: 8 additions & 1 deletion cocos2dx/platform/CCCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion cocos2dx/platform/emscripten/CCApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion cocos2dx/platform/emscripten/CCImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 25 additions & 0 deletions cocos2dx/platform/linux/CCApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 0ed7515

Please sign in to comment.