diff --git a/src/main/java/Sdf1_login/CustomScreenManager.java b/src/main/java/Sdf1_login/CustomScreenManager.java index 6a495e8..c7e8913 100644 --- a/src/main/java/Sdf1_login/CustomScreenManager.java +++ b/src/main/java/Sdf1_login/CustomScreenManager.java @@ -384,10 +384,11 @@ public class CustomScreenManager implements Listener { // ★ 15l-7j 封页补肉:正文前 ~380 字进封页,但必须在语义边界(。!?;\n)处切, // 残句续下一页(与正文分页同一套 findSemanticCut 切法)。 - // 旧 bug:封页硬切 body.substring(0,380) 劈句子(「投票规则详见…未在投票有效期内」 - // 被吞进剩余 body 的第一段,导致第2页开头是残缺句「参与表决的,视为自动弃权」)。 + // ★ 15l-7k:封页 limit 放宽到 400——MC 成书 UI 每屏竖排实际容 ~400 字(380 是旧 + // 软限制),放宽让「投票规则详见第六章第3节;」这类分号(在 390 左右)能被纳入封页, + // 避免切在更早的句号导致「投票规则详见」整段被丢进下一页。 if (!body.isEmpty()) { - int cut = findSemanticCut(body, 380); + int cut = findSemanticCut(body, 400); pages.add(body.substring(0, cut)); body = body.substring(cut); } @@ -404,10 +405,10 @@ public class CustomScreenManager implements Listener { // 当前页为空:直接开始新段落 if (page.length() == 0) { - if (p.length() > 380) { + if (p.length() > 400) { java.util.List sentences = splitSentences(p); for (String s : sentences) { - if (page.length() + s.length() + 1 > 380 && page.length() > 0) { + if (page.length() + s.length() + 1 > 400 && page.length() > 0) { pages.add(page.toString().trim()); page = new StringBuilder(); } @@ -420,14 +421,14 @@ public class CustomScreenManager implements Listener { } // 当前页已有内容:判断段落是否能整段放入 - if (page.length() + p.length() + 1 <= 380) { + if (page.length() + p.length() + 1 <= 400) { page.append("\n").append(p); continue; } // 整段放不进:在「当前页 + 段落」里找语义边界截断 String candidate = page.toString() + "\n" + p; - int cut = findSemanticCut(candidate, 380); + int cut = findSemanticCut(candidate, 400); // ★ 15l-7f 修复:不 trim,保留语义边界(。!?;\n)在页内,避免吃掉前面整段 String firstHalf = candidate.substring(0, cut); String secondHalf = candidate.substring(cut); @@ -438,8 +439,8 @@ public class CustomScreenManager implements Listener { page = new StringBuilder(secondHalf); // 若剩余段仍超页,继续按语义截断或按句拆 - while (page.length() > 380) { - int nextCut = findSemanticCut(page.toString(), 380); + while (page.length() > 400) { + int nextCut = findSemanticCut(page.toString(), 400); String chunk = page.substring(0, nextCut); String remain = page.substring(nextCut); while (chunk.endsWith("\n") || chunk.endsWith(" ")) chunk = chunk.substring(0, chunk.length() - 1); @@ -460,7 +461,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) <= 380) { + if (last.length() < 20 && (prev.length() + last.length() + 1) <= 400) { pages.set(pages.size() - 2, prev + "\n" + last); pages.remove(pages.size() - 1); } @@ -536,21 +537,22 @@ public class CustomScreenManager implements Listener { * 在 limit 以内找最佳语义截断点(。!?;、行首)。 * ★ 15l-7i 修复:从后往前扫时只接受 i < limit 的句末标点(避免 best 落在 limit 之后 * 导致切点越界、丢内容)。扫不到则退化按逗号/空格,再退化硬切 limit。 + * ★ 15l-7k:句末搜索容差放宽到 limit+20——MC 成书 UI 每屏竖排实际容 ~400+ 字, + * 最近句末(如分号)若落在 limit~limit+20 之间,纳入切点(避免「投票规则详见…;」 + * 被 i= 0; i--) { + int searchEnd = Math.min(s.length() - 1, limit + 20); // ★ 15l-7k 容差 +20 + for (int i = searchEnd; i >= 0; i--) { char c = s.charAt(i); - // 只接受 limit 以内的语义边界(旧 bug:i>=limit 的句末也被设为 best,越界) - if (i < limit) { - if (c == '。' || c == '!' || c == '?' || c == ';' || c == '\n') { - best = i + 1; - break; - } + if (c == '。' || c == '!' || c == '?' || c == ';' || c == '\n') { + best = i + 1; + break; } } - if (best <= 0 || best > limit) { + if (best <= 0 || best > limit + 20) { // 退化:limit 以内找逗号/空格 for (int i = Math.min(s.length() - 1, limit - 1); i >= 0; i--) { char c = s.charAt(i); @@ -560,7 +562,7 @@ public class CustomScreenManager implements Listener { } } } - if (best <= 0 || best > limit) best = limit; + if (best <= 0 || best > limit + 20) best = limit; return best; }