Skip to content

Commit abe20ee

Browse files
committed
Nhãn In TZe_24mm_C thêm khả năng căn chỉnh văn bản bên dưới logo công ty của tài sản, đồng thời ưu tiên logo công ty của tài sản.
1 parent fb3712d commit abe20ee

File tree

2 files changed

+132
-2
lines changed

2 files changed

+132
-2
lines changed

app/Models/Labels/Tapes/Brother/TZe_24mm_C.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class TZe_24mm_C extends TZe_24mm
1414
private const LABEL_MARGIN = - 0.35;
1515
private const FIELD_SIZE = 3.20;
1616
private const FIELD_MARGIN = 0.15;
17+
private const BORDER_TEXT_SIZE = 1.60; // small text for border (unused for margins now)
1718

1819
public function getUnit()
1920
{
@@ -37,7 +38,8 @@ public function getSupport2DBarcode()
3738
}
3839
public function getSupportFields()
3940
{
40-
return 0;
41+
// Support one extra field like TZe_24mm_B
42+
return 1;
4143
}
4244
public function getSupportLogo()
4345
{
@@ -91,14 +93,38 @@ public function write($pdf, $record)
9193
$currentX += $usableWidth - (self::LOGO_MARGIN/2);
9294

9395
if ($record->has('logo')) {
96+
// Adjust logo size to match QR code square size
9497
$logoSize = static::writeImage(
9598
$pdf, $record->get('logo'),
9699
$currentX, $pa->y1,
97-
self::LOGO_MAX_WIDTH, $usableHeight,
100+
$barcodeSize, $barcodeSize,
98101
'L', 'T', 300, true, false, 0
99102
);
103+
104+
// If a field is provided, render its value below the logo area
105+
if ($record->has('fields')) {
106+
$fields = $record->get('fields');
107+
if (is_iterable($fields) && count($fields) > 0) {
108+
$first = $fields[0];
109+
$value = is_array($first) ? ($first['value'] ?? '') : '';
110+
if (!empty($value)) {
111+
// Place text centered under the logo; constrain to area to the right of the QR code
112+
$textY = $pa->y1 + $logoSize[1] + self::TITLE_MARGIN;
113+
$availableWidthRight = $pa->x2 - $currentX; // from currentX to right printable edge
114+
static::writeText(
115+
$pdf, $value,
116+
$currentX, $textY,
117+
'freemono', 'b', self::TAG_SIZE, 'C',
118+
$availableWidthRight, self::TAG_SIZE, true, 0
119+
);
120+
}
121+
}
122+
}
123+
100124
$currentX += $logoSize[0] + self::LOGO_MARGIN;
101125
$usableWidth -= $logoSize[0] + self::LOGO_MARGIN;
102126
}
127+
128+
// Border margin field rendering removed: field now only appears below the logo.
103129
}
104130
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
3+
namespace App\Models\Labels\Tapes\Brother;
4+
5+
class TZe_24mm_C extends TZe_24mm
6+
{
7+
private const BARCODE_MARGIN = 1.40;
8+
private const TAG_SIZE = 4.00;
9+
private const LOGO_MAX_WIDTH = 13.50;
10+
private const LOGO_MARGIN = 2.20;
11+
private const TITLE_SIZE = 2.80;
12+
private const TITLE_MARGIN = 0.50;
13+
private const LABEL_SIZE = 2.00;
14+
private const LABEL_MARGIN = - 0.35;
15+
private const FIELD_SIZE = 3.20;
16+
private const FIELD_MARGIN = 0.15;
17+
18+
public function getUnit()
19+
{
20+
return 'mm';
21+
}
22+
public function getWidth()
23+
{
24+
return 34.0;
25+
}
26+
public function getSupportAssetTag()
27+
{
28+
return true;
29+
}
30+
public function getSupport1DBarcode()
31+
{
32+
return false;
33+
}
34+
public function getSupport2DBarcode()
35+
{
36+
return true;
37+
}
38+
public function getSupportFields()
39+
{
40+
return 0;
41+
}
42+
public function getSupportLogo()
43+
{
44+
return true;
45+
}
46+
public function getSupportTitle()
47+
{
48+
return false;
49+
}
50+
51+
public function preparePDF($pdf)
52+
{
53+
}
54+
55+
public function write($pdf, $record)
56+
{
57+
$pa = $this->getPrintableArea();
58+
59+
$currentX = $pa->x1;
60+
$currentY = $pa->y1;
61+
$usableWidth = $pa->w;
62+
$usableHeight = $pa->h;
63+
64+
$barcodeSize = $pa->h - self::TAG_SIZE;
65+
66+
if ($record->has('barcode2d')) {
67+
static::writeText(
68+
$pdf, $record->get('tag'),
69+
$pa->x1, $pa->y2 - self::TAG_SIZE,
70+
'freemono', 'b', self::TAG_SIZE, 'C',
71+
$barcodeSize, self::TAG_SIZE, true, 0
72+
);
73+
static::write2DBarcode(
74+
$pdf, $record->get('barcode2d')->content, $record->get('barcode2d')->type,
75+
$currentX, $currentY,
76+
$barcodeSize, $barcodeSize
77+
);
78+
$currentX += $barcodeSize + self::BARCODE_MARGIN;
79+
$usableWidth -= $barcodeSize + self::BARCODE_MARGIN;
80+
} else {
81+
static::writeText(
82+
$pdf, $record->get('tag'),
83+
$pa->x1, $pa->y2 - self::TAG_SIZE,
84+
'freemono', 'b', self::TAG_SIZE, 'R',
85+
$usableWidth, self::TAG_SIZE, true, 0
86+
);
87+
}
88+
89+
$usableWidth -= self::LOGO_MAX_WIDTH - self::LOGO_MARGIN;
90+
91+
$currentX += $usableWidth - (self::LOGO_MARGIN/2);
92+
93+
if ($record->has('logo')) {
94+
$logoSize = static::writeImage(
95+
$pdf, $record->get('logo'),
96+
$currentX, $pa->y1,
97+
self::LOGO_MAX_WIDTH, $usableHeight,
98+
'L', 'T', 300, true, false, 0
99+
);
100+
$currentX += $logoSize[0] + self::LOGO_MARGIN;
101+
$usableWidth -= $logoSize[0] + self::LOGO_MARGIN;
102+
}
103+
}
104+
}

0 commit comments

Comments
 (0)