Skip to content

Commit 947ccf9

Browse files
authored
Merge pull request #17868 from Godmartinz/adds-Tze_24mm-variant
Adds Brother Label TZe_24mm_E variant
2 parents 06f313f + 77153c3 commit 947ccf9

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
3+
namespace App\Models\Labels\Tapes\Brother;
4+
5+
class TZe_24mm_E extends TZe_24mm
6+
{
7+
private const BARCODE_MARGIN = 1.50;
8+
private const TAG_SIZE = 2.00;
9+
private const TITLE_SIZE = 2.80;
10+
private const TITLE_MARGIN = 0.50;
11+
private const LABEL_SIZE = 2.00;
12+
private const LABEL_MARGIN = - 0.35;
13+
private const FIELD_SIZE = 2.80;
14+
private const FIELD_MARGIN = 0.15;
15+
private const BARCODE1D_SIZE = - 1.00;
16+
17+
public function getUnit() { return 'mm'; }
18+
public function getWidth() { return 45.0; }
19+
public function getHeight() { return 15; }
20+
public function getSupportAssetTag() { return true; }
21+
public function getSupport1DBarcode() { return true; }
22+
public function getSupport2DBarcode() { return true; }
23+
public function getSupportFields() { return 3; }
24+
public function getSupportLogo() { return false; }
25+
public function getSupportTitle() { return true; }
26+
27+
public function preparePDF($pdf) {}
28+
29+
public function write($pdf, $record) {
30+
$pa = $this->getPrintableArea();
31+
32+
$currentX = $pa->x1;
33+
$currentY = $pa->y1;
34+
$usableWidth = $pa->w;
35+
36+
37+
$usableHeight = $pa->h - self::BARCODE1D_SIZE;
38+
$barcodeSize = $usableHeight - self::TAG_SIZE;
39+
40+
if ($record->has('barcode2d')) {
41+
static::writeText(
42+
$pdf, $record->get('tag'),
43+
$pa->x1, $pa->y2 - self::TAG_SIZE - self::BARCODE1D_SIZE,
44+
'freesans', 'b', self::TAG_SIZE, 'C',
45+
$barcodeSize, self::TAG_SIZE, true, 0
46+
);
47+
static::write2DBarcode(
48+
$pdf, $record->get('barcode2d')->content, $record->get('barcode2d')->type,
49+
$currentX, $currentY,
50+
$barcodeSize, $barcodeSize
51+
);
52+
$currentX += $barcodeSize + self::BARCODE_MARGIN;
53+
$usableWidth -= $barcodeSize + self::BARCODE_MARGIN;
54+
} else {
55+
static::writeText(
56+
$pdf, $record->get('tag'),
57+
$pa->x1, $pa->y2 - self::TAG_SIZE - self::BARCODE1D_SIZE,
58+
'freesans', 'B', self::TAG_SIZE, 'R',
59+
$usableWidth, self::TAG_SIZE, true, 0
60+
);
61+
}
62+
63+
if ($record->has('title')) {
64+
static::writeText(
65+
$pdf, $record->get('title'),
66+
$currentX, $currentY,
67+
'freesans', 'B', self::TITLE_SIZE, 'L',
68+
$usableWidth, self::TITLE_SIZE, true, 0
69+
);
70+
$currentY += self::TITLE_SIZE + self::TITLE_MARGIN;
71+
}
72+
73+
foreach ($record->get('fields') as $field) {
74+
// Write label and value on the same line
75+
// Calculate label width with proportional character spacing
76+
$labelWidth = $pdf->GetStringWidth($field['label'], 'freesans', '', self::LABEL_SIZE);
77+
$charCount = strlen($field['label']);
78+
$spacingPerChar = 0.5;
79+
$totalSpacing = $charCount * $spacingPerChar;
80+
$adjustedWidth = $labelWidth + $totalSpacing;
81+
82+
static::writeText(
83+
$pdf, $field['label'],
84+
$currentX, $currentY,
85+
'freesans', 'B', self::LABEL_SIZE, 'L',
86+
$adjustedWidth, self::LABEL_SIZE, true, 0, $spacingPerChar
87+
);
88+
89+
static::writeText(
90+
$pdf, $field['value'],
91+
$currentX + $adjustedWidth + 2, $currentY,
92+
'freesans', 'B', self::FIELD_SIZE, 'L',
93+
$usableWidth - $adjustedWidth - 2, self::FIELD_SIZE, true, 0, 0.3
94+
);
95+
96+
$currentY += max(self::LABEL_SIZE, self::FIELD_SIZE) + self::FIELD_MARGIN;
97+
}
98+
99+
100+
if ($record->has('barcode1d')) {
101+
static::write1DBarcode(
102+
$pdf, $record->get('barcode1d')->content, $record->get('barcode1d')->type,
103+
$currentX, $barcodeSize + self::BARCODE_MARGIN, $usableWidth - self::TAG_SIZE, self::TAG_SIZE
104+
);
105+
}
106+
}
107+
}

0 commit comments

Comments
 (0)