Skip to content

Commit

Permalink
Adjusted font ranges; applied font atlas changes to ChatOverlay
Browse files Browse the repository at this point in the history
  • Loading branch information
123jimin committed Apr 16, 2021
1 parent dad6426 commit e37e525
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 43 deletions.
1 change: 1 addition & 0 deletions Main/include/GuiUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class BasicNuklearGui : public IApplicationTickable

private:
void InitNuklearFontAtlas();
void InitNuklearFontAtlasFallback(struct nk_font_atlas* atlas, float fontSize);
};

class BasicWindow : public BasicNuklearGui
Expand Down
29 changes: 3 additions & 26 deletions Main/src/ChatOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,31 +53,8 @@ void ChatOverlay::InitNuklearIfNeeded()
nk_sdl_font_stash_begin(&atlas);
struct nk_font *fallback = nk_font_atlas_add_from_file(atlas, Path::Normalize( Path::Absolute("fonts/settings/NotoSans-Regular.ttf")).c_str(), 24, 0);

// struct nk_font_config cfg_kr = nk_font_config(24);
// cfg_kr.merge_mode = nk_true;
// cfg_kr.range = nk_font_korean_glyph_ranges();

// NK_STORAGE const nk_rune jp_ranges[] = {
// 0x0020, 0x00FF,
// 0x3000, 0x303f,
// 0x3040, 0x309f,
// 0x30a0, 0x30ff,
// 0x4e00, 0x9faf,
// 0xff00, 0xffef,
// 0
// };
// struct nk_font_config cfg_jp = nk_font_config(24);
// cfg_jp.merge_mode = nk_true;
// cfg_jp.range = jp_ranges;

NK_STORAGE const nk_rune cjk_ranges[] = {
0x0020, 0x00FF,
0x3000, 0x30FF,
0x3131, 0x3163,
0xAC00, 0xD79D,
0x31F0, 0x31FF,
0xFF00, 0xFFEF,
0x4e00, 0x9FAF,
0x0E3F, 0xFFFF,
0
};

Expand All @@ -93,9 +70,9 @@ void ChatOverlay::InitNuklearIfNeeded()
nk_font_atlas_add_from_file(atlas, Path::Normalize(Path::Absolute("fonts/settings/DroidSansFallback.ttf")).c_str(), 24, &cfg_cjk);
}

nk_sdl_font_stash_end();
usc_nk_sdl_font_stash_end();
nk_font_atlas_cleanup(atlas);
//nk_style_load_all_cursors(m_nctx, atlas->cursors);

nk_style_set_font(m_nctx, &fallback->handle);
}

Expand Down
58 changes: 41 additions & 17 deletions Main/src/GuiUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,41 +72,65 @@ static void ExtendFontAtlas(struct nk_font_atlas* atlas, const std::string_view&

void BasicNuklearGui::InitNuklearFontAtlas()
{
// This font should cover latin and cyrillic fonts.
const String defaultFontPath = Path::Normalize(Path::Absolute("fonts/settings/NotoSans-Regular.ttf"));
const String cjkFontPath = Path::Normalize(Path::Absolute("fonts/settings/DroidSansFallback.ttf"));
const float fontSize = 24.f;

struct nk_font_atlas* atlas;
nk_sdl_font_stash_begin(&atlas);

struct nk_font* font = nk_font_atlas_add_from_file(atlas, defaultFontPath.data(), fontSize, 0);

static const nk_rune cjk_ranges[] = {
0x0020, 0x00FF,
// Chinese
0x3000, 0x30FF,
if (!g_gameConfig.GetBool(GameConfigKeys::LimitSettingsFont))
{
InitNuklearFontAtlasFallback(atlas, fontSize);
}

usc_nk_sdl_font_stash_end();
nk_font_atlas_cleanup(atlas);

nk_style_set_font(m_nctx, &font->handle);
}

void BasicNuklearGui::InitNuklearFontAtlasFallback(struct nk_font_atlas* atlas, float fontSize)
{
const String cjkFontPath = Path::Normalize(Path::Absolute("fonts/settings/DroidSansFallback.ttf"));

// Essentials
constexpr int CJK_SIZE_SMALL = 1024;
static const nk_rune cjk_ranges_small[] = {
// CJK symbols and punctuation
0x3000, 0x303F,
// Hiragana
0x3040, 0x309F,
// Katakana
0x30A0, 0x30FF,
0x31F0, 0x31FF,
// Fullwidth and halfwidth characters
0xFF00, 0xFFEF,
0x4E00, 0x9FAF,
// Korean
0x3131, 0x3163,
0xAC00, 0xD7A3,
0
};

// Basically all BMP characters in the font file
constexpr int CJK_SIZE_LARGE = 8192;
static const nk_rune cjk_ranges_large[] = {
0x0E3F, 0xFFFF,
0
};

int maxTextureSize = 0;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
Logf("System max texture size: %d", Logger::Severity::Info, maxTextureSize);
Logf("System max texture size: %d (cjk small: %d / large: %d)", Logger::Severity::Info,
maxTextureSize, CJK_SIZE_SMALL, CJK_SIZE_LARGE);

if (maxTextureSize >= FULL_FONT_TEXTURE_HEIGHT && !g_gameConfig.GetBool(GameConfigKeys::LimitSettingsFont))
if (maxTextureSize >= CJK_SIZE_LARGE)
{
ExtendFontAtlas(atlas, cjkFontPath, fontSize, cjk_ranges);
ExtendFontAtlas(atlas, cjkFontPath, fontSize, cjk_ranges_large);
}
else if (maxTextureSize >= CJK_SIZE_SMALL)
{
ExtendFontAtlas(atlas, cjkFontPath, fontSize, cjk_ranges_small);
}

usc_nk_sdl_font_stash_end();
nk_font_atlas_cleanup(atlas);

nk_style_set_font(m_nctx, &font->handle);
}

void BasicNuklearGui::Tick(float deltatime)
Expand Down

0 comments on commit e37e525

Please sign in to comment.