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 ));