perf(reader): M31 字体路径记忆化(开书字体查找 35 目录 walk → 1 次 stat)+ 「· 读」徽标即时刷新
字体:find_font_rec/resolve_font 从 reader.c 抽到 app/font_resolve.c 并加进程内记忆化。 只缓存成功路径;命中后仍做一次 access() 校验(字库被删即重扫);没找到不缓存, 用户之后拷入的字库下次开书即可找到。顶栏「刷新」额外调 font_cache_invalidate(), 给「新拷入字库、旧字库仍在」一条显式失效路径。宿主实测:35 目录树 walk 0.026~0.54ms (=300+ 次系统调用)vs 命中 0.001ms(1 次 access);开书路径每次省一次完整 walk。 徽标:副题格式化抽成 shelf_fmt_sub()(扫描与「刚读完置顶」共用一份实现), promote_just_read() 改 ts 后立即重算这本的 sub/sub_folder,「· 读」不再等下次全量刷新。 回归:test_reader_core 6846、shelf_group_smoke 63(+8)、font_resolve_smoke 14 全绿; build_reader.sh 0 warning;扫描缓存/进度语义未改。app.json 0.1.3/code4 → 0.1.4/code5。
This commit is contained in:
1 parent
0b30cdbafb
commit
dc9bfdbdaf
12 files changed
+460
-53
No files matched your search
@@ -8,10 +8,10 @@
|
||||
#include "../reader_internal.h"
|
||||
#include "meow_ui_internal.h" /* back_buf/pitch/bpp 访问器(决策见报告) */
|
||||
#include "book.h"
|
||||
#include "font_resolve.h"
|
||||
#include "progress.h"
|
||||
#include "reader_conf.h"
|
||||
#include "rdchapter.h" /* RDCHAP_TITLE_MAX(章节标题) */
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -45,7 +45,6 @@ static int g_jump_scroll; /* 列表滚动(首行项下标) */
|
||||
static char g_jump_buf[8]; /* 章内/段内页码输入缓冲(ASCII 数字) */
|
||||
static int g_chap_cache_idx = -1; /* 章节范围缓存(章起/止页;随字号/行距重排失效) */
|
||||
static int g_chap_cache_start, g_chap_cache_end;
|
||||
static char g_font_path[400];
|
||||
static int g_notice_ms;
|
||||
|
||||
/* ---- R3 翻页动画(轻量水平滑入) ---- */
|
||||
@@ -141,39 +140,10 @@ static void reader_set_bg(const char *bg)
|
||||
reader_redraw();
|
||||
}
|
||||
|
||||
/* 递归(深度≤3)扫 MeowOS/fonts/ 找第一个 .otf/.ttf。0=找到。 */
|
||||
static int find_font_rec(const char *dir, int depth)
|
||||
{
|
||||
if (depth > 3) return 0;
|
||||
DIR *dp = opendir(dir);
|
||||
if (!dp) return 0;
|
||||
struct dirent *de;
|
||||
int found = 0;
|
||||
while ((de = readdir(dp)) && !found) {
|
||||
if (de->d_name[0] == '.') continue;
|
||||
char full[480];
|
||||
if (snprintf(full, sizeof full, "%s/%s", dir, de->d_name) >= (int)sizeof full) continue;
|
||||
struct stat st;
|
||||
if (stat(full, &st) != 0) continue;
|
||||
if (S_ISDIR(st.st_mode)) { found = find_font_rec(full, depth + 1); }
|
||||
else {
|
||||
const char *d = strrchr(de->d_name, '.');
|
||||
if (d && (strcasecmp(d, ".otf") == 0 || strcasecmp(d, ".ttf") == 0)) {
|
||||
if (strlen(full) < sizeof g_font_path) {
|
||||
strcpy(g_font_path, full);
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dp);
|
||||
return found;
|
||||
}
|
||||
/* MeowOS/fonts/ 找第一个 .otf/.ttf(M31:路径进程内记忆化,见 font_resolve.c)。 */
|
||||
static const char *resolve_font(void)
|
||||
{
|
||||
g_font_path[0] = 0;
|
||||
if (find_font_rec(READER_SD_ROOT "/MeowOS/fonts", 0)) return g_font_path;
|
||||
return NULL;
|
||||
return font_resolve(READER_SD_ROOT "/MeowOS/fonts");
|
||||
}
|
||||
|
||||
static void chapter_name(void)
|
||||
|
||||
Reference in new issue
Block a user