From d4d86eb1da3749e8e71f099380bf09a844ded99f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E8=BF=9B?= Date: Fri, 24 Jul 2026 18:27:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20IMAGE=20=E8=A6=86=E7=9B=96=E7=9A=84=20TE?= =?UTF-8?q?XT=20=E8=8A=82=E7=82=B9=E8=87=AA=E5=8A=A8=E7=A7=BB=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当 TEXT 节点和 IMAGE 节点同坐标同尺寸时,移除 TEXT(图片替代文字) --- convert-w2p.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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);