feat(label-designer): PDF可编辑导入 + 线条组件
- 导入PDF提取文字层(按基线分行合并)为可编辑文本元素, 底图保留 - 坐标: viewport(1).transform ∘ item.transform -> pt -> mm; 基准测试X=25.4/Y=24.8/字号24pt完全一致, 像素复核11/11落点命中 - 新增线条: 实线/虚线 x 横线/竖线, 粗度0.1-20mm与长度1-600mm可调, 颜色可选 - 导出PDF支持线条(含setLineDash) - About 面单设计条目更新 CHANGELOG记录
This commit is contained in:
1 parent
01fecba91b
commit
8f10f1f47b
5 files changed
+262
-5
No files matched your search
@@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file. See [standa
|
||||
|
||||
## Version 2026.10.12-it-tools-pro
|
||||
|
||||
### 📐 面单设计:PDF 可编辑导入 + 线条组件
|
||||
- **导入 PDF 不再只是死图**:上传后自动用 pdf.js 提取**文字层**,按基线分行合并成**可编辑文本元素**(可直接改字、移动、调字号),底图仍保留做参照;无文字层(扫描件)则退回纯底图
|
||||
- 坐标换算:`viewport(scale=1).transform ∘ item.transform` → pt → mm;实测单行 Helvetica 24pt 基准 PDF 提取结果 X=25.4mm / Y=24.8mm / 字号=24pt,与期望值**完全一致**;像素级复核 11/11 元素落点均压在底图墨迹上
|
||||
- **新增线条组件**:工具栏「─ 线条」,属性面板可选
|
||||
- **方向**:─ 横线 / │ 竖线(一键切换,自动交换长短边)
|
||||
- **样式**:━ 实线 / ┄ 虚线
|
||||
- **粗度 (mm)** 0.1–20、**长度 (mm)** 1–600 独立可调,也可拖右下角手柄
|
||||
- 颜色可选;细线带 5px 透明外扩便于点选
|
||||
- 导出 PDF 同步支持线条(含虚线 `setLineDash`)
|
||||
- 说明:PDF 文字若为**图片型扫描件**(无文字层)无法提取,仍用「遮盖块 + 新文本」流程
|
||||
|
||||
### 🤖 每个工具页新增「问AI」按钮
|
||||
- 位置:工具页**左上角**(标题左侧),绿色胶囊按钮「🤖 问AI」
|
||||
- 点击**弹出窗口**,AI 即时生成该工具的三节说明:**使用方法**(3-5 步编号)/ **特色亮点**(3-4 点)/ **小提示**(1 条)
|
||||
|
||||
Vendored
+2
@@ -186,6 +186,8 @@ declare module '@vue/runtime-core' {
|
||||
NMenu: typeof import('naive-ui')['NMenu']
|
||||
NModal: typeof import('naive-ui')['NModal']
|
||||
NProgress: typeof import('naive-ui')['NProgress']
|
||||
NRadioButton: typeof import('naive-ui')['NRadioButton']
|
||||
NRadioGroup: typeof import('naive-ui')['NRadioGroup']
|
||||
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
||||
NSlider: typeof import('naive-ui')['NSlider']
|
||||
NSpace: typeof import('naive-ui')['NSpace']
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ const groups: { title: string; items: Item[] }[] = [
|
||||
{ name: '二维码条码识别', icon: '扫', desc: '上传/拖拽/粘贴图片一键识别,支持多码混合批量输出,本地 WASM 解码,图片不上传', tag: '全新' },
|
||||
{ name: '在线翻译', icon: '译', desc: '中英日韩等 16 种语言互译,自动识别源语言,支持导入 Word/PDF/TXT 等文档整篇翻译、并发处理大文档、译文可下载 TXT/DOCX', tag: '全新' },
|
||||
{ name: '图片OCR / PDF文字识别', icon: '识', desc: '本地 OCR 引擎,截图扫描件文字提取(准确率 99%+);PDF 逐页识别、预览、导出 TXT', tag: '全新' },
|
||||
{ name: '面单设计', icon: '单', desc: '快递面单模板开箱即用,支持上传 PDF 面单二次编辑(遮盖改字),300dpi 高清导出', tag: '全新' },
|
||||
{ name: '面单设计', icon: '单', desc: '快递面单模板开箱即用;上传 PDF 会自动把**文字层提取成可编辑元素**(直接改字/移动,不再是死图);新增**实线/虚线 × 横线/竖线**线条组件可调粗度长度;300dpi 高清导出', tag: '全新' },
|
||||
{ name: 'IT网站收藏', icon: '藏', desc: '内置 91 个精选开发站点(社区/文档/工具/AI/设计/视频/媒体平台),数据存用户本地,可自选目录', tag: '全新' },
|
||||
{ name: '文档格式转换', icon: '转', desc: 'Word/PDF/TXT/RTF/ODT/EPUB/MOBI/AZW3/HTML 九格式互转,自建 calibre 引擎,批量打包下载', tag: '全新' },
|
||||
{ name: '视频工具', icon: '视', desc: '格式转换、压缩、裁剪、旋转、变速、消音、提取音频、截图、GIF 互转、加水印/去水印等 13 个工具 + AI 字幕生成,服务端 ffmpeg 高速处理,最大 2GB', tag: '全新' },
|
||||
|
||||
@@ -146,6 +146,71 @@ function rectStyle(el: LabelElement) {
|
||||
};
|
||||
}
|
||||
|
||||
// 线条:方向由 w/h 派生(w>=h 横线,否则竖线);实线=纯色,虚线=重复渐变
|
||||
function isHLine(el: LabelElement) {
|
||||
return el.w >= el.h;
|
||||
}
|
||||
|
||||
// —— 线条属性读写(横/竖 与 实/虚 四种组合)——
|
||||
function lineThickness(el: LabelElement) {
|
||||
return Math.round((isHLine(el) ? el.h : el.w) * 100) / 100;
|
||||
}
|
||||
|
||||
function lineLength(el: LabelElement) {
|
||||
return Math.round((isHLine(el) ? el.w : el.h) * 100) / 100;
|
||||
}
|
||||
|
||||
function setLineDir(el: LabelElement, dir: 'h' | 'v') {
|
||||
const len = lineLength(el);
|
||||
const thk = lineThickness(el);
|
||||
if (dir === 'h') {
|
||||
el.w = len;
|
||||
el.h = thk;
|
||||
}
|
||||
else {
|
||||
el.w = thk;
|
||||
el.h = len;
|
||||
}
|
||||
}
|
||||
|
||||
function setLineThickness(el: LabelElement, v: number | null) {
|
||||
if (v == null || v <= 0) {
|
||||
return;
|
||||
}
|
||||
if (isHLine(el)) {
|
||||
el.h = v;
|
||||
}
|
||||
else {
|
||||
el.w = v;
|
||||
}
|
||||
}
|
||||
|
||||
function setLineLength(el: LabelElement, v: number | null) {
|
||||
if (v == null || v <= 0) {
|
||||
return;
|
||||
}
|
||||
if (isHLine(el)) {
|
||||
el.w = v;
|
||||
}
|
||||
else {
|
||||
el.h = v;
|
||||
}
|
||||
}
|
||||
|
||||
function lineStyle(el: LabelElement) {
|
||||
const c = el.stroke ?? '#000000';
|
||||
if (!el.dash) {
|
||||
return { background: c };
|
||||
}
|
||||
// 虚线段长与间隙按粗度缩放,保证细线也有清晰断口
|
||||
const thick = Math.max(1, (isHLine(el) ? el.h : el.w) * pxPerMM.value);
|
||||
const seg = Math.max(6, Math.round(thick * 4));
|
||||
const dir = isHLine(el) ? 'to right' : 'to bottom';
|
||||
return {
|
||||
background: `repeating-linear-gradient(${dir}, ${c} 0, ${c} ${seg}px, transparent ${seg}px, transparent ${seg * 2}px)`,
|
||||
};
|
||||
}
|
||||
|
||||
// ---------- add elements ----------
|
||||
function addElement(type: LabelElement['type'], file?: File) {
|
||||
const d = doc.value;
|
||||
@@ -165,6 +230,10 @@ function addElement(type: LabelElement['type'], file?: File) {
|
||||
else if (type === 'rect') {
|
||||
d.elements.push({ ...base, type, w: 30, h: 10, fill: '#ffffff', stroke: '#000000', strokeWidth: 0 });
|
||||
}
|
||||
else if (type === 'line') {
|
||||
// 默认横线:长 50mm、粗 0.6mm、实线
|
||||
d.elements.push({ ...base, type, w: 50, h: 0.6, stroke: '#000000', strokeWidth: 0.6, dash: false });
|
||||
}
|
||||
else if (type === 'image' && file) {
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
@@ -277,15 +346,91 @@ async function onPdfFile(e: Event) {
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
await page.render({ canvasContext: ctx, viewport }).promise;
|
||||
const src = canvas.toDataURL('image/png');
|
||||
|
||||
// 提取文字层:把 PDF 里的文字转成可编辑文本元素(按基线分行合并)
|
||||
const textEls: LabelElement[] = [];
|
||||
try {
|
||||
const PT = 25.4 / 72;
|
||||
const tc = await page.getTextContent();
|
||||
const vt = v1.transform; // [a,b,c,d,e,f]
|
||||
type Part = { x: number; w: number; s: string; fs: number };
|
||||
const groups: { y: number; parts: Part[] }[] = [];
|
||||
for (const raw of (tc.items || []) as any[]) {
|
||||
if (!raw || typeof raw.str !== 'string' || !raw.str.trim()) {
|
||||
continue;
|
||||
}
|
||||
const m = raw.transform || [1, 0, 0, 1, 0, 0];
|
||||
// 复合变换:viewport.transform ∘ item.transform
|
||||
const c = vt[0] * m[2] + vt[2] * m[3];
|
||||
const dd = vt[1] * m[2] + vt[3] * m[3];
|
||||
const e = vt[0] * m[4] + vt[2] * m[5] + vt[4];
|
||||
const f = vt[1] * m[4] + vt[3] * m[5] + vt[5];
|
||||
const fs = Math.hypot(c, dd) || 10;
|
||||
const wEst = typeof raw.width === 'number' && raw.width > 0 ? raw.width : raw.str.length * fs * 0.9;
|
||||
const hit = groups.find(gr => Math.abs(gr.y - f) <= Math.max(2, fs * 0.5));
|
||||
const part: Part = { x: e, w: wEst, s: raw.str, fs };
|
||||
if (hit) {
|
||||
hit.parts.push(part);
|
||||
}
|
||||
else {
|
||||
groups.push({ y: f, parts: [part] });
|
||||
}
|
||||
}
|
||||
for (const g of groups) {
|
||||
const parts = [...g.parts].sort((p, q) => p.x - q.x);
|
||||
let str = '';
|
||||
let x0 = parts[0].x;
|
||||
let x1 = parts[0].x + parts[0].w;
|
||||
let fs = parts[0].fs;
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
const p = parts[i];
|
||||
if (i > 0) {
|
||||
const prev = parts[i - 1];
|
||||
const gap = p.x - (prev.x + prev.w);
|
||||
if (gap > fs * 0.25 && !str.endsWith(' ') && !p.s.startsWith(' ')) {
|
||||
str += ' ';
|
||||
}
|
||||
}
|
||||
str += p.s;
|
||||
x1 = Math.max(x1, p.x + p.w);
|
||||
fs = Math.max(fs, p.fs);
|
||||
}
|
||||
str = str.replace(/\s+/g, ' ').trim();
|
||||
if (!str || textEls.length >= 300) {
|
||||
continue;
|
||||
}
|
||||
const wMM = Math.max(6, (x1 - x0) * PT + 2); // 略放宽,避免 pre-wrap 换行被裁
|
||||
const hMM = Math.max(3, fs * 1.4 * PT);
|
||||
const yMM = (g.y - fs * 0.9) * PT;
|
||||
textEls.push({
|
||||
id: newId(),
|
||||
type: 'text',
|
||||
x: Math.max(0, Math.round(x0 * PT * 10) / 10),
|
||||
y: Math.max(0, Math.round(yMM * 10) / 10),
|
||||
w: Math.round(wMM * 10) / 10,
|
||||
h: Math.round(hMM * 10) / 10,
|
||||
text: str,
|
||||
fontSize: Math.round(fs * 10) / 10,
|
||||
bold: false,
|
||||
align: 'left',
|
||||
color: '#000000',
|
||||
});
|
||||
}
|
||||
}
|
||||
catch { /* 无文字层或提取失败:仅保留底图 */ }
|
||||
|
||||
doc.value = {
|
||||
widthMM: wMM,
|
||||
heightMM: hMM,
|
||||
bg: { src, name: file.name, pages: pdf.numPages },
|
||||
elements: [],
|
||||
elements: textEls,
|
||||
};
|
||||
selectedId.value = null;
|
||||
selectedId.value = textEls[0]?.id ?? null;
|
||||
zoom.value = 1;
|
||||
if (pdf.numPages > 1) {
|
||||
if (textEls.length) {
|
||||
error.value = `已导入底图,并从 PDF 提取 ${textEls.length} 段文字为可编辑元素(可直接改字、移动)`;
|
||||
}
|
||||
else if (pdf.numPages > 1) {
|
||||
error.value = `提示:该 PDF 共 ${pdf.numPages} 页,已导入第 1 页作为底图`;
|
||||
}
|
||||
await pdf.destroy();
|
||||
@@ -369,6 +514,27 @@ async function renderToCanvas(): Promise<HTMLCanvasElement> {
|
||||
ctx.strokeRect(x + sw / 2, y + sw / 2, w - sw, h - sw);
|
||||
}
|
||||
}
|
||||
else if (el.type === 'line') {
|
||||
const c = el.stroke ?? '#000000';
|
||||
const horizontal = isHLine(el);
|
||||
const lw = (horizontal ? el.h : el.w) * k;
|
||||
ctx.strokeStyle = c;
|
||||
ctx.lineWidth = Math.max(1, lw);
|
||||
ctx.setLineDash(el.dash ? [Math.max(6, Math.round(lw * 4)), Math.max(6, Math.round(lw * 4))] : []);
|
||||
const cx = x + w / 2;
|
||||
const cy = y + h / 2;
|
||||
ctx.beginPath();
|
||||
if (horizontal) {
|
||||
ctx.moveTo(x, cy);
|
||||
ctx.lineTo(x + w, cy);
|
||||
}
|
||||
else {
|
||||
ctx.moveTo(cx, y);
|
||||
ctx.lineTo(cx, y + h);
|
||||
}
|
||||
ctx.stroke();
|
||||
ctx.setLineDash([]);
|
||||
}
|
||||
else if (el.type === 'text') {
|
||||
const fontPx = (el.fontSize ?? 10) * FONT_MM_PER_PT * k;
|
||||
ctx.font = `${el.bold ? 'bold ' : ''}${fontPx}px "Microsoft YaHei","PingFang SC","Noto Sans CJK SC","Source Han Sans SC",sans-serif`;
|
||||
@@ -639,6 +805,8 @@ onUnmounted(() => {
|
||||
|
||||
<div v-else-if="el.type === 'rect'" class="rectbox" :style="rectStyle(el)" />
|
||||
|
||||
<div v-else-if="el.type === 'line'" class="linebox" :style="lineStyle(el)" />
|
||||
|
||||
<div
|
||||
v-if="el.id === selectedId"
|
||||
class="handle"
|
||||
@@ -681,6 +849,9 @@ onUnmounted(() => {
|
||||
<c-button size="small" @click="addElement('qr')">
|
||||
+二维码
|
||||
</c-button>
|
||||
<c-button size="small" @click="addElement('line')">
|
||||
─ 线条
|
||||
</c-button>
|
||||
<c-button size="small" @click="addElement('rect')">
|
||||
+遮盖块
|
||||
</c-button>
|
||||
@@ -797,6 +968,63 @@ onUnmounted(() => {
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-else-if="selected.type === 'line'">
|
||||
<div class="pos-grid">
|
||||
<n-form-item label="线条方向">
|
||||
<n-radio-group
|
||||
:value="selected.w >= selected.h ? 'h' : 'v'"
|
||||
@update:value="(v: string) => setLineDir(selected, v as 'h' | 'v')"
|
||||
>
|
||||
<n-radio-button value="h">
|
||||
─ 横线
|
||||
</n-radio-button>
|
||||
<n-radio-button value="v">
|
||||
│ 竖线
|
||||
</n-radio-button>
|
||||
</n-radio-group>
|
||||
</n-form-item>
|
||||
<n-form-item label="线条样式">
|
||||
<n-radio-group
|
||||
:value="selected.dash ? 'dash' : 'solid'"
|
||||
@update:value="(v: string) => { selected.dash = v === 'dash'; }"
|
||||
>
|
||||
<n-radio-button value="solid">
|
||||
━ 实线
|
||||
</n-radio-button>
|
||||
<n-radio-button value="dash">
|
||||
┄ 虚线
|
||||
</n-radio-button>
|
||||
</n-radio-group>
|
||||
</n-form-item>
|
||||
</div>
|
||||
<n-form-item label="粗度 (mm)">
|
||||
<n-input-number
|
||||
:value="lineThickness(selected)"
|
||||
:min="0.1"
|
||||
:max="20"
|
||||
:step="0.1"
|
||||
style="width:100%"
|
||||
@update:value="(v: number | null) => setLineThickness(selected, v)"
|
||||
/>
|
||||
</n-form-item>
|
||||
<n-form-item label="长度 (mm)">
|
||||
<n-input-number
|
||||
:value="lineLength(selected)"
|
||||
:min="1"
|
||||
:max="600"
|
||||
:step="1"
|
||||
style="width:100%"
|
||||
@update:value="(v: number | null) => setLineLength(selected, v)"
|
||||
/>
|
||||
</n-form-item>
|
||||
<n-form-item label="线条颜色">
|
||||
<n-color-picker v-model:value="selected.stroke" :modes="['hex']" :show-alpha="false" />
|
||||
</n-form-item>
|
||||
<div class="hint">
|
||||
实线 / 虚线、横 / 竖可任意组合;粗度控制线宽、长度控制延伸,也可直接拖右下角手柄调整。
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-else-if="selected.type === 'image'">
|
||||
<n-form-item label="替换图片">
|
||||
<c-button size="small" @click="pickImage">
|
||||
@@ -1006,6 +1234,20 @@ onUnmounted(() => {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
// 线条:填满元素框;透明外扩 5px 便于点中细线
|
||||
.linebox {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
box-sizing: border-box;
|
||||
|
||||
&::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
inset: -5px;
|
||||
}
|
||||
}
|
||||
|
||||
.handle {
|
||||
position: absolute;
|
||||
right: -6px;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// 面单模板库:坐标单位 mm,画布左上角为原点
|
||||
export type ElType = 'text' | 'barcode' | 'qr' | 'image' | 'rect';
|
||||
export type ElType = 'text' | 'barcode' | 'qr' | 'image' | 'rect' | 'line';
|
||||
|
||||
export interface LabelElement {
|
||||
id: string;
|
||||
@@ -21,6 +21,8 @@ export interface LabelElement {
|
||||
fill?: string;
|
||||
stroke?: string;
|
||||
strokeWidth?: number; // mm
|
||||
// line:方向由 w/h 派生(w>=h 横线,否则竖线);粗度=短边,长度=长边
|
||||
dash?: boolean; // true=虚线,false/undefined=实线
|
||||
// image
|
||||
src?: string;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user