Files
MeowOS-For-R3P2/patch_v2/reader_app/app/progress.c
T
MeowOS 553a7d5d9e reader R1: os.meow.reader 书架+TXT 垂直链路骨架
- core: 编码检测(BOM→UTF-8严格→GB18030/Big5统计, Big5与GB重叠按GB18030兜底, §3.5风险注明)
  + GB18030双字节码表(uint16[126][190]=47880B, tools/gen_gb18030_table.py 生成, 生成物入仓)
  + 流式排版器(贪心断行+Kinsoku避头尾+分页+重排锚定, rd_meas_fn 测量回调替 FreeType, 宿主可测)
  + TXT 流式加载器(按段读, 不整文件入内存, \n 恒独立换行可安全分段)
- engine: FreeType 封装(FT_New_Face 按需读文件, NO_HINTING/LIGHT 灰阶, LRU 512 key=码点+字号,
  blend565, rdft_advance 只测宽不栅格化)
- app: 书架(扫 Books/ 识别 5 后缀, 最近读置顶, 空态提示) + 阅读页(W_CUSTOM 画布 3 栏翻页
  +中央菜单占位(字号±/行距±/返回) +顶栏进度%/章节名) + 书桥(段表+flat 页索引, 渲染, 重排回锚)
  + 进度持久化(MeowData/os.meow.reader/progress/, path hash→seg/ch/fs/ls/ts)
- 取舍: 正文字体 FreeType 直读 TF MeowOS/fonts/ TTF/OTF; 无字体回退 SDK 位图字库(meow_ui_text,
  未打包字体(许可/体积), 全 glyph 兜底 R2); 页位图缓存当前+前后各1页(3×691KB), 翻页动画默认无
- 内存实测(宿主 --wrap malloc, 73页书): 书结构 130KB + 当前段刮擦~1.6MB(行/页容量按 n 偏高,R2 收紧)
  + 字形缓存~650KB + 3页位图 2.07MB ≈ 4.45MB 动态, 在 ≤8MB 阅读态预算内
- 测试: 宿主 core 58/58(enc/gb18030金标准/kinsoku/page/reflow/txt); qemu-mipsel ft_smoke PASS
  + book_smoke(12页/渲染有墨/翻页/重排回锚) PASS; reader 交叉 -Wall -Wextra 0 warning
- 产物: reader(mipsel 静态1.2MB)+build_reader.sh(vendor FreeType 可复现); vendor/二进制 gitignore
2026-09-01 23:26:42 +08:00

103 lines
3.5 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* app/progress.c — 进度持久化(实现见 app/progress.h)。 */
#include "progress.h"
#include "meow_ui.h" /* meow_config_dir() */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
/* 从 MEOW_DATA_DIR(<TF>/MeowData/<pkg>/data)剥掉尾 "/data",得到 <TF>/MeowData/<pkg>。 */
static void strip_data_suffix(const char *d, char *out, int outsz)
{
if (!d || !d[0]) { strncpy(out, "/tmp", (size_t)outsz - 1); out[outsz - 1] = 0; return; }
size_t n = strlen(d);
const char *suffix = "/data";
size_t sl = strlen(suffix);
size_t keep;
if (n >= sl && strcmp(d + n - sl, suffix) == 0) keep = n - sl;
else keep = n;
if (keep >= (size_t)outsz) keep = (size_t)outsz - 1;
memcpy(out, d, keep);
out[keep] = 0;
}
int rdprog_dir(char *out, int outsz)
{
if (!out || outsz <= 0) return -1;
const char *data = meow_config_dir();
char base[360];
strip_data_suffix(data ? data : "", base, sizeof base);
if (snprintf(out, (size_t)outsz, "%s/progress", base) >= outsz) return -2;
/* mkdir -p */
char tmp[400];
strncpy(tmp, out, sizeof tmp - 1); tmp[sizeof tmp - 1] = 0;
for (char *p = tmp + 1; *p; p++) {
if (*p == '/') { *p = 0; mkdir(tmp, 0755); *p = '/'; }
}
mkdir(tmp, 0755);
return 0;
}
void rdprog_hash(const char *book_path, char *out, int outsz)
{
uint32_t h = 2166136261u;
for (const unsigned char *p = (const unsigned char *)book_path; *p; p++) {
h ^= *p; h *= 16777619u;
}
snprintf(out, (size_t)outsz, "%08x.prog", h);
}
static int rdprog_path(const char *book_path, char *out, int outsz,
int *created_dir)
{
char dir[400];
if (rdprog_dir(dir, sizeof dir) != 0) return -1;
char name[24];
rdprog_hash(book_path, name, sizeof name);
if (snprintf(out, (size_t)outsz, "%s/%s", dir, name) >= outsz) return -2;
if (created_dir) *created_dir = 1;
return 0;
}
int rdprog_load(const char *book_path, rdprog *p)
{
if (!book_path || !p) return -1;
char path[440];
if (rdprog_path(book_path, path, sizeof path, NULL) != 0) return -1;
FILE *f = fopen(path, "rb");
if (!f) return 0;
char line[256];
int seg = 0, fs = 0, ls = 0; int32_t ch = 0; uint64_t ts = 0; int v = 0, found = 0;
while (fgets(line, sizeof line, f)) {
if (sscanf(line, "v=%d", &v) == 1) { if (v == 1) found = 1; }
else if (sscanf(line, "seg=%d", &seg) == 1) { /* no-op */ }
else if (sscanf(line, "ch=%d", &ch) == 1) { /* no-op */ }
else if (sscanf(line, "fs=%d", &fs) == 1) { /* no-op */ }
else if (sscanf(line, "ls=%d", &ls) == 1) { /* no-op */ }
else if (sscanf(line, "ts=%llu", (unsigned long long *)&ts) == 1) { /* no-op */ }
}
fclose(f);
if (!found) return 0;
p->valid = 1; p->seg = seg; p->ch = ch; p->fs = fs; p->ls = ls; p->ts = ts;
return 1;
}
int rdprog_save(const char *book_path, const rdprog *p)
{
if (!book_path || !p) return -1;
char path[440];
if (rdprog_path(book_path, path, sizeof path, NULL) != 0) return -1;
FILE *f = fopen(path, "wb");
if (!f) return -1;
/* 先写临时再改原子(exFAT 无 rename+replace 语义保证,直接写亦可接受) */
fprintf(f, "v=1\n");
fprintf(f, "seg=%d\n", p->seg);
fprintf(f, "ch=%d\n", (int)p->ch);
fprintf(f, "fs=%d\n", p->fs);
fprintf(f, "ls=%d\n", p->ls);
fprintf(f, "ts=%llu\n", (unsigned long long)p->ts);
fclose(f);
return 0;
}