Skip to content

Commit

Permalink
ImGuiManager: Don't rasterize full glyph range for debug font
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Sep 2, 2024
1 parent 164a353 commit 4c51337
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/util/imgui_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static void SetKeyMap();
static bool LoadFontData();
static void ReloadFontDataIfActive();
static bool AddImGuiFonts(bool fullscreen_fonts);
static ImFont* AddTextFont(float size);
static ImFont* AddTextFont(float size, bool full_glyph_range);
static ImFont* AddFixedFont(float size);
static bool AddIconFonts(float size);
static void AcquirePendingOSDMessages(Common::Timer::Value current_time);
Expand All @@ -81,6 +81,8 @@ static void DrawSoftwareCursor(const SoftwareCursor& sc, const std::pair<float,
static float s_global_prescale = 1.0f; // before window scale
static float s_global_scale = 1.0f;

static constexpr std::array<ImWchar, 4> s_ascii_font_range = {{0x20, 0x7F, 0x00, 0x00}};

static std::string s_font_path;
static std::vector<WCharType> s_font_range;
static std::vector<WCharType> s_emoji_range;
Expand Down Expand Up @@ -583,20 +585,21 @@ bool ImGuiManager::LoadFontData()
return true;
}

ImFont* ImGuiManager::AddTextFont(float size)
ImFont* ImGuiManager::AddTextFont(float size, bool full_glyph_range)
{
ImFontConfig cfg;
cfg.FontDataOwnedByAtlas = false;
return ImGui::GetIO().Fonts->AddFontFromMemoryTTF(
s_standard_font_data.data(), static_cast<int>(s_standard_font_data.size()), size, &cfg, s_font_range.data());
return ImGui::GetIO().Fonts->AddFontFromMemoryTTF(s_standard_font_data.data(),
static_cast<int>(s_standard_font_data.size()), size, &cfg,
full_glyph_range ? s_font_range.data() : s_ascii_font_range.data());
}

ImFont* ImGuiManager::AddFixedFont(float size)
{
ImFontConfig cfg;
cfg.FontDataOwnedByAtlas = false;
return ImGui::GetIO().Fonts->AddFontFromMemoryTTF(s_fixed_font_data.data(),
static_cast<int>(s_fixed_font_data.size()), size, &cfg, nullptr);
return ImGui::GetIO().Fonts->AddFontFromMemoryTTF(
s_fixed_font_data.data(), static_cast<int>(s_fixed_font_data.size()), size, &cfg, s_ascii_font_range.data());
}

bool ImGuiManager::AddIconFonts(float size)
Expand Down Expand Up @@ -661,27 +664,27 @@ bool ImGuiManager::AddImGuiFonts(bool fullscreen_fonts)
ImGuiIO& io = ImGui::GetIO();
io.Fonts->Clear();

s_standard_font = AddTextFont(standard_font_size);
s_standard_font = AddTextFont(standard_font_size, false);
if (!s_standard_font)
return false;

s_fixed_font = AddFixedFont(standard_font_size);
if (!s_fixed_font)
return false;

s_osd_font = AddTextFont(osd_font_size);
s_osd_font = AddTextFont(osd_font_size, true);
if (!s_osd_font || !AddIconFonts(osd_font_size))
return false;

if (fullscreen_fonts)
{
const float medium_font_size = ImGuiFullscreen::LayoutScale(ImGuiFullscreen::LAYOUT_MEDIUM_FONT_SIZE);
s_medium_font = AddTextFont(medium_font_size);
s_medium_font = AddTextFont(medium_font_size, true);
if (!s_medium_font || !AddIconFonts(medium_font_size))
return false;

const float large_font_size = ImGuiFullscreen::LayoutScale(ImGuiFullscreen::LAYOUT_LARGE_FONT_SIZE);
s_large_font = AddTextFont(large_font_size);
s_large_font = AddTextFont(large_font_size, true);
if (!s_large_font || !AddIconFonts(large_font_size))
return false;
}
Expand Down

0 comments on commit 4c51337

Please sign in to comment.