From daadc2ea71a96181acc17b2e3f79ce7e31b96deb Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 14 Mar 2023 12:30:28 +0100 Subject: [PATCH] impr: Attempt loading of full unicode plane from font if possible --- main/source/init/splash_window.cpp | 5 +++-- main/source/init/tasks.cpp | 28 +++++++++++++++++++--------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/main/source/init/splash_window.cpp b/main/source/init/splash_window.cpp index a4740e92f..0538a15dd 100644 --- a/main/source/init/splash_window.cpp +++ b/main/source/init/splash_window.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -278,7 +279,7 @@ namespace hex::init { std::uint8_t *px; int w, h; io.Fonts->AddFontFromMemoryCompressedTTF(font_awesome_compressed_data, font_awesome_compressed_size, 11.0_scaled, &cfg, fontAwesomeRange); - io.Fonts->GetTexDataAsRGBA32(&px, &w, &h); + io.Fonts->GetTexDataAsAlpha8(&px, &w, &h); // Create new font atlas GLuint tex; @@ -286,7 +287,7 @@ namespace hex::init { glBindTexture(GL_TEXTURE_2D, tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA8, GL_UNSIGNED_INT, px); + glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, w, h, 0, GL_ALPHA, GL_UNSIGNED_BYTE, px); io.Fonts->SetTexID(reinterpret_cast(tex)); } diff --git a/main/source/init/tasks.cpp b/main/source/init/tasks.cpp index 61a900a03..baf446eb0 100644 --- a/main/source/init/tasks.cpp +++ b/main/source/init/tasks.cpp @@ -118,28 +118,38 @@ namespace hex::init { // Setup basic font configuration auto fonts = IM_NEW(ImFontAtlas)(); ImFontConfig cfg = {}; - cfg.OversampleH = cfg.OversampleV = 1, cfg.PixelSnapH = true; + cfg.OversampleH = cfg.OversampleV = 2, cfg.PixelSnapH = true; cfg.SizePixels = fontSize; + fonts->Flags |= ImFontAtlasFlags_NoPowerOfTwoHeight; + // Configure font glyph ranges that should be loaded from the default font and unifont ImVector ranges; { ImFontGlyphRangesBuilder glyphRangesBuilder; - glyphRangesBuilder.AddRanges(fonts->GetGlyphRangesDefault()); - glyphRangesBuilder.AddRanges(fonts->GetGlyphRangesJapanese()); - glyphRangesBuilder.AddRanges(fonts->GetGlyphRangesChineseFull()); - glyphRangesBuilder.AddRanges(fonts->GetGlyphRangesCyrillic()); - glyphRangesBuilder.AddRanges(fonts->GetGlyphRangesKorean()); - glyphRangesBuilder.AddRanges(fonts->GetGlyphRangesThai()); - glyphRangesBuilder.AddRanges(fonts->GetGlyphRangesVietnamese()); { - constexpr static ImWchar controlCodeRange[] = { 0x0000, 0x001F, 0 }; + constexpr static ImWchar controlCodeRange[] = { 0x0001, 0x001F, 0 }; constexpr static ImWchar extendedAsciiRange[] = { 0x007F, 0x00FF, 0 }; + glyphRangesBuilder.AddRanges(controlCodeRange); + glyphRangesBuilder.AddRanges(fonts->GetGlyphRangesDefault()); glyphRangesBuilder.AddRanges(extendedAsciiRange); } + if (loadUnicode) { + constexpr static ImWchar fullRange[] = { 0x0100, 0xFFEF, 0 }; + + glyphRangesBuilder.AddRanges(fullRange); + } else { + glyphRangesBuilder.AddRanges(fonts->GetGlyphRangesJapanese()); + glyphRangesBuilder.AddRanges(fonts->GetGlyphRangesChineseFull()); + glyphRangesBuilder.AddRanges(fonts->GetGlyphRangesCyrillic()); + glyphRangesBuilder.AddRanges(fonts->GetGlyphRangesKorean()); + glyphRangesBuilder.AddRanges(fonts->GetGlyphRangesThai()); + glyphRangesBuilder.AddRanges(fonts->GetGlyphRangesVietnamese()); + } + glyphRangesBuilder.BuildRanges(&ranges); }