Font loading for macOS

This commit is contained in:
Edward Li 2021-02-01 19:40:12 +08:00
parent 7d73920ac2
commit 98c4343410
2 changed files with 27 additions and 1 deletions

View File

@ -203,7 +203,29 @@ void gui_init()
default: default:
break; break;
} }
// TODO linux, macOS, Android... #elif __APPLE__
std::string fontDir = std::string("/System/Library/Fonts/");
extern std::string os_Locale();
std::string locale = os_Locale();
if (locale.find("ja") == 0) // Japanese
{
io.Fonts->AddFontFromFileTTF((fontDir + "ヒラギノ角ゴシック W4.ttc").c_str(), 17.f * scaling, &font_cfg, io.Fonts->GetGlyphRangesJapanese());
}
else if (locale.find("ko") == 0) // Korean
{
io.Fonts->AddFontFromFileTTF((fontDir + "AppleSDGothicNeo.ttc").c_str(), 17.f * scaling, &font_cfg, io.Fonts->GetGlyphRangesKorean());
}
else if (locale.find("zh_Hant") == 0) // Traditional Chinese
{
io.Fonts->AddFontFromFileTTF((fontDir + "PingFang.ttc").c_str(), 17.f * scaling, &font_cfg, GetGlyphRangesChineseTraditionalOfficial());
}
else if (locale.find("zh_Hans") == 0) // Simplified Chinese
{
io.Fonts->AddFontFromFileTTF((fontDir + "PingFang.ttc").c_str(), 17.f * scaling, &font_cfg, GetGlyphRangesChineseSimplifiedOfficial());
}
// TODO linux, Android...
#endif #endif
INFO_LOG(RENDERER, "Screen DPI is %d, size %d x %d. Scaling by %.2f", screen_dpi, screen_width, screen_height, scaling); INFO_LOG(RENDERER, "Screen DPI is %d, size %d x %d. Scaling by %.2f", screen_dpi, screen_width, screen_height, scaling);

View File

@ -248,3 +248,7 @@ extern "C" void emu_set_mouse_position(int x, int y, int width, int height)
{ {
SetMousePosition(x, y, width, height); SetMousePosition(x, y, width, height);
} }
std::string os_Locale(){
return [[[NSLocale autoupdatingCurrentLocale] localeIdentifier] UTF8String];
}