Various things

Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2025-10-07 04:32:14 +03:00
parent 278f4c6df3
commit 64979c6e5c
3 changed files with 29 additions and 4 deletions

View File

@@ -6,6 +6,7 @@
#include <cstdlib>
#include <cstring>
#include <span>
#include <unordered_set>
#include <vector>
#include <poll.h>
#include <pthread.h>
@@ -303,15 +304,33 @@ auto App::init_egl() -> void
auto const font = find_font_path();
assert(font && "Could not find font");
std::vector<std::filesystem::path> fallback_paths;
std::unordered_set<std::string> 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));

View File

@@ -13,6 +13,7 @@
#include <unordered_map>
#include <utility>
#include <vector>
#include <limits>
#include <fontconfig/fontconfig.h>
@@ -635,7 +636,8 @@ auto TextRenderer::shape_text(FontHandle const font,
if (codepoints.empty())
return shaped;
std::vector<usize> selections(codepoints.size(), 0);
constexpr usize kNoFont = std::numeric_limits<usize>::max();
std::vector<usize> 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];

View File

@@ -30,7 +30,7 @@ auto App::tick() -> void
BeginDrawing();
ClearBackground(BLANK);
ClearBackground(theme().window.background);
DrawFPS(10, 10);
if (m_tr) {