diff --git a/convert-w2p.js b/convert-w2p.js index e2b0fa7..4355501 100644 --- a/convert-w2p.js +++ b/convert-w2p.js @@ -631,11 +631,27 @@ 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) + })); 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 完全覆盖时移除 + 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); + for (var ir of imageRects) { + if (Math.abs(cx - ir.x) < 3 && Math.abs(cy - ir.y) < 3 && Math.abs(cw - ir.w) < 3 && Math.abs(ch - ir.h) < 3) { + overlapRemove.add(ci.id); + break; + } + } + } var key = ci.type + ',' + Math.round(ci.rect.x) + ',' + Math.round(ci.rect.y) + ',' + Math.round(ci.rect.w) + ',' + Math.round(ci.rect.h); if (seen[key]) { overlapRemove.add(ci.id);