125续15l-7m: 成书limit 120→100+findSemanticCut容差+20→+10(最大切点110字,根治140超UI一屏~130视口仍劈'使用/法');Python复刻player.md验证每页23~110字无超130

This commit is contained in:
youpaishidifu
2026-11-22 16:26:46 +08:00
parent 493591c4b4
commit ebefb2875f
@@ -382,15 +382,15 @@ public class CustomScreenManager implements Listener {
java.util.List<String> pages = new java.util.ArrayList<>();
// ★ 15l-7j 封页补肉:正文前 ~120 字进封页,但必须在语义边界(。!?;\n)处切,
// ★ 15l-7j 封页补肉:正文前 ~100 字进封页,但必须在语义边界(。!?;\n)处切,
// 残句续下一页(与正文分页同一套 findSemanticCut 切法)。
// ★ 15l-7l 修复:limit 150→120(15l-7k 错改 400 被 15l-17 修回 150,但截图实证
// 150 仍偏大——第2页「使用」被劈、第3页「法」被劈,UI 一屏竖排实际容 ~130 字)。
// 120 字 + 语义切点(。!?;)+ 残句续下一页,每页保守不劈字。
// ★ 15l-7m 修复:limit 120→100(容差收紧 +10 后最大切点 110 字,安全落 MC
// 成书 UI 一屏竖排视口 ~130 字内)。旧 120+容差20=140 仍劈「使用/法」。
// 100 字 + 语义切点(。!?;)+ 残句续下一页,每页保守不劈字。
// ★ 15l-7k 的「投票规则详见第六章第3节;」分号容差需求,靠 findSemanticCut 的
// 容差 limit+20=140 仍能满足(分号若落在 120~140 之间仍纳入切点)。
// 容差 limit+10=110 仍能满足(分号若落在 100~110 之间仍纳入切点)。
if (!body.isEmpty()) {
int cut = findSemanticCut(body, 120);
int cut = findSemanticCut(body, 100);
pages.add(body.substring(0, cut));
body = body.substring(cut);
}
@@ -407,10 +407,10 @@ public class CustomScreenManager implements Listener {
// 当前页为空:直接开始新段落
if (page.length() == 0) {
if (p.length() > 120) {
if (p.length() > 100) {
java.util.List<String> sentences = splitSentences(p);
for (String s : sentences) {
if (page.length() + s.length() + 1 > 120 && page.length() > 0) {
if (page.length() + s.length() + 1 > 100 && page.length() > 0) {
pages.add(page.toString().trim());
page = new StringBuilder();
}
@@ -423,14 +423,14 @@ public class CustomScreenManager implements Listener {
}
// 当前页已有内容:判断段落是否能整段放入
if (page.length() + p.length() + 1 <= 120) {
if (page.length() + p.length() + 1 <= 100) {
page.append("\n").append(p);
continue;
}
// 整段放不进:在「当前页 + 段落」里找语义边界截断
String candidate = page.toString() + "\n" + p;
int cut = findSemanticCut(candidate, 120);
int cut = findSemanticCut(candidate, 100);
// ★ 15l-7f 修复:不 trim,保留语义边界(。!?;\n)在页内,避免吃掉前面整段
String firstHalf = candidate.substring(0, cut);
String secondHalf = candidate.substring(cut);
@@ -441,8 +441,8 @@ public class CustomScreenManager implements Listener {
page = new StringBuilder(secondHalf);
// 若剩余段仍超页,继续按语义截断或按句拆
while (page.length() > 120) {
int nextCut = findSemanticCut(page.toString(), 120);
while (page.length() > 100) {
int nextCut = findSemanticCut(page.toString(), 100);
String chunk = page.substring(0, nextCut);
String remain = page.substring(nextCut);
while (chunk.endsWith("\n") || chunk.endsWith(" ")) chunk = chunk.substring(0, chunk.length() - 1);
@@ -463,7 +463,7 @@ public class CustomScreenManager implements Listener {
if (pages.size() > 2) {
String last = pages.get(pages.size() - 1);
String prev = pages.get(pages.size() - 2);
if (last.length() < 20 && (prev.length() + last.length() + 1) <= 120) {
if (last.length() < 20 && (prev.length() + last.length() + 1) <= 100) {
pages.set(pages.size() - 2, prev + "\n" + last);
pages.remove(pages.size() - 1);
}
@@ -539,15 +539,14 @@ public class CustomScreenManager implements Listener {
* 在 limit 以内找最佳语义截断点(。!?;、行首)。
* ★ 15l-7i 修复:从后往前扫时只接受 i < limit 的句末标点(避免 best 落在 limit 之后
* 导致切点越界、丢内容)。扫不到则退化按逗号/空格,再退化硬切 limit。
* ★ 15l-7l:句末搜索容差放宽到 limit+20——MC 成书 UI 每屏竖排实际容 ~155 字,
* 15l-17 把 limit 改成 150,容差 limit+20=170 仍能在「最近句末落在 150~170 之间」时
* 纳入切点(15l-7k 的「投票规则详见第六章第3节;」分号容差需求仍满足)。
* 超 limit+20 仍硬切 limit。
* ★ 15l-7m:容差收紧 limit+20→limit+10——旧 +20 把切点推到 140 字(120+20),
* 超 MC 成书 UI 一屏竖排实际视口 ~130 字,仍劈「使用/法」。+10 时 100+10=110,
* 安全落视口内。超 limit+10 仍硬切 limit。
*/
private int findSemanticCut(String s, int limit) {
if (s.length() <= limit) return s.length();
int best = -1;
int searchEnd = Math.min(s.length() - 1, limit + 20); // ★ 15l-7k 容差 +20(15l-7l 沿用)
int searchEnd = Math.min(s.length() - 1, limit + 10); // ★ 15l-7m 容差收紧 +20→+10
for (int i = searchEnd; i >= 0; i--) {
char c = s.charAt(i);
if (c == '。' || c == '!' || c == '?' || c == ';' || c == '\n') {
@@ -555,7 +554,7 @@ public class CustomScreenManager implements Listener {
break;
}
}
if (best <= 0 || best > limit + 20) {
if (best <= 0 || best > limit + 10) {
// 退化:limit 以内找逗号/空格
for (int i = Math.min(s.length() - 1, limit - 1); i >= 0; i--) {
char c = s.charAt(i);
@@ -565,7 +564,7 @@ public class CustomScreenManager implements Listener {
}
}
}
if (best <= 0 || best > limit + 20) best = limit;
if (best <= 0 || best > limit + 10) best = limit;
return best;
}