Skip to content

Commit b2e09ef

Browse files
committed
adds support for GenericTape label printers, includes class for 53mm tape printer
1 parent 251851e commit b2e09ef

File tree

4 files changed

+290
-0
lines changed

4 files changed

+290
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
namespace App\Models\Labels\Tapes\Generic;
4+
5+
use App\Helpers\Helper;
6+
use App\Models\Labels\Label;
7+
8+
abstract class GenericTape extends Label
9+
{
10+
// Default tape width in mm
11+
protected const TAPE_WIDTH = 42.0;
12+
13+
// Tape properties
14+
protected float $width;
15+
protected float $height;
16+
protected bool $continuous;
17+
protected float $spacing = 0.0; // Space between labels for non-continuous tapes
18+
19+
// Margins in mm
20+
protected float $marginTop;
21+
protected float $marginBottom;
22+
protected float $marginLeft;
23+
protected float $marginRight;
24+
25+
// Element sizing in mm
26+
protected float $titleSize;
27+
protected float $titleMargin;
28+
protected float $fieldSize;
29+
protected float $fieldMargin;
30+
protected float $labelSize;
31+
protected float $labelMargin;
32+
protected float $barcodeMargin;
33+
protected float $tagSize;
34+
35+
/**
36+
* Constructor for generic tape
37+
*
38+
* @param float $width Width of the tape in mm
39+
* @param float $height Height of the label in mm (for continuous tapes, this is the default height)
40+
* @param bool $continuous Whether the tape is continuous or pre-cut
41+
* @param float $spacing Spacing between labels for non-continuous tapes (in mm)
42+
*/
43+
public function __construct(float $width, float $height, bool $continuous = true, float $spacing = 0.0) {
44+
$this->width = $width;
45+
$this->height = $height;
46+
$this->continuous = $continuous;
47+
$this->spacing = $spacing;
48+
49+
// Calculate base font size (7% of tape width)
50+
$baseFontSize = static::TAPE_WIDTH * 0.07;
51+
52+
// Calculate margin (4% of tape width)
53+
$margin = static::TAPE_WIDTH * 0.04;
54+
55+
// Set margins
56+
$this->marginTop = $margin;
57+
$this->marginBottom = $margin;
58+
$this->marginLeft = $margin;
59+
$this->marginRight = $margin;
60+
61+
// Calculate and set element sizing based on base font size
62+
$this->titleSize = $baseFontSize; // Same as base font size
63+
$this->titleMargin = $baseFontSize * 0.3; // 30% of base font size
64+
$this->fieldSize = $baseFontSize * 1.1; // 110% of base font size
65+
$this->fieldMargin = $baseFontSize * 0.1; // 10% of base font size
66+
$this->labelSize = $baseFontSize * 0.7; // 70% of base font size
67+
$this->labelMargin = $baseFontSize * -0.1; // -10% of base font size
68+
$this->barcodeMargin = $baseFontSize * 0.5; // 50% of base font size
69+
$this->tagSize = $baseFontSize * 0.8; // 80% of base font size
70+
}
71+
72+
// Unit of measurement
73+
public function getUnit() { return 'mm'; }
74+
75+
// Label dimensions
76+
public function getWidth() { return $this->width; }
77+
public function getHeight() { return $this->height; }
78+
79+
// Margins
80+
public function getMarginTop() { return $this->marginTop; }
81+
public function getMarginBottom() { return $this->marginBottom; }
82+
public function getMarginLeft() { return $this->marginLeft; }
83+
public function getMarginRight() { return $this->marginRight; }
84+
85+
86+
/**
87+
* Check if this is a continuous tape
88+
*
89+
* @return bool
90+
*/
91+
public function isContinuous() {
92+
return $this->continuous;
93+
}
94+
95+
/**
96+
* Get spacing between labels (for die-cut tapes)
97+
*
98+
* @return float
99+
*/
100+
public function getSpacing() {
101+
return $this->spacing;
102+
}
103+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace App\Models\Labels\Tapes\Generic;
4+
5+
abstract class Tape_53mm extends GenericTape
6+
{
7+
// Override tape width to 53mm
8+
protected const TAPE_WIDTH = 53.0;
9+
10+
private float $tapeHeight;
11+
12+
/**
13+
* Constructor for 53mm tape
14+
*
15+
* @param float $height Height of the label in mm (default 30mm)
16+
* @param bool $continuous Whether the tape is continuous or pre-cut
17+
* @param float $spacing Spacing between labels for non-continuous tapes (in mm)
18+
*/
19+
public function __construct(float $height = 30.0, bool $continuous = true, float $spacing = 0.0) {
20+
parent::__construct(self::TAPE_WIDTH, $height, $continuous, $spacing);
21+
$this->tapeHeight = $height;
22+
}
23+
24+
/**
25+
* Get the barcode size ratio for calculations
26+
*
27+
* @return float
28+
*/
29+
public function getBarcodeRatio() {
30+
return 0.9; // Barcode should use 90% of available width
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
namespace App\Models\Labels\Tapes\Generic;
4+
5+
class Tape_53mm_A extends Tape_53mm
6+
{
7+
8+
public function __construct() {
9+
parent::__construct(40.0, true, 0.0);
10+
}
11+
12+
public function getUnit() { return 'mm'; }
13+
public function getSupportAssetTag() { return false; }
14+
public function getSupport1DBarcode() { return false; }
15+
public function getSupport2DBarcode() { return true; }
16+
public function getSupportFields() { return 5; }
17+
public function getSupportLogo() { return false; }
18+
public function getSupportTitle() { return true; }
19+
20+
public function preparePDF($pdf) {
21+
$pdf->SetAutoPageBreak(false);
22+
}
23+
24+
public function write($pdf, $record) {
25+
$pa = $this->getPrintableArea();
26+
27+
$currentX = $pa->x1;
28+
$currentY = $pa->y1;
29+
$usableWidth = $pa->w;
30+
$usableHeight = $pa->h;
31+
32+
if ($record->has('title')) {
33+
static::writeText(
34+
$pdf, $record->get('title'),
35+
$pa->x1, $pa->y1,
36+
'freesans', '', $this->titleSize, 'C',
37+
$pa->w, $this->titleSize, true, 0
38+
);
39+
$currentY += $this->titleSize + $this->titleMargin;
40+
$usableHeight -= $this->titleSize + $this->titleMargin;
41+
}
42+
43+
// Make the barcode as large as possible while still leaving room for fields
44+
$barcodeSize = min($usableHeight * 0.8, $usableWidth * $this->getBarcodeRatio());
45+
46+
if ($record->has('barcode2d')) {
47+
$barcodeX = $pa->x1 + ($usableWidth - $barcodeSize) / 2;
48+
49+
static::write2DBarcode(
50+
$pdf, $record->get('barcode2d')->content, $record->get('barcode2d')->type,
51+
$barcodeX, $currentY,
52+
$barcodeSize, $barcodeSize
53+
);
54+
$currentY += $barcodeSize + $this->barcodeMargin;
55+
}
56+
57+
if ($record->has('fields')) {
58+
foreach ($record->get('fields') as $field) {
59+
static::writeText(
60+
$pdf, $field['label'],
61+
$currentX, $currentY,
62+
'freesans', '', $this->labelSize, 'L',
63+
$usableWidth, $this->labelSize, true, 0
64+
);
65+
$currentY += $this->labelSize + $this->labelMargin;
66+
67+
static::writeText(
68+
$pdf, $field['value'],
69+
$currentX, $currentY,
70+
'freemono', 'B', $this->fieldSize, 'L',
71+
$usableWidth, $this->fieldSize, true, 0, 0.01
72+
);
73+
$currentY += $this->fieldSize + $this->fieldMargin;
74+
}
75+
}
76+
}
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
namespace App\Models\Labels\Tapes\Generic;
4+
5+
use Illuminate\Support\Collection;
6+
use TCPDF;
7+
8+
class Tape_53mm_B extends Tape_53mm
9+
{
10+
11+
12+
public function getUnit() { return 'mm'; }
13+
public function getSupportAssetTag() { return false; }
14+
public function getSupport1DBarcode() { return false; }
15+
public function getSupport2DBarcode() { return true; }
16+
public function getSupportFields() { return 5; }
17+
public function getSupportLogo() { return false; }
18+
public function getSupportTitle() { return true; }
19+
20+
public function preparePDF($pdf) {
21+
$pdf->SetAutoPageBreak(false);
22+
}
23+
24+
public function write($pdf, $record) {
25+
$pa = $this->getPrintableArea();
26+
27+
$currentX = $pa->x1;
28+
$currentY = $pa->y1;
29+
$usableWidth = $pa->w;
30+
$usableHeight = $pa->h;
31+
32+
if ($record->has('title')) {
33+
static::writeText(
34+
$pdf, $record->get('title'),
35+
$pa->x1, $pa->y1,
36+
'freesans', '', $this->titleSize, 'C',
37+
$pa->w, $this->titleSize, true, 0
38+
);
39+
$currentY += $this->titleSize + $this->titleMargin;
40+
$usableHeight -= $this->titleSize + $this->titleMargin;
41+
}
42+
43+
// Make the barcode as large as possible while still leaving room for fields
44+
$barcodeSize = min($usableHeight * 0.8, $usableWidth * $this->getBarcodeRatio());
45+
46+
if ($record->has('barcode2d')) {
47+
$barcodeX = $pa->x1;
48+
49+
static::write2DBarcode(
50+
$pdf, $record->get('barcode2d')->content, $record->get('barcode2d')->type,
51+
$barcodeX, $currentY,
52+
$barcodeSize, $barcodeSize
53+
);
54+
$currentX += $barcodeSize + $this->barcodeMargin;
55+
$usableWidth -= $barcodeSize + $this->barcodeMargin;
56+
}
57+
58+
if ($record->has('fields')) {
59+
foreach ($record->get('fields') as $field) {
60+
static::writeText(
61+
$pdf, $field['label'],
62+
$currentX, $currentY,
63+
'freesans', '', $this->labelSize, 'L',
64+
$usableWidth, $this->labelSize, true, 0
65+
);
66+
$currentY += $this->labelSize + $this->labelMargin;
67+
68+
static::writeText(
69+
$pdf, $field['value'],
70+
$currentX, $currentY,
71+
'freemono', 'B', $this->fieldSize, 'L',
72+
$usableWidth, $this->fieldSize, true, 0, 0.01
73+
);
74+
$currentY += $this->fieldSize + $this->fieldMargin;
75+
}
76+
}
77+
}
78+
}

0 commit comments

Comments
 (0)