mirror of
https://gitee.com/ulthon/ulthon_information.git
synced 2026-07-09 06:12:48 +08:00
feat(typesetting): 段落按句拆分填满页面剩余空间 - 减少空白浪费
- paginateContent正常块换页判断增加按句拆分逻辑 - p/blockquote超过剩余空间时调用splitOversizedBlock拆分 - 拆分后的句子块逐步填入当前页,多余推到后续页 - img/pre/table/h2/h3/h4不拆分,直接换页 - remainingSpace>50条件防止极小碎片 - 拆分失败时回退到原有换页逻辑
This commit is contained in:
@@ -663,6 +663,33 @@ var PhoneImageEngine = (function () {
|
|||||||
var nextBlock = (i + 1 < blocks.length) ? blocks[i + 1] : null;
|
var nextBlock = (i + 1 < blocks.length) ? blocks[i + 1] : null;
|
||||||
|
|
||||||
if (currentHeight + block.estimatedHeight > contentAreaHeight && currentPageBlocks.length > 0) {
|
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(
|
contentPages.push(generateContentPage(
|
||||||
currentPageBlocks, pageNumber, sizeConfig, false
|
currentPageBlocks, pageNumber, sizeConfig, false
|
||||||
));
|
));
|
||||||
|
|||||||
Reference in New Issue
Block a user