80 lines
4.3 KiB
C
80 lines
4.3 KiB
C
/* app/book.h — 书桥:把 core(TXT/排版) + engine(FreeType) 串成「一本 TXT 书」。
|
||
*
|
||
* 打开一本书:探测编码 → 逐段 rdtxt 流式读 → 每段 utf8→码点 → rd_layout(测量=rdft_advance)
|
||
* → 页索引(flat:每页=段+段内字符偏移)+ 段表(file_off/file_len/page_start/page_count)。
|
||
* 渲染页:定位段 → 重读该段 → 重排 → 取该页行 → 逐字 rdft_glyph → blend565 到全屏缓冲。
|
||
* 锚定/进度:(段,字符偏移),与字号无关;改字号/行距触发后台重排并回锚(§6.3)。
|
||
*
|
||
* 内存纪律:单段(文本+cps+布局)≈ 320KB 冲击,随段释放;页索引 flat ~每页 12B;3 页位图由
|
||
* 阅读 view 持有(本模块只填一个渲染目标缓冲,不缓存整页)。
|
||
*/
|
||
#ifndef RDBOOK_H
|
||
#define RDBOOK_H
|
||
|
||
#include "rdenc.h"
|
||
#include <stddef.h>
|
||
#include <stdint.h>
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
typedef struct rd_book rd_book;
|
||
|
||
typedef struct rd_book_page {
|
||
int32_t seg; /* 段下标 */
|
||
int32_t seg_char; /* 段内字符偏移(页首) */
|
||
} rd_book_page;
|
||
|
||
/* 打开书:path=TXT;font_path=FreeType 字体;geom=版面(fs 字号 / ls 行距% / pw,ph 全屏 /
|
||
* mx,my 左右/上下边距 / top 顶部 inset(状态栏+顶条))。0=成功。 */
|
||
int rd_book_open(rd_book **b, const char *path, const char *font_path,
|
||
int fs, int ls, int pw, int ph, int mx, int my, int top);
|
||
void rd_book_close(rd_book *b);
|
||
|
||
int rd_book_pages(rd_book *b);
|
||
int rd_book_current(rd_book *b); /* 当前页 */
|
||
int rd_book_turn(rd_book *b, int delta); /* +1/-1;clamp 到 [0,npages-1] */
|
||
int rd_book_set_page(rd_book *b, int page); /* 跳到绝对页;clamp;返回实际页(段刮擦用) */
|
||
int rd_book_is_image(rd_book *b); /* 1=CBZ 图片页书 */
|
||
|
||
/* 目录:0=无;i 项标题写到 title,目标段/字符偏移填 *seg 与 *ch。 */
|
||
int rd_book_toc_n(const rd_book *b);
|
||
int rd_book_toc(const rd_book *b, int i, char *title, int tsz, int *seg, int32_t *ch);
|
||
void rd_book_anchor(rd_book *b, int *seg, int32_t *ch);/* 当前页锚(段,字符偏移) */
|
||
int rd_book_jump_to_anchor(rd_book *b, int seg, int32_t ch, int fs, int ls); /* 重排 + 回锚 */
|
||
int rd_book_set_size(rd_book *b, int fs, int ls); /* 重排 + 回锚(anchor=当前页) */
|
||
|
||
/* 渲染页到全屏缓冲:out 为 pw*ph RGB565(每行 pitch 字节);先填 bg565 再画正文。
|
||
* 0=成功;1=该页为空(无正文,如末页空白)。 */
|
||
int rd_book_render(rd_book *b, int page_no, uint16_t *out, int pitch, uint16_t bg565, uint16_t fg565);
|
||
|
||
/* SDK 字库兜底:逐行回调(每行一个 utf8 文本串,屏幕坐标 x,y 已含 inset/边距)。
|
||
* 用于「无 TTF/OTF → 用 meow_ui_text 位图字库渲染正文」的降级路径(见 reader 视图取舍)。 */
|
||
typedef void (*rd_book_line_fn)(int x, int y, const char *utf8, int len, void *ctx);
|
||
int rd_book_render_text(rd_book *b, int page_no, rd_book_line_fn fn, void *ctx);
|
||
|
||
/* 书名/信息(章节名:TXT 无章节=文件名;enc 可读名)。调用方 strcpy 到自己的缓冲。 */
|
||
const char *rd_book_basename(const rd_book *b); /* 文件名(路径尾分量) */
|
||
const char *rd_book_encname(const rd_book *b);
|
||
rd_enc_t rd_book_enc_get(const rd_book *b); /* TXT 有效编码(非 TXT = RD_ENC_UTF8) */
|
||
const char *rd_book_path(const rd_book *b); /* 原始路径 */
|
||
|
||
/* R3:TXT 编码切换:重开 src(覆盖编码)+ 重建索引 + 回锚。返回目标页;非 TXT/CBZ 或失败负值。
|
||
* 用于「编码」菜单(Big5 繁体书手动选定)。 */
|
||
int rd_book_set_enc(rd_book *b, rd_enc_t enc);
|
||
|
||
/* R3.1:页索引持久化缓存目录(MeowData/os.meow.reader/index)。dir 为空 → 禁持久化(直排,不落盘)。
|
||
* 由 reader.c 在 open 前建目录并注入;书/字号/行距/版面/编码/字体任一变化时缓存自动失效重排。 */
|
||
void rd_book_set_index_dir(const char *dir);
|
||
|
||
/* 字体/几何 */
|
||
int rd_book_font(rd_book *b); /* 当前字号 */
|
||
int rd_book_ls(rd_book *b); /* 行距% */
|
||
void rd_book_geom(rd_book *b, int *fs, int *ls, int *pw, int *ph, int *mx, int *my, int *top);
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
#endif /* RDBOOK_H */
|