fix: IMAGE 覆盖的 TEXT 节点自动移除
当 TEXT 节点和 IMAGE 节点同坐标同尺寸时,移除 TEXT(图片替代文字)
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user