diff --git a/convert-w2p.js b/convert-w2p.js index d724463..daa4bb8 100644 --- a/convert-w2p.js +++ b/convert-w2p.js @@ -634,24 +634,28 @@ async function convert(input) { // 额外:IMAGE 节点覆盖的 TEXT 节点也去掉(图片替代文字) var imageRects = sg.children.filter(c => c.type === 'IMAGE' && c.rect).map(c => ({ x: Math.round(c.rect.x), y: Math.round(c.rect.y), - w: Math.round(c.rect.w), h: Math.round(c.rect.h) + w: Math.round(c.rect.w), h: Math.round(c.rect.h), + z: parseInt(c.styles?.zIndex) || 0 })); var seen = {}; var overlapRemove = new Set(); for (var i = sg.children.length - 1; i >= 0; i--) { var ci = sg.children[i]; if (!ci.rect) continue; - // TEXT 节点被 IMAGE 完全覆盖或包含时移除 + // TEXT 节点被 IMAGE 覆盖时移除(IMAGE 的 z-index >= TEXT 的 z-index) if (ci.type === 'TEXT') { var cx = Math.round(ci.rect.x), cy = Math.round(ci.rect.y); var cw = Math.round(ci.rect.w), ch = Math.round(ci.rect.h); + var textZ = parseInt(ci.styles?.zIndex) || 0; for (var ir of imageRects) { - // 完全重叠 + // 检查坐标重叠或包含 var exactMatch = Math.abs(cx - ir.x) < 3 && Math.abs(cy - ir.y) < 3 && Math.abs(cw - ir.w) < 3 && Math.abs(ch - ir.h) < 3; - // TEXT 被 IMAGE 包含(IMAGE 在 TEXT 内部) var contained = ir.x >= cx - 5 && ir.y >= cy - 5 && ir.x + ir.w <= cx + cw + 5 && ir.y + ir.h <= cy + ch + 5; if (exactMatch || contained) { - overlapRemove.add(ci.id); + // IMAGE z-index >= TEXT z-index 时才移除(IMAGE 在上方) + if (ir.z >= textZ) { + overlapRemove.add(ci.id); + } break; } } @@ -927,19 +931,22 @@ async function convert(input) { // ---------------------------------------------------------- // 第三步:组装最终 Schema // ---------------------------------------------------------- - // 用第一个 slide 容器的尺寸决定画布比例 + // 画布尺寸:多 slide(PPT设计稿)用容器尺寸,单 slide(网页)用 canvas let layout = 'LAYOUT_16x9'; - if (slideGroups.length > 0) { - const sr = slideGroups[0].slideRect; - if (sr && sr.w && sr.h) { - const sw = sr.w / 72; - const sh = sr.h / 72; - layout = 'CUSTOM'; - return { - presentation: { layout: 'CUSTOM', slideWidth: sw, slideHeight: sh }, - slides: slides - }; - } + var sizeSource; + if (slideGroups.length > 1) { + sizeSource = slideGroups[0].slideRect; + } else { + sizeSource = { w: canvas.width || 1920, h: canvas.height || 1080 }; + } + if (sizeSource.w && sizeSource.h) { + const sw = sizeSource.w / 72; + const sh = sizeSource.h / 72; + layout = 'CUSTOM'; + return { + presentation: { layout: 'CUSTOM', slideWidth: sw, slideHeight: sh }, + slides: slides + }; } return {