125续15m4: 成书封页往前扫语义边界(避免贪心硬切劈词致中间孤短页)+中间孤短页<40并入下页(<=105)+findSemanticCut容差参数化

This commit is contained in:
youpaishidifu
2026-11-22 21:20:00 +08:00
parent 3935a5248c
commit d9035a6abc
3 changed files with 626 additions and 7 deletions
@@ -390,10 +390,20 @@ public class CustomScreenManager implements Listener {
// ★ 15l-7k 的「投票规则详见第六章第3节;」分号容差需求,靠 findSemanticCut 的
// 容差 limit+10=110 仍能满足(分号若落在 100~110 之间仍纳入切点)。
// ★ 15m3 回退 15m2 的 cut<60 并入逻辑:封页正常 fill 85(标题+协议目的+长段开头)。
// 15m2 把封页太稀并入正文反而让页1 更短(20字),CR 修复后封页 85 字正常不孤稀。
// findSemanticCut 容差+10 让切点尽量到 85~95,标题页填满。
// ★ 15m4 封页根治稀疏:旧 findSemanticCut(body,85) 在标题行后 早停到 20 字,
// 封页只填 20 字孤稀。改贪心 fill 直接取前 85 字(残句续下一页),封页满屏。
// 正文页仍用 findSemanticCut 语义切(不劈词)。
if (!body.isEmpty()) {
int cut = findSemanticCut(body, 85);
// 15m4 封页往前扫: 从0往85找最后一个语义边界(句末/逗号/换行), 取最靠后, 避免劈词
int cut = Math.min(body.length(), 85);
for (int ci = cut; ci >= 0; ci--) {
char cc = body.charAt(ci);
if (cc == '。' || cc == '!' || cc == '?' || cc == ';' || cc == ',' || cc == ',' || cc == '\n') {
cut = ci + 1;
break;
}
}
pages.add(body.substring(0, cut));
body = body.substring(cut);
}
@@ -481,6 +491,16 @@ public class CustomScreenManager implements Listener {
}
}
// 15m4 中间孤短页合并: 封页贪心fill切出的残句页(<40字)并入下页, 避免孤稀
for (int pi = 1; pi + 1 < pages.size(); pi++) {
String cur = pages.get(pi);
String nxt = pages.get(pi + 1);
if (cur.length() < 40 && (cur.length() + nxt.length() + 1) <= 105) {
pages.set(pi + 1, cur + "\n" + nxt);
pages.remove(pi);
}
}
bookMeta.setPages(pages);
book.setItemMeta(meta);
return book;
@@ -557,10 +577,11 @@ public class CustomScreenManager implements Listener {
* 超 MC 成书 UI 一屏竖排实际视口 ~130 字,仍劈「使用/法」。+10 时 100+10=110,
* 安全落视口内。超 limit+10 仍硬切 limit。
*/
private int findSemanticCut(String s, int limit) {
private int findSemanticCut(String s, int limit) { return findSemanticCut(s, limit, 10); }
private int findSemanticCut(String s, int limit, int tol) {
if (s.length() <= limit) return s.length();
int best = -1;
int searchEnd = Math.min(s.length() - 1, limit + 10); // ★ 15l-7m 容差收紧 +20→+10
int searchEnd = Math.min(s.length() - 1, limit + tol); // ★ 15m4 容差参数化(默认10,封页20)
for (int i = searchEnd; i >= 0; i--) {
char c = s.charAt(i);
if (c == '。' || c == '!' || c == '?' || c == ';' || c == '\n') {
@@ -568,7 +589,7 @@ public class CustomScreenManager implements Listener {
break;
}
}
if (best <= 0 || best > limit + 10) {
if (best <= 0 || best > limit + tol) {
// 退化:limit 以内找逗号/空格
for (int i = Math.min(s.length() - 1, limit - 1); i >= 0; i--) {
char c = s.charAt(i);
@@ -578,7 +599,7 @@ public class CustomScreenManager implements Listener {
}
}
}
if (best <= 0 || best > limit + 10) best = limit;
if (best <= 0 || best > limit + tol) best = limit;
return best;
}