feat: 替换点阵字体为FreeType矢量渲染,支持运行时字体/字号/字重、行边距切换、后台排版线程及页面锚点恢复#30
Closed
jingxbw-work wants to merge 2 commits intoOpenSiFli:mainfrom
Closed
feat: 替换点阵字体为FreeType矢量渲染,支持运行时字体/字号/字重、行边距切换、后台排版线程及页面锚点恢复#30jingxbw-work wants to merge 2 commits intoOpenSiFli:mainfrom
jingxbw-work wants to merge 2 commits intoOpenSiFli:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
主要改动
将点阵字体引擎替换为 FreeType 矢量字体渲染,支持从 TF 卡加载 TTF 字体文件,实现运行时字体/字号/行距切换。新增后台排版线程和字体预热线程提升翻页响应速度,通过互斥锁和页面锚点机制保证并发安全和设置切换后的阅读位置恢复。
新增文件
lib/epdiy/font_ft.c/.h— FreeType 矢量字体引擎,替代旧版font.c点阵方案;含 LRU 字形缓存(3MB)、CMap 缓存(4096 条)、可变字体 wght 轴支持、异步预热线程src/ft_dfs_bridge.c— FreeType 文件 I/O 桥接层,内置 64KB 低区预读 + 16×4KB LRU 多槽缓冲,减少 SD 卡随机读取src/font_manager.c/.h— 字体管理器,启动时扫描/fonts目录,支持运行时切换字体,失败时自动回退到内置字体src/reading_settings.cpp/.h— 阅读设置页面(长按 K2 进入),可调字体、字号、字重、行距、边距;持久化到 TF 卡/settings.cfgfont/SConscript+tools/font_converter.py— 构建时将 TTF 文件转换为带.font_datasection 属性的 C 数组,链接到 PSRAM修改文件
核心逻辑
src/main.cpp— 设置页面集成(READING_SETTINGS 状态)、锚点保存/恢复(进入设置前保存、退出后恢复阅读位置)、电池刷屏优化(仅百分比或充电状态变化时刷新)、SD 卡电源保护(后台排版线程或字体预热线程运行时不断电)lib/Epub/EpubList/EpubReader.cpp/.h— 后台排版线程(优先级 24、32KB 栈),仅在render()末尾统一启动,消除prev()向前翻章时的竞态;字体切换时通过页面锚点(PageAnchor)恢复阅读位置;next()翻到未排好的页时等待后台线程而非同步阻塞lib/Epub/RubbishHtmlParser/RubbishHtmlParser.cpp/.h— 互斥锁保护 pages 向量读写(block 排版不持锁、分页 push_back 持锁);新增PageAnchor结构体和锚点查找接口(get_page_anchor/find_page_by_anchor);分页底部溢出修复(分页条件从m_layout_y + m_layout_line_height改为m_layout_y + 2 * m_layout_line_height)适配改动
src/epub_fonts.c— 移除点阵字体头文件引用,改为 FreeType dummy stubssrc/epub_mem.c— 新增 FreeType 内存分配适配(ft_smalloc/ft_sfree/ft_srealloc/ft_scalloc指向 PSRAM 堆)src/boards/SF32Paper.cpp— SD 卡电源管理接口src/boards/controls/Actions.h— 新增LONG_SELECT动作src/boards/controls/SF32_ButtonControls.cpp— 长按检测逻辑lib/Epub/Renderer/EpdiyFrameBufferRenderer.h—draw_text改用 FreeType API(get_line_height调用epd_font_ft_get_line_height)构建与链接
project/SConscript、src/SConscript— 加入新源文件project/proj.conf— 项目配置更新link.lds—*epub_fonts.o (.text* .rodata*)→*(.font_data)link.sct—font.o (+RO)→font_ft.o (+RO)删除文件
lib/epdiy/font.c— 旧版点阵字体引擎Fonts/目录(bold_font.h、bold_italic_font.h、italic_font.h、regular_font.h)— 旧版点阵字体头文件