|
|
@ -441,6 +441,7 @@ export class ZPLGenerator { |
|
|
generateQRCodeZPL(element, x, y) { |
|
|
generateQRCodeZPL(element, x, y) { |
|
|
const orientation = this.config.qrcodeOrientation |
|
|
const orientation = this.config.qrcodeOrientation |
|
|
const data = element.data || '' |
|
|
const data = element.data || '' |
|
|
|
|
|
const showContent = element.showContent !== undefined ? element.showContent : false |
|
|
|
|
|
|
|
|
// 将毫米转换为ZPL尺寸单位,使用精确的DPI转换公式
|
|
|
// 将毫米转换为ZPL尺寸单位,使用精确的DPI转换公式
|
|
|
// 二维码的尺寸参数是模块大小,通常1-10
|
|
|
// 二维码的尺寸参数是模块大小,通常1-10
|
|
|
@ -459,15 +460,43 @@ export class ZPLGenerator { |
|
|
size = Math.max(size, 2) // 短数据使用较小尺寸
|
|
|
size = Math.max(size, 2) // 短数据使用较小尺寸
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 尝试使用更明确的二维码格式
|
|
|
|
|
|
// 对于长数字内容,使用数字模式可能更有效
|
|
|
|
|
|
|
|
|
let zpl = '' |
|
|
|
|
|
|
|
|
|
|
|
// 生成二维码
|
|
|
if (/^\d+$/.test(data)) { |
|
|
if (/^\d+$/.test(data)) { |
|
|
// 纯数字内容,使用数字模式
|
|
|
// 纯数字内容,使用数字模式
|
|
|
return `^FO${x},${y}^BQ${orientation},2,${size}^FDMN,${data}^FS` |
|
|
|
|
|
|
|
|
zpl = `^FO${x},${y}^BQ${orientation},2,${size}^FDMN,${data}^FS` |
|
|
} else { |
|
|
} else { |
|
|
// 混合内容,使用自动模式
|
|
|
// 混合内容,使用自动模式
|
|
|
return `^FO${x},${y}^BQ${orientation},2,${size}^FDMA,${data}^FS` |
|
|
|
|
|
|
|
|
zpl = `^FO${x},${y}^BQ${orientation},2,${size}^FDMA,${data}^FS` |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 如果需要显示明文,在二维码下方添加文本
|
|
|
|
|
|
if (showContent && data) { |
|
|
|
|
|
// 计算文本位置:二维码下方,居中对齐
|
|
|
|
|
|
const textY = y + sizeInDots + 10 // 二维码下方留10个点的间距
|
|
|
|
|
|
const fontSize = 15 // 根据二维码大小调整字体大小
|
|
|
|
|
|
|
|
|
|
|
|
// 设置中文字体支持
|
|
|
|
|
|
zpl += `\n^CI28^CWJ,E:ARIAL.TTF^CFJ,${fontSize}` |
|
|
|
|
|
|
|
|
|
|
|
// 计算文本宽度以实现居中对齐
|
|
|
|
|
|
const estimatedTextWidth = this.estimateTextWidth(data, fontSize) |
|
|
|
|
|
let textX = x + Math.round((sizeInDots - estimatedTextWidth) / 2) |
|
|
|
|
|
textX = Math.max(x, textX) // 确保不超出左边界
|
|
|
|
|
|
|
|
|
|
|
|
// 如果文本太长,使用多行显示
|
|
|
|
|
|
if (data.length > 20) { |
|
|
|
|
|
const lineWidth = Math.max(sizeInDots, estimatedTextWidth) |
|
|
|
|
|
const lineRows = Math.min(3, Math.ceil(data.length / 20)) // 最多3行
|
|
|
|
|
|
zpl += `\n^FO${x},${textY}^FB${lineWidth},${lineRows},0,C^CFJ,${fontSize}^FD${data}^FS` |
|
|
|
|
|
} else { |
|
|
|
|
|
// 单行文本
|
|
|
|
|
|
zpl += `\n^FO${textX},${textY}^FD${data}^FS` |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return zpl |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|