From 92426fe57e1f5bbb93b54083bbff55d0bdd6dd7a Mon Sep 17 00:00:00 2001 From: augushong Date: Sun, 17 May 2026 13:35:19 +0800 Subject: [PATCH] =?UTF-8?q?feat(typesetting):=20=E6=AE=B5=E8=90=BD?= =?UTF-8?q?=E6=8C=89=E5=8F=A5=E6=8B=86=E5=88=86=E5=A1=AB=E6=BB=A1=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E5=89=A9=E4=BD=99=E7=A9=BA=E9=97=B4=20-=20=E5=87=8F?= =?UTF-8?q?=E5=B0=91=E7=A9=BA=E7=99=BD=E6=B5=AA=E8=B4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - paginateContent正常块换页判断增加按句拆分逻辑 - p/blockquote超过剩余空间时调用splitOversizedBlock拆分 - 拆分后的句子块逐步填入当前页,多余推到后续页 - img/pre/table/h2/h3/h4不拆分,直接换页 - remainingSpace>50条件防止极小碎片 - 拆分失败时回退到原有换页逻辑 --- public/static/js/phone-image.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/public/static/js/phone-image.js b/public/static/js/phone-image.js index e7ec469..731ed13 100644 --- a/public/static/js/phone-image.js +++ b/public/static/js/phone-image.js @@ -663,6 +663,33 @@ var PhoneImageEngine = (function () { var nextBlock = (i + 1 < blocks.length) ? blocks[i + 1] : null; if (currentHeight + block.estimatedHeight > contentAreaHeight && currentPageBlocks.length > 0) { + var remainingSpace = contentAreaHeight - currentHeight; + // 检查是否可以按句拆分来填满剩余空间 + var canSplit = (block.type === 'p' || block.type === 'blockquote') && + block.estimatedHeight <= contentAreaHeight && remainingSpace > 50; + + if (canSplit) { + // 按句拆分,逐步填入页面 + var splitParts = splitOversizedBlock(block, contentAreaHeight); + if (splitParts.length > 1) { + // 逐句填入当前页剩余空间 + for (var sp = 0; sp < splitParts.length; sp++) { + if (currentHeight + splitParts[sp].estimatedHeight > contentAreaHeight && currentPageBlocks.length > 0) { + contentPages.push(generateContentPage( + currentPageBlocks, pageNumber, sizeConfig, false + )); + currentPageBlocks = []; + currentHeight = 0; + pageNumber++; + } + currentPageBlocks.push(splitParts[sp]); + currentHeight += splitParts[sp].estimatedHeight; + } + // 跳过后面的 currentPageBlocks.push(block),用拆分后的块代替 + continue; + } + } + // 不可拆分(img/pre/table/h)或拆分失败,直接换页 contentPages.push(generateContentPage( currentPageBlocks, pageNumber, sizeConfig, false ));