fix(label-designer): 非白底文字不再丢失;条码占位扩展到人读字符与紧邻装饰线

- boxBackground 增返回背景中位色;擦除改用采样色(白擦白/灰擦灰/蓝擦蓝),不再留白块
- 任何底色上的文字都生成可编辑元素(旧逻辑把非近白底的字整段静默丢弃,改不了也擦不掉)
- 深色底(亮度<110)替换文字自动转白色,保证反白字可见
- 条码占位扩展为条码+四周1mm+下方min(0.45*条高,8mm),一并擦除人读字符与紧邻框线
- 验证:300dpi 靶子底图像素采样,人读字符带/点划线带/灰条/蓝条黑字残留均0.00%
This commit is contained in:
personal82555 committed 2026-10-14 22:27:04 +08:00
1 parent fddfecf415
commit 2e090903c2
2 files changed
+73 -29

No files matched your search

+14
View File
@@ -4,6 +4,20 @@ All notable changes to this project will be documented in this file. See [standa
## Version 2026.10.14-it-tools-pro
### 🩹 修复:面单导入后仍有改不了的字、删条码后仍有痕迹
- **问题 A(有些字改不了)**:文字层用「近白低饱和」判断是否擦除底图,但那个判断**同时门控了"是否生成可编辑元素"**——底色不在阈值内(面单常见的灰条、蓝条、色带)时整段文字被静默丢弃:既不生成元素、也不擦除,永久留在底图上
- 实测靶子:蓝条 (184,212,240) 亮度 207 达标但**色差 56 > 40** → 直接被丢弃
- **问题 B(删条码仍有痕迹)**:条码擦除只覆盖 `zxing` 给的**紧贴条码 bbox**,人读字符(条码下方那行小字)与紧邻的分区线在 bbox 之外;且这些字又被 `overlapCode` 直接 `continue` 掉 → 既没擦也没成为元素,删掉条码元素后原样残留
- **修复**:
- `boxBackground()` 增加返回该框的**背景中位色**(文字像素是少数,被中位数排除)
- 擦除改用**采样到的背景色**:白底擦白(原行为)、灰条擦灰、蓝条擦蓝 —— 不再留下白块
- **任何底色上的文字都生成可编辑元素**;深色底(亮度 < 110)自动把替换文字设为白色,保证反白字可见
- 条码占位范围扩展为 **条码 + 四周 1mm + 下方 min(0.45×条高, 8mm)**,一并擦除人读字符与紧邻装饰线;`codeBoxes` 按扩展后的范围登记,文字层据此跳过(人读字符归条码元素的 `showValue` 渲染,改内容会同步更新)
- **验证**(300dpi 真实 PDF 靶子 + 底图像素采样):
- 导入提示 `提取 1 个条码/二维码 + 3 段文字`(灰条字 / 蓝条字 / 白底字各 1,修复前灰蓝两段为 0)
- 条码下人读字符带暗像素 **0.00%**(66332 px)、点划线带 **0.00%**(30282 px)→ 无痕迹
- 灰条主色 (209,209,209)、蓝条主色 (184,212,240),两区黑字残留均 **0.00%** → 擦成同色、无白块
### 🧲 试用浮条从「倒计时催命」改为「价值 + 安全感」
- **问题**:浮条只显示 `免费试用 X 剩余 27:52 + 购买授权`——只制造稀缺、不给任何"值得买"的理由;`购买授权` 是动作不是利益;刚做好的**每日重置**完全没露面,等于藏着白做
- **改动**(未授权态):
+59 -29
View File
@@ -397,9 +397,20 @@ async function onPdfFile(e: Event) {
if (wPx < 4 || hPx < 4) {
continue;
}
// 擦除底图上的原条码(避免与新条码重影)
// 擦除底图上的原条码(避免与新条码重影)。
// zxing 给的是紧贴条码的 bbox,人读字符(条码下方那行小字)与紧邻的装饰线
// 落在 bbox 之外 —— 必须一并纳入擦除与占位,否则删掉条码元素后
// 底图仍残留这行字与框线(用户看到的"痕迹")。
const pxPerMm = EXPORT_DPI / 25.4;
const padPx = Math.max(2, Math.round(1 * pxPerMm)); // 四周 1mm
const hrExtra = Math.min(hPx * 0.45, 8 * pxPerMm); // 下方人读字符条,上限 8mm
ctx.fillStyle = '#ffffff';
ctx.fillRect(Math.floor(x0), Math.floor(y0), Math.ceil(wPx), Math.ceil(hPx));
ctx.fillRect(
Math.floor(x0 - padPx),
Math.floor(y0 - padPx),
Math.ceil(wPx + padPx * 2),
Math.ceil(hPx + padPx + hrExtra),
);
const isQR = /qr|aztec|datamatrix|pdf417/i.test(String(sym.format || ''));
const el = {
id: newId(),
@@ -412,7 +423,13 @@ async function onPdfFile(e: Event) {
...(isQR ? {} : { format: mapCodeFormat(String(sym.format || '')), showValue: true }),
} as LabelElement;
codeEls.push(el);
codeBoxes.push({ x: el.x, y: el.y, w: el.w, h: el.h });
// 占位框按"条码 + 人读字符条"的实际范围登记,供文字层跳过使用
codeBoxes.push({
x: Math.max(0, el.x - 1),
y: Math.max(0, el.y - 1),
w: el.w + 2,
h: el.h + hrExtra / pxPerMm + 2,
});
}
}
catch { /* 无条码或识别失败:跳过 */ }
@@ -539,22 +556,32 @@ async function onPdfFile(e: Event) {
let w = Math.min(canvas.width - x, Math.round(wMm * k));
let h = Math.min(canvas.height - y, Math.round(hMm * k));
if (w <= 0 || h <= 0) {
return { lum: 255, spread: 0 };
return { lum: 255, spread: 0, r: 255, g: 255, b: 255 };
}
const d = ctx.getImageData(x, y, w, h).data;
const lum: number[] = [];
const spr: number[] = [];
const rs: number[] = [];
const gs: number[] = [];
const bs: number[] = [];
for (let i = 0; i < d.length; i += 4) {
const r = d[i];
const g = d[i + 1];
const b = d[i + 2];
lum.push(r * 0.299 + g * 0.587 + b * 0.114);
spr.push(Math.max(r, g, b) - Math.min(r, g, b));
rs.push(r);
gs.push(g);
bs.push(b);
}
lum.sort((a, b2) => a - b2);
spr.sort((a, b2) => a - b2);
rs.sort((a, b2) => a - b2);
gs.sort((a, b2) => a - b2);
bs.sort((a, b2) => a - b2);
const mid = Math.floor(lum.length / 2);
return { lum: lum[mid], spread: spr[mid] };
// 中位色 = 该框的背景色(文字像素是少数,被中位数排除在外)
return { lum: lum[mid], spread: spr[mid], r: rs[mid], g: gs[mid], b: bs[mid] };
}
const textEls: LabelElement[] = [];
try {
@@ -618,31 +645,34 @@ async function onPdfFile(e: Event) {
if (overlapCode) {
continue;
}
// 只在「近白、低饱和」背景处擦除底图原字——彩色/深色区域保留原字且不叠加,避免白块与重影
// 用底图采样到的背景中位色擦除原字:
// · 白底 → 擦成白(原有行为)
// · 灰条 / 色带 → 擦成同色,不再留下白块
// 且**任何底色上的文字都生成可编辑元素**。之前"背景非近白就整段丢弃"
// 会让面单灰条 / 色带上的字既改不了、也擦不掉,永久留在底图上。
const bg = boxBackground(elX, elY, txtW, elH);
if (bg.lum >= 205 && bg.spread <= 40) {
const kk = EXPORT_DPI / 25.4;
ctx.fillStyle = '#ffffff';
ctx.fillRect(
Math.max(0, Math.round(elX * kk)),
Math.max(0, Math.round(elY * kk)),
Math.max(1, Math.round(txtW * kk)),
Math.max(1, Math.round(elH * kk)),
);
textEls.push({
id: newId(),
type: 'text',
x: Math.round(elX * 10) / 10,
y: Math.max(0, Math.round(elY * 10) / 10),
w: Math.round(elW * 10) / 10,
h: Math.round(elH * 10) / 10,
text: str,
fontSize: Math.round(fs * 10) / 10,
bold: false,
align: 'left',
color: '#000000',
});
}
const kk = EXPORT_DPI / 25.4;
ctx.fillStyle = `rgb(${bg.r}, ${bg.g}, ${bg.b})`;
ctx.fillRect(
Math.max(0, Math.round(elX * kk)),
Math.max(0, Math.round(elY * kk)),
Math.max(1, Math.round(txtW * kk)),
Math.max(1, Math.round(elH * kk)),
);
textEls.push({
id: newId(),
type: 'text',
x: Math.round(elX * 10) / 10,
y: Math.max(0, Math.round(elY * 10) / 10),
w: Math.round(elW * 10) / 10,
h: Math.round(elH * 10) / 10,
text: str,
fontSize: Math.round(fs * 10) / 10,
bold: false,
align: 'left',
// 深色底上的原字通常是反白的,替换后也要保持可见
color: bg.lum < 110 ? '#ffffff' : '#000000',
});
}
}
catch { /* 无文字层或提取失败:仅保留底图 */ }