Skip to content

[6026] 修复超长文档大纲侧边栏跳转最后一节异常(跳转至错误位置或视口全白) - #4738

Merged
da-liii merged 2 commits into
mainfrom
da/200_27/6026
Oct 16, 2026
Merged

da-liii merged 2 commits into
mainfrom
da/200_27/6026

Conversation

@da-liii

@da-liii da-liii commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

任务背景

在极限超长文档(如 vol05.stem,14MB、1.7万页、近9万个段落)渐进式排版彻底完成后,在左侧大纲侧边栏搜索并点击最后一节“第九百五十一节:大时代!”,主文档视口未能准确定位展示目标章节,出现跳转到错误位置(如停留在前序章节/第一节)或视口完全呈现一片纯白无法渲染的缺陷。

根因分析

  1. 重绘与背景清除管线 32 位整型截断:
    edit_interface_rep::handle_repaint、handle_clear 及 draw_background 接口历史遗留参数为 SI x1, SI y1, SI x2, SI y2。当跳转至第 17,150+ 页文末章节时,其纵向坐标达负 220 亿(缩放后仍达负 62 亿),突破 32 位整型范围产生严重回绕(回绕至 -1,936,323,328),导致 draw_with_stored 计算出的物理视口矩形严重偏移错位,无法命中目标页面盒。
  2. Renderer::encode 接口与实现 32 位整型截断:
    renderer_rep::encode 纯虚接口与实现此前为 SI& x, SI& y,内联 DI 重载隐式向下截断为 int,导致 ren->encode 在转换大负坐标时发生溢出,破坏了重绘视口的裁剪盒 cx/cy。
  3. 后备缓冲与图片坐标乘法溢出:
    在 mupdf_picture.cpp 和 qt_picture.cpp 中,ox = pox * pixel 与 oy = poy * pixel 为 32 位 int * int 乘法,在大坐标下产生溢出;同时 to_qrect、to_qsize、to_qpoint 中 float c = 1.0 / SCREEN_PIXEL 存在单精度浮点精度损失。

改动内容

  1. 重绘渲染管线全面升级为 64 位整数(DI):
    • 将 handle_repaint、handle_clear、draw_background 全面升级为 DI x1, DI y1, DI x2, DI y2(同步更新 Qt / ImGui / CLI / tm_button 实现);
    • 将 renderer_rep::encode 升级为 virtual void encode (DI& x, DI& y),消除 32 位截断点;
    • 将 mupdf_qt_simple_widget.cpp 后备缓冲拷贝坐标 x1, y1, x2, y2 升级为 DI。
  2. 消除乘法溢出与精度截断:
    • 在 mupdf_picture.cpp 与 qt_picture.cpp 中对 pox/poy 进行 ((DI) pox) * pixel 显式向上转型乘法;
    • 在 qt_utilities.cpp 中将 c = 1.0 / SCREEN_PIXEL 升级为 double,杜绝 64 位整型到 Qt 矩形转换时的精度损失。

关键验证

  • 运行自动化端到端测试 python3 tests/mogan/python/6026.py:
    • 成功等待 1.7 万页渐进排版完成(~40s);
    • 搜索并点击“第九百五十一节:大时代!”;
    • 视口精准定位至第 17,158 页,标题及正文文字清晰完整渲染(std=43.20),光标位于标题“第”字左侧正常闪烁(diff=335897),测试 PASS;
  • xmake r 6024、xmake r 6013、xmake r 6004 全部零报错通过;
  • 执行 gf fmt --changed-since=main 格式化通过。

@da-liii
da-liii merged commit c68a494 into main Oct 16, 2026
7 checks passed
@da-liii
da-liii deleted the da/200_27/6026 branch October 16, 2026 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant