feat(label): 二维码贴右下角,底边与末行对齐

文字纵向铺满整张纸,二维码移到右下角、底边和日期底边齐平;
所有行仍让开二维码静区,长品名多折行也不压码。
This commit is contained in:
雨天
2026-11-23 12:44:34 +08:00
parent 5e980adfd3
commit cecfcad8c7
3 changed files with 19 additions and 22 deletions
+7 -10
View File
@@ -270,21 +270,14 @@ def plan_label(cfg, title, fields, qr_data=''):
def build(f, allow):
tmp = []
y = my
full_w = w - mx * 2 # 二维码静区以下的行可以用整宽
qr_safe = (qr['y'] + qr['size'] + 4 * qr['cell']) if qr else 0
for i, t in enumerate(texts):
wid = full_w if (qr and y >= qr_safe) else text_w
if _text_width(t, f) <= wid * slack:
tmp.append(t) # 容差内原样放,吃掉右侧留白,不截字
y += f * _LINE_RATIO
if _text_width(t, f) <= text_w * slack:
tmp.append(t) # 容差内原样放,吃掉右侧留白,不截字
continue
if i not in allow:
return None
# max_lines 给足:宁可折很多行/降字号,也绝不截字
part = _wrap(t, f, wid, 999)
tmp.extend(part)
y += len(part) * f * _LINE_RATIO
tmp.extend(_wrap(t, f, text_w, 999))
if len(tmp) * f * _LINE_RATIO > avail_h:
return None
return tmp
@@ -347,6 +340,10 @@ def plan_label(cfg, title, fields, qr_data=''):
lines.append({'text': t, 'font': font, 'x': mx, 'y': int(y),
'w': int(_text_width(t.rstrip(), font))})
y += step
# 二维码贴右下角:底边和最后一行底边对齐(现场参考图的版式)。
# 放在最后算,是因为要先知道文字铺完最后一行落在哪。
if qr and lines:
qr['y'] = max(my, int(lines[-1]['y'] + font - qr['size']))
gap_mm = _num(cfg.get('gap_mm'), 2)
if gap_mm < 0:
+10 -8
View File
@@ -61,17 +61,12 @@ def fail_reasons(p, cfg, qr):
q = p['qr']
out = []
gap = int(round(2 * dpm)) if q else 0
quiet = (4 * q['cell']) if q else 0
qr_bottom = (q['y'] + q['size']) if q else 0
for ln in p['lines']:
if ln['x'] < mx - 1:
out.append('行越左边界 x=%d' % ln['x'])
if ln['x'] + ln['w'] > w:
out.append('行越右纸边 x+w=%d > %d' % (ln['x'] + ln['w'], w))
# 只有与码垂直范围相交(含下方静区)的行才需要让出码区;
# 码下方更远的行可以用整宽。
if q and ln['y'] < qr_bottom + quiet \
and ln['x'] + ln['w'] > q['x'] - gap:
if q and ln['x'] + ln['w'] > q['x'] - gap:
out.append('行离码不足 %dmm x+w=%d, 码左沿=%d'
% (gap // int(round(dpm)), ln['x'] + ln['w'], q['x']))
if p['lines']:
@@ -88,6 +83,14 @@ def fail_reasons(p, cfg, qr):
out.append('二维码越右边界')
if q['y'] + q['size'] > h - my + 1:
out.append('二维码越下边界')
if q['y'] < my - 1:
out.append('二维码越上边界')
# 二维码底边和最后一行底边对齐(参考图版式)
if p['lines']:
last_bottom = p['lines'][-1]['y'] + p['font']
if abs((q['y'] + q['size']) - last_bottom) > 1:
out.append('二维码底边未与末行对齐 码底=%d 末行=%d'
% (q['y'] + q['size'], last_bottom))
return out
@@ -139,8 +142,7 @@ _p = L.plan_label({'width_mm': 60, 'height_mm': 40, 'dpi': 203}, '分拣标签',
'数量: 1.00 桶', '日期: 11-04 19:02'],
qr_data='CT2026110400001234')
_q = _p['qr']
_gap = min([_q['x'] - (ln['x'] + ln['w']) for ln in _p['lines']
if ln['y'] < _q['y'] + _q['size']] or [_q['x']])
_gap = min(_q['x'] - (ln['x'] + ln['w']) for ln in _p['lines'])
check('示例文字离码 ≥2mm(16 dots)', _gap >= 16, 'gap=%d' % _gap)
check('示例字没被截断', not any('截断' in str(x) for x in _p['warnings']),
str(_p['warnings']))
+2 -4
View File
@@ -29,11 +29,9 @@
【v1.0.69 标签改左右布局 + 点卡不再抖(2026-11-23)】
◆ 标签改成左右布局(文字在左、二维码在右)
· 文字块改成贴顶排版,和右上角二维码在同一条水平线上;以前文字块
垂直居中,看着像“上面一块码、中间一块字”两段。
◆ 标签改成左右布局(文字在左、二维码在右下)
· 文字从第一行到最后一行均匀铺满整张纸的高度,底部不再空一大块。
· 落在二维码下方(静区以外)的行用整条纸宽,长品名/日期能排得更开。
· 二维码贴右下角,底边和最后一行(日期)底边对齐。
· 没有二维码的标签(调试预览)仍按原来的垂直居中,版面不变。
· 安装包出厂纸型改为 60×40mm(203dpi 下 480×320 点)。
· 老机器升级不会覆盖 config.json,纸型仍是原来的设置;需要时走