feat(tuku): M7 条漫模式与续读——模式一键切换/每册记忆、视口±1 懒解码、滑块跳页、册间衔接
- 条漫:meow_scroll 跟手+fling,按滚动位置懒解码视口±1 页(驻留上限 4 页); 排版用 mr_book_meta 累加适宽高度(nav.c 纯逻辑,宿主可测) - 模式:阅读 chrome 图标一键切翻页/条漫;每册模式与 last page 经 meow_config 持久化 (reader.mode/page.<FNV1a64(册路径)>),重进该册恢复模式与页码 - 续读:离开/翻页/滚动停止节流落盘;书库扫描给含图册副标题追加「· 续读 Pn」 - 册间衔接:末页前进→同父目录下一含图册首页,首页后退→上一册末页;无相邻册轻提示不退出 - 跳页:chrome 内 meow_slider,目标页预解码完成后落位(2.5s 超时降级提示) - 解码:改走 M12 预算解码 meow_img_load_file_dim;超大 PNG/BMP 先 probe 预判, 超 40MiB 原始 RGBA 跳过并显示「图片无法显示」,12MiB 以上记 WARN(如实保留残余风险) - 测试:新增条漫排版/跳页状态/模式续读持久化/册间边界宿主测试,以及真实 SDK 源码树上的 阅读器集成测试(模式切换/跳页落位/续读/跨册),test/run_webtoon_tests.sh 一键运行
This commit is contained in:
1 parent
8cbb240931
commit
ff97f3cee7
14 files changed
+2539
-93
No files matched your search
@@ -1,5 +1,8 @@
|
||||
/* logic/reader/nav.c — 阅读导航纯逻辑实现(见 nav.h 的方向语义说明)。 */
|
||||
#include "logic/reader/nav.h"
|
||||
#include "logic/reader/page_source.h" /* MR_BOOK_MAX_PAGES(条漫排版页数上限) */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int mr_nav_tap_zone(int x, int view_w)
|
||||
{
|
||||
@@ -118,3 +121,209 @@ int mr_nav_fit_next(int fit)
|
||||
if (fit < 0 || fit >= MR_FIT_COUNT) return MR_FIT_WIDTH;
|
||||
return (fit + 1) % MR_FIT_COUNT;
|
||||
}
|
||||
|
||||
/* ============================================================ */
|
||||
/* 条漫排版 / 滚动窗口 */
|
||||
/* ============================================================ */
|
||||
static int strip_page_height(int src_w, int src_h, int vw)
|
||||
{
|
||||
long long h;
|
||||
if (vw <= 0) vw = 1;
|
||||
if (src_w > 0 && src_h > 0)
|
||||
h = (long long)src_h * vw / src_w; /* 适宽等比 */
|
||||
else
|
||||
h = (long long)vw * 3 / 2; /* 未知尺寸:2:3 竖图占位 */
|
||||
if (h < 1) h = 1;
|
||||
if (h > MR_STRIP_MAX_PAGE_H) h = MR_STRIP_MAX_PAGE_H;
|
||||
return (int)h;
|
||||
}
|
||||
|
||||
void mr_strip_free(mr_strip *s)
|
||||
{
|
||||
if (!s) return;
|
||||
free(s->top);
|
||||
free(s->height);
|
||||
s->top = NULL;
|
||||
s->height = NULL;
|
||||
s->count = s->total = 0;
|
||||
s->vw = s->vh = 0;
|
||||
}
|
||||
|
||||
int mr_strip_build(mr_strip *s, int count, int vw, int vh,
|
||||
mr_strip_meta_fn meta, void *ctx)
|
||||
{
|
||||
if (!s) return -1;
|
||||
mr_strip_free(s);
|
||||
if (count <= 0 || count > MR_BOOK_MAX_PAGES || vw <= 0 || vh <= 0) return -1;
|
||||
|
||||
s->top = (int *)calloc((size_t)count + 1, sizeof *s->top);
|
||||
s->height = (int *)calloc((size_t)count, sizeof *s->height);
|
||||
if (!s->top || !s->height) { mr_strip_free(s); return -1; }
|
||||
|
||||
s->count = count;
|
||||
s->vw = vw;
|
||||
s->vh = vh;
|
||||
long long y = 0;
|
||||
for (int i = 0; i < count; i++) {
|
||||
int sw = 0, sh = 0;
|
||||
if (meta && !meta(ctx, i, &sw, &sh)) { sw = sh = 0; } /* 未知/失败 → 占位 */
|
||||
int h = strip_page_height(sw, sh, vw);
|
||||
s->height[i] = h;
|
||||
s->top[i] = (int)y;
|
||||
y += h;
|
||||
if (y > 1000000000LL) { /* 累计偏移上限(防溢出;正常书远达不到) */
|
||||
y = 1000000000LL;
|
||||
for (int k = i + 1; k < count; k++) {
|
||||
s->height[k] = 1;
|
||||
s->top[k] = (int)y;
|
||||
y += 1;
|
||||
if (y > 1000000000LL) y = 1000000000LL;
|
||||
}
|
||||
s->top[count] = (int)y;
|
||||
s->total = (int)y;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
s->top[count] = (int)y;
|
||||
s->total = (int)y;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mr_strip_page_h(const mr_strip *s, int index)
|
||||
{
|
||||
if (!s || !s->height || index < 0 || index >= s->count) return 0;
|
||||
return s->height[index];
|
||||
}
|
||||
|
||||
int mr_strip_top(const mr_strip *s, int index)
|
||||
{
|
||||
if (!s || !s->top || index < 0 || index > s->count) return 0;
|
||||
return s->top[index];
|
||||
}
|
||||
|
||||
int mr_strip_total(const mr_strip *s)
|
||||
{
|
||||
return s ? s->total : 0;
|
||||
}
|
||||
|
||||
int mr_strip_max_offset(const mr_strip *s)
|
||||
{
|
||||
if (!s || s->count <= 0) return 0;
|
||||
int m = s->total - s->vh;
|
||||
return m > 0 ? m : 0;
|
||||
}
|
||||
|
||||
int mr_strip_page_at(const mr_strip *s, int off)
|
||||
{
|
||||
if (!s || s->count <= 0 || !s->top) return -1;
|
||||
if (off <= 0) return 0;
|
||||
if (off >= s->total) return s->count - 1;
|
||||
int lo = 0, hi = s->count - 1;
|
||||
while (lo < hi) { /* 最大的 top[i] <= off */
|
||||
int mid = lo + (hi - lo + 1) / 2;
|
||||
if (s->top[mid] <= off) lo = mid;
|
||||
else hi = mid - 1;
|
||||
}
|
||||
return lo;
|
||||
}
|
||||
|
||||
int mr_strip_offset_for_page(const mr_strip *s, int page)
|
||||
{
|
||||
if (!s || s->count <= 0) return -1;
|
||||
if (page < 0) page = 0;
|
||||
if (page >= s->count) page = s->count - 1;
|
||||
int off = s->top[page];
|
||||
int m = mr_strip_max_offset(s);
|
||||
if (off > m) off = m;
|
||||
if (off < 0) off = 0;
|
||||
return off;
|
||||
}
|
||||
|
||||
int mr_strip_window(const mr_strip *s, int off, int max_pages,
|
||||
int *first, int *last)
|
||||
{
|
||||
if (first) *first = 0;
|
||||
if (last) *last = -1;
|
||||
if (!s || s->count <= 0) return 0;
|
||||
if (max_pages <= 0) max_pages = 1;
|
||||
|
||||
int m = mr_strip_max_offset(s);
|
||||
if (off < 0) off = 0;
|
||||
if (off > m) off = m;
|
||||
|
||||
int f = mr_strip_page_at(s, off);
|
||||
int l = mr_strip_page_at(s, off + s->vh - 1);
|
||||
if (l < f) l = f;
|
||||
|
||||
int lo = f - 1; /* 视口 ±1 页 */
|
||||
int hi = l + 1;
|
||||
if (lo < 0) lo = 0;
|
||||
if (hi > s->count - 1) hi = s->count - 1;
|
||||
if (hi - lo + 1 > max_pages) { /* 驻留上限:从视口中心向外截 */
|
||||
int center = (f + l) / 2;
|
||||
lo = center - (max_pages - 1) / 2;
|
||||
hi = lo + max_pages - 1;
|
||||
if (lo < 0) { lo = 0; hi = max_pages - 1; }
|
||||
if (hi > s->count - 1) { hi = s->count - 1; lo = hi - max_pages + 1; }
|
||||
if (lo < 0) lo = 0;
|
||||
}
|
||||
if (first) *first = lo;
|
||||
if (last) *last = hi;
|
||||
return hi - lo + 1;
|
||||
}
|
||||
|
||||
int mr_strip_at_end(const mr_strip *s, int off)
|
||||
{
|
||||
if (!s || s->count <= 0) return 0;
|
||||
return off >= mr_strip_max_offset(s);
|
||||
}
|
||||
|
||||
int mr_strip_at_start(const mr_strip *s, int off)
|
||||
{
|
||||
if (!s || s->count <= 0) return 0;
|
||||
return off <= 0;
|
||||
}
|
||||
|
||||
/* ============================================================ */
|
||||
/* 跳页状态 */
|
||||
/* ============================================================ */
|
||||
void mr_jump_cancel(mr_jump *j)
|
||||
{
|
||||
if (!j) return;
|
||||
j->pending = 0;
|
||||
j->target = -1;
|
||||
j->t0 = 0;
|
||||
}
|
||||
|
||||
void mr_jump_begin(mr_jump *j, int page, int count, unsigned long long now)
|
||||
{
|
||||
if (!j) return;
|
||||
if (count <= 0 || page < 0 || page >= count) { mr_jump_cancel(j); return; }
|
||||
j->pending = 1;
|
||||
j->target = page;
|
||||
j->t0 = now;
|
||||
}
|
||||
|
||||
int mr_jump_active(const mr_jump *j)
|
||||
{
|
||||
return j && j->pending ? 1 : 0;
|
||||
}
|
||||
|
||||
int mr_jump_target(const mr_jump *j)
|
||||
{
|
||||
return (j && j->pending) ? j->target : -1;
|
||||
}
|
||||
|
||||
int mr_jump_poll(mr_jump *j, int have_img, unsigned long long now,
|
||||
unsigned long long timeout_ms, int *timed_out)
|
||||
{
|
||||
if (timed_out) *timed_out = 0;
|
||||
if (!j || !j->pending) return 0;
|
||||
if (have_img) { mr_jump_cancel(j); return 1; }
|
||||
if (timeout_ms > 0 && now - j->t0 >= timeout_ms) {
|
||||
mr_jump_cancel(j);
|
||||
if (timed_out) *timed_out = 1;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user