Skip to content

A free open source IT asset/license management system

adds support for GenericTape label printers, includes class for 53mm tape printer

Chris Olin2c141579dd09
diff --git a/app/Models/Labels/Tapes/Generic/GenericTape.php b/app/Models/Labels/Tapes/Generic/GenericTape.php
new file mode 100644
index 0000000000..3825d54e2e
--- /dev/null
+++ b/app/Models/Labels/Tapes/Generic/GenericTape.php
@@ -0,0 +1,103 @@
+<?php
+
+namespace App\Models\Labels\Tapes\Generic;
+
+use App\Helpers\Helper;
+use App\Models\Labels\Label;
+
+abstract class GenericTape extends Label
+{
+ // Default tape width in mm
+ protected const TAPE_WIDTH = 42.0;
+
+ // Tape properties
+ protected float $width;
+ protected float $height;
+ protected bool $continuous;
+ protected float $spacing = 0.0; // Space between labels for non-continuous tapes
+
+ // Margins in mm
+ protected float $marginTop;
+ protected float $marginBottom;
+ protected float $marginLeft;
+ protected float $marginRight;
+
+ // Element sizing in mm
+ protected float $titleSize;
+ protected float $titleMargin;
+ protected float $fieldSize;
+ protected float $fieldMargin;
+ protected float $labelSize;
+ protected float $labelMargin;
+ protected float $barcodeMargin;
+ protected float $tagSize;
+
+ /**
+ * Constructor for generic tape
+ *
+ * @param float $width Width of the tape in mm
+ * @param float $height Height of the label in mm (for continuous tapes, this is the default height)
+ * @param bool $continuous Whether the tape is continuous or pre-cut
+ * @param float $spacing Spacing between labels for non-continuous tapes (in mm)
+ */
+ public function __construct(float $width, float $height, bool $continuous = true, float $spacing = 0.0) {
+ $this->width = $width;
+ $this->height = $height;
+ $this->continuous = $continuous;
+ $this->spacing = $spacing;
+
+ // Calculate base font size (7% of tape width)
+ $baseFontSize = static::TAPE_WIDTH * 0.07;
+
+ // Calculate margin (4% of tape width)
+ $margin = static::TAPE_WIDTH * 0.04;
+
+ // Set margins
+ $this->marginTop = $margin;
+ $this->marginBottom = $margin;
+ $this->marginLeft = $margin;
+ $this->marginRight = $margin;
+
+ // Calculate and set element sizing based on base font size
+ $this->titleSize = $baseFontSize; // Same as base font size
+ $this->titleMargin = $baseFontSize * 0.3; // 30% of base font size
+ $this->fieldSize = $baseFontSize * 1.1; // 110% of base font size
+ $this->fieldMargin = $baseFontSize * 0.1; // 10% of base font size
+ $this->labelSize = $baseFontSize * 0.7; // 70% of base font size
+ $this->labelMargin = $baseFontSize * -0.1; // -10% of base font size
+ $this->barcodeMargin = $baseFontSize * 0.5; // 50% of base font size
+ $this->tagSize = $baseFontSize * 0.8; // 80% of base font size
+ }
+
+ // Unit of measurement
+ public function getUnit() { return 'mm'; }
+
+ // Label dimensions
+ public function getWidth() { return $this->width; }
+ public function getHeight() { return $this->height; }
+
+ // Margins
+ public function getMarginTop() { return $this->marginTop; }
+ public function getMarginBottom() { return $this->marginBottom; }
+ public function getMarginLeft() { return $this->marginLeft; }
+ public function getMarginRight() { return $this->marginRight; }
+
+
+ /**
+ * Check if this is a continuous tape
+ *
+ * @return bool
+ */
+ public function isContinuous() {
+ return $this->continuous;
+ }
+
+ /**
+ * Get spacing between labels (for die-cut tapes)
+ *
+ * @return float
+ */
+ public function getSpacing() {
+ return $this->spacing;
+ }
+}
\ No newline at end of file
diff --git a/app/Models/Labels/Tapes/Generic/Tape_53mm.php b/app/Models/Labels/Tapes/Generic/Tape_53mm.php
new file mode 100644
index 0000000000..fc46838d66
--- /dev/null
+++ b/app/Models/Labels/Tapes/Generic/Tape_53mm.php
@@ -0,0 +1,32 @@
+<?php
+
+namespace App\Models\Labels\Tapes\Generic;
+
+abstract class Tape_53mm extends GenericTape
+{
+ // Override tape width to 53mm
+ protected const TAPE_WIDTH = 53.0;
+
+ private float $tapeHeight;
+
+ /**
+ * Constructor for 53mm tape
+ *
+ * @param float $height Height of the label in mm (default 30mm)
+ * @param bool $continuous Whether the tape is continuous or pre-cut
+ * @param float $spacing Spacing between labels for non-continuous tapes (in mm)
+ */
+ public function __construct(float $height = 30.0, bool $continuous = true, float $spacing = 0.0) {
+ parent::__construct(self::TAPE_WIDTH, $height, $continuous, $spacing);
+ $this->tapeHeight = $height;
+ }
+
+ /**
+ * Get the barcode size ratio for calculations
+ *
+ * @return float
+ */
+ public function getBarcodeRatio() {
+ return 0.9; // Barcode should use 90% of available width
+ }
+}
\ No newline at end of file
diff --git a/app/Models/Labels/Tapes/Generic/Tape_53mm_A.php b/app/Models/Labels/Tapes/Generic/Tape_53mm_A.php
new file mode 100644
index 0000000000..399efbe11c
--- /dev/null
+++ b/app/Models/Labels/Tapes/Generic/Tape_53mm_A.php
@@ -0,0 +1,77 @@
+<?php
+
+namespace App\Models\Labels\Tapes\Generic;
+
+class Tape_53mm_A extends Tape_53mm
+{
+
+ public function __construct() {
+ parent::__construct(40.0, true, 0.0);
+ }
+
+ public function getUnit() { return 'mm'; }
+ public function getSupportAssetTag() { return false; }
+ public function getSupport1DBarcode() { return false; }
+ public function getSupport2DBarcode() { return true; }
+ public function getSupportFields() { return 5; }
+ public function getSupportLogo() { return false; }
+ public function getSupportTitle() { return true; }
+
+ public function preparePDF($pdf) {
+ $pdf->SetAutoPageBreak(false);
+ }
+
+ public function write($pdf, $record) {
+ $pa = $this->getPrintableArea();
+
+ $currentX = $pa->x1;
+ $currentY = $pa->y1;
+ $usableWidth = $pa->w;
+ $usableHeight = $pa->h;
+
+ if ($record->has('title')) {
+ static::writeText(
+ $pdf, $record->get('title'),
+ $pa->x1, $pa->y1,
+ 'freesans', '', $this->titleSize, 'C',
+ $pa->w, $this->titleSize, true, 0
+ );
+ $currentY += $this->titleSize + $this->titleMargin;
+ $usableHeight -= $this->titleSize + $this->titleMargin;
+ }
+
+ // Make the barcode as large as possible while still leaving room for fields
+ $barcodeSize = min($usableHeight * 0.8, $usableWidth * $this->getBarcodeRatio());
+
+ if ($record->has('barcode2d')) {
+ $barcodeX = $pa->x1 + ($usableWidth - $barcodeSize) / 2;
+
+ static::write2DBarcode(
+ $pdf, $record->get('barcode2d')->content, $record->get('barcode2d')->type,
+ $barcodeX, $currentY,
+ $barcodeSize, $barcodeSize
+ );
+ $currentY += $barcodeSize + $this->barcodeMargin;
+ }
+
+ if ($record->has('fields')) {
+ foreach ($record->get('fields') as $field) {
+ static::writeText(
+ $pdf, $field['label'],
+ $currentX, $currentY,
+ 'freesans', '', $this->labelSize, 'L',
+ $usableWidth, $this->labelSize, true, 0
+ );
+ $currentY += $this->labelSize + $this->labelMargin;
+
+ static::writeText(
+ $pdf, $field['value'],
+ $currentX, $currentY,
+ 'freemono', 'B', $this->fieldSize, 'L',
+ $usableWidth, $this->fieldSize, true, 0, 0.01
+ );
+ $currentY += $this->fieldSize + $this->fieldMargin;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/Models/Labels/Tapes/Generic/Tape_53mm_B.php b/app/Models/Labels/Tapes/Generic/Tape_53mm_B.php
new file mode 100644
index 0000000000..e297a30248
--- /dev/null
+++ b/app/Models/Labels/Tapes/Generic/Tape_53mm_B.php
@@ -0,0 +1,78 @@
+<?php
+
+namespace App\Models\Labels\Tapes\Generic;
+
+use Illuminate\Support\Collection;
+use TCPDF;
+
+class Tape_53mm_B extends Tape_53mm
+{
+
+
+ public function getUnit() { return 'mm'; }
+ public function getSupportAssetTag() { return false; }
+ public function getSupport1DBarcode() { return false; }
+ public function getSupport2DBarcode() { return true; }
+ public function getSupportFields() { return 5; }
+ public function getSupportLogo() { return false; }
+ public function getSupportTitle() { return true; }
+
+ public function preparePDF($pdf) {
+ $pdf->SetAutoPageBreak(false);
+ }
+
+ public function write($pdf, $record) {
+ $pa = $this->getPrintableArea();
+
+ $currentX = $pa->x1;
+ $currentY = $pa->y1;
+ $usableWidth = $pa->w;
+ $usableHeight = $pa->h;
+
+ if ($record->has('title')) {
+ static::writeText(
+ $pdf, $record->get('title'),
+ $pa->x1, $pa->y1,
+ 'freesans', '', $this->titleSize, 'C',
+ $pa->w, $this->titleSize, true, 0
+ );
+ $currentY += $this->titleSize + $this->titleMargin;
+ $usableHeight -= $this->titleSize + $this->titleMargin;
+ }
+
+ // Make the barcode as large as possible while still leaving room for fields
+ $barcodeSize = min($usableHeight * 0.8, $usableWidth * $this->getBarcodeRatio());
+
+ if ($record->has('barcode2d')) {
+ $barcodeX = $pa->x1;
+
+ static::write2DBarcode(
+ $pdf, $record->get('barcode2d')->content, $record->get('barcode2d')->type,
+ $barcodeX, $currentY,
+ $barcodeSize, $barcodeSize
+ );
+ $currentX += $barcodeSize + $this->barcodeMargin;
+ $usableWidth -= $barcodeSize + $this->barcodeMargin;
+ }
+
+ if ($record->has('fields')) {
+ foreach ($record->get('fields') as $field) {
+ static::writeText(
+ $pdf, $field['label'],
+ $currentX, $currentY,
+ 'freesans', '', $this->labelSize, 'L',
+ $usableWidth, $this->labelSize, true, 0
+ );
+ $currentY += $this->labelSize + $this->labelMargin;
+
+ static::writeText(
+ $pdf, $field['value'],
+ $currentX, $currentY,
+ 'freemono', 'B', $this->fieldSize, 'L',
+ $usableWidth, $this->fieldSize, true, 0, 0.01
+ );
+ $currentY += $this->fieldSize + $this->fieldMargin;
+ }
+ }
+ }
+}
\ No newline at end of file