From 64979c6e5c2ac0de7a683bce42fecdf477a8777f Mon Sep 17 00:00:00 2001 From: Slendi Date: Tue, 7 Oct 2025 04:32:14 +0300 Subject: [PATCH] Various things Signed-off-by: Slendi --- src/App.cpp | 21 ++++++++++++++++++++- src/TextRenderer.cpp | 10 ++++++++-- src/Tick.cpp | 2 +- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/App.cpp b/src/App.cpp index 7b0e184..a836895 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -303,15 +304,33 @@ auto App::init_egl() -> void auto const font = find_font_path(); assert(font && "Could not find font"); std::vector fallback_paths; + std::unordered_set seen_paths; + auto const primary_path_str = font->string(); + constexpr char const *fallback_candidates[] = { "Noto Sans CJK JP:style=Regular", "Noto Sans CJK SC:style=Regular", "Noto Sans CJK KR:style=Regular", "Noto Sans CJK TC:style=Regular", + "sans-serif:lang=ja", + "sans-serif:lang=ko", + "sans-serif:lang=zh-cn", + "sans-serif:lang=zh-tw", + "sans-serif:lang=zh-hk", }; for (auto const *name : fallback_candidates) { - if (auto fallback = find_font_path(name)) + if (auto fallback = find_font_path(name)) { + auto const path_str = fallback->string(); + if (path_str == primary_path_str) + continue; + if (!seen_paths.emplace(path_str).second) + continue; fallback_paths.push_back(*fallback); + } + } + if (fallback_paths.empty()) { + TraceLog(LOG_WARNING, + "No fallback fonts found; some glyphs may render as missing"); } auto const font_handle = m_tr->load_font(*font, std::span(fallback_paths)); diff --git a/src/TextRenderer.cpp b/src/TextRenderer.cpp index a369da7..695d027 100644 --- a/src/TextRenderer.cpp +++ b/src/TextRenderer.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include @@ -635,7 +636,8 @@ auto TextRenderer::shape_text(FontHandle const font, if (codepoints.empty()) return shaped; - std::vector selections(codepoints.size(), 0); + constexpr usize kNoFont = std::numeric_limits::max(); + std::vector selections(codepoints.size(), kNoFont); for (size_t i = 0; i < codepoints.size(); ++i) { bool matched = false; for (size_t candidate = 0; candidate < font_set.font_indices.size(); @@ -655,12 +657,16 @@ auto TextRenderer::shape_text(FontHandle const font, } } if (!matched) - selections[i] = 0; + selections[i] = kNoFont; } size_t idx = 0; while (idx < codepoints.size()) { size_t font_choice = selections[idx]; + if (font_choice == kNoFont) { + ++idx; + continue; + } if (font_choice >= font_set.font_indices.size()) font_choice = 0; usize runtime_index = font_set.font_indices[font_choice]; diff --git a/src/Tick.cpp b/src/Tick.cpp index bb531f9..5c333fe 100644 --- a/src/Tick.cpp +++ b/src/Tick.cpp @@ -30,7 +30,7 @@ auto App::tick() -> void BeginDrawing(); - ClearBackground(BLANK); + ClearBackground(theme().window.background); DrawFPS(10, 10); if (m_tr) {