Skip to content

阅读层:译文只在真的放不下时才缩小,Alt+T 加「译文放不下时自动缩小」开关 - #1506

Open
ilynthn wants to merge 4 commits into
mainfrom
reader/translation-auto-shrink
Open

ilynthn wants to merge 4 commits into
mainfrom
reader/translation-auto-shrink

Conversation

@ilynthn

@ilynthn ilynthn commented Nov 29, 2026

Copy link
Copy Markdown
Owner

问题

群友反馈译文会超出对话框,希望「超过对话框就缩小字号」。这个功能本来就有,但判断经常出错:

  • 下方还有很大空位,译文却整段缩小
  • 缩小后下一句很短的译文也不恢复
  • 真放不下时,译文外框会越过游戏窗口底边

改动

web/reader/modules/text-place.js:

  • 根因一:inject.js 等翻译时会按最近三句译文的高度预留空间。逐字定位和锚定的窗口里,这个预留在译文就绪后还在,短译文被当成长译文来量。现在这两种窗口里就绪的译文不再带预留(对话带除外,避免原文跳动)
  • 根因二:原来按高度比例一次算出字号,24px 会直接跳到 20px。新增 shrinkTo(),逐步缩小、每步实测,只缩到刚好放得下,最多缩 15%。apply()、pin()、underGameLine()、applyPage() 共用它
  • 缩到下限还放不下时,在底边内截断或滚动,不再越过客户区底边
  • 退出锚定时清掉 pin() 写进去的字号和高度限制
  • 给按钮条留的 1.3 行改成内核键 placement.bottomReserveLines(core/profiles/defaults.cjs,默认 1.3,原行为不变;domains.cjs 登记 0~6)。底下没有按钮条的游戏可以在自己的差分里设 0,用满整个高度。档案还没加载时按 1.3 算

开关:

  • Alt+T「文字」里,在「字号跟随游戏窗口缩放」下面加了「译文放不下时自动缩小」,中英日三语
  • 对应偏好 translationAutoShrink,两份 game-style.js 的默认值和清洗规则一致;默认开,旧设置文件里没有这个字段时也按开处理
  • 关掉后各条路径(逐字、锚定、整页、对话带、阅读框 game-fit.js)都不缩译文字号,放不下的部分截断或滚动;切换时当前这句立刻重排

验证

新增 validation/translation-auto-shrink.test.cjs,在无头 Edge 里跑阅读层的真实代码,只模拟宿主消息。在 origin/main(c6a9722a)上 5 项失败、1 项通过(对照):

  • 「the button reserve shrinks a two-row translation by at most 15 %」:main 缩到 20px,低于 85%
  • 「two rows that fit keep the configured size」:差分设预留为 0 时,main 仍缩到 20px
  • 「a translation that really overflows shrinks and stays inside the client」:main 外框越过底边
  • 「the next short line is back at the configured size」:main 下一句仍是 20px
  • 「with auto shrink off the size stays and the overflow is cut inside the client」
  • 「a short line high on the screen was already fine」(对照):main 和本分支都通过

本分支全部通过;text-place-user-row-layout、text-place-dom 也都通过。

PR 前做过一次独立只读审查,查出的问题都已在第二个提交里修掉:

  • 档案没加载时预留被算成 0
  • 关掉开关后,对话带和旧式框仍会缩小
  • 缩到下限后仍可能越界
  • 退出锚定时残留缩过的字号
  • 对话带的原文可能在译文就绪后跳动
  • 已有测试 text-place-user-row-layout 的正则对不上了

未验证:

  • 没有在真实游戏里测过
  • 群友截图那部游戏用的是哪条显示路径不清楚
  • Alt+T 修改前后截图未附(只加了一个复选框),待补

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T16:58:57.773190Z eb980fb PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eb980fb913

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread web/reader/modules/text-place.js Resolved
Comment thread web/reader/modules/text-place.js Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 等合并

Development

Successfully merging this pull request may close these issues.

1 participant