From 53513d93fa0891fd5917e25779f888bab9bf68a4 Mon Sep 17 00:00:00 2001 From: Cram42 Date: Wed, 2 Nov 2022 22:38:00 +0800 Subject: [PATCH] Rework TZe labels for Asset Tag support --- .../Labels/Tapes/Brother/TZe_12mm_A.php | 43 +++++++------- .../Labels/Tapes/Brother/TZe_24mm_A.php | 57 ++++++++++++------- 2 files changed, 59 insertions(+), 41 deletions(-) diff --git a/app/Models/Labels/Tapes/Brother/TZe_12mm_A.php b/app/Models/Labels/Tapes/Brother/TZe_12mm_A.php index dbac6b9a71..786f6eca45 100644 --- a/app/Models/Labels/Tapes/Brother/TZe_12mm_A.php +++ b/app/Models/Labels/Tapes/Brother/TZe_12mm_A.php @@ -4,16 +4,16 @@ namespace App\Models\Labels\Tapes\Brother; class TZe_12mm_A extends TZe_12mm { - private const BARCODE_SIZE = 2.50; + private const BARCODE_SIZE = 3.20; private const BARCODE_MARGIN = 0.30; - private const FIELD_SIZE_MOD = 1.00; + private const TEXT_SIZE_MOD = 1.00; public function getUnit() { return 'mm'; } public function getWidth() { return 50.0; } - public function getSupportAssetTag() { return false; } + public function getSupportAssetTag() { return true; } public function getSupport1DBarcode() { return true; } public function getSupport2DBarcode() { return false; } - public function getSupportFields() { return 2; } + public function getSupportFields() { return 1; } public function getSupportLogo() { return false; } public function getSupportTitle() { return false; } @@ -28,26 +28,27 @@ class TZe_12mm_A extends TZe_12mm $pa->x1, $pa->y1, $pa->w, self::BARCODE_SIZE ); } + + $currentY = $pa->y1 + self::BARCODE_SIZE + self::BARCODE_MARGIN; + $usableHeight = $pa->h - self::BARCODE_SIZE - self::BARCODE_MARGIN; + $fontSize = $usableHeight + self::TEXT_SIZE_MOD; - $fields = $record->get('fields'); - $y = $pa->y1 + self::BARCODE_SIZE + self::BARCODE_MARGIN; - $realSize = $pa->h - self::BARCODE_SIZE - self::BARCODE_MARGIN; - $fontSize = $realSize + self::FIELD_SIZE_MOD; + $tagWidth = $pa->w / 3; + $fieldWidth = $pa->w / 3 * 2; - if ($fields->count() >= 1) { + static::writeText( + $pdf, $record->get('tag'), + $pa->x1, $currentY, + 'freemono', 'b', $fontSize, 'L', + $tagWidth, $usableHeight, true, 0, 0 + ); + + if ($record->get('fields')->count() >= 1) { static::writeText( - $pdf, $fields->values()->get(0), - $pa->x1, $y, - 'freemono', 'B', $fontSize, 'L', - $pa->w, $realSize, true, 0, 0.1 - ); - } - if ($fields->count() >= 2) { - static::writeText( - $pdf, $fields->values()->get(1), - $pa->x1, $y, - 'freemono', 'B', $fontSize, 'R', - $pa->w, $realSize, true, 0, 0.1 + $pdf, $record->get('fields')->values()->get(0), + $pa->x1 + ($tagWidth), $currentY, + 'freemono', 'b', $fontSize, 'R', + $fieldWidth, $usableHeight, true, 0, 0 ); } diff --git a/app/Models/Labels/Tapes/Brother/TZe_24mm_A.php b/app/Models/Labels/Tapes/Brother/TZe_24mm_A.php index 26618c1640..36d185d64c 100644 --- a/app/Models/Labels/Tapes/Brother/TZe_24mm_A.php +++ b/app/Models/Labels/Tapes/Brother/TZe_24mm_A.php @@ -5,16 +5,17 @@ namespace App\Models\Labels\Tapes\Brother; class TZe_24mm_A extends TZe_24mm { private const BARCODE_MARGIN = 1.40; + private const TAG_SIZE = 2.80; private const TITLE_SIZE = 2.80; - private const TITLE_MARGIN = 0.60; - private const LABEL_SIZE = 1.90; - private const LABEL_MARGIN = - 0.30; + private const TITLE_MARGIN = 0.50; + private const LABEL_SIZE = 2.00; + private const LABEL_MARGIN = - 0.35; private const FIELD_SIZE = 3.20; - private const FIELD_MARGIN = 0.30; + private const FIELD_MARGIN = 0.15; public function getUnit() { return 'mm'; } public function getWidth() { return 65.0; } - public function getSupportAssetTag() { return false; } + public function getSupportAssetTag() { return true; } public function getSupport1DBarcode() { return false; } public function getSupport2DBarcode() { return true; } public function getSupportFields() { return 3; } @@ -26,45 +27,61 @@ class TZe_24mm_A extends TZe_24mm public function write($pdf, $record) { $pa = $this->getPrintableArea(); - $x = $pa->x1; - $y = $pa->y1; - $w = $pa->w; + $currentX = $pa->x1; + $currentY = $pa->y1; + $usableWidth = $pa->w; + + $barcodeSize = $pa->h - self::TAG_SIZE; if ($record->has('barcode2d')) { + static::writeText( + $pdf, $record->get('tag'), + $pa->x1, $pa->y2 - self::TAG_SIZE, + 'freemono', 'b', self::TAG_SIZE, 'C', + $barcodeSize, self::TAG_SIZE, true, 0 + ); static::write2DBarcode( $pdf, $record->get('barcode2d')->content, $record->get('barcode2d')->type, - $x, $y, $pa->h, $pa->h + $currentX, $currentY, + $barcodeSize, $barcodeSize + ); + $currentX += $barcodeSize + self::BARCODE_MARGIN; + $usableWidth -= $barcodeSize + self::BARCODE_MARGIN; + } else { + static::writeText( + $pdf, $record->get('tag'), + $pa->x1, $pa->y2 - self::TAG_SIZE, + 'freemono', 'b', self::TAG_SIZE, 'R', + $usableWidth, self::TAG_SIZE, true, 0 ); - $x += $pa->h + self::BARCODE_MARGIN; - $w -= $pa->h + self::BARCODE_MARGIN; } if ($record->has('title')) { static::writeText( $pdf, $record->get('title'), - $x, $y, + $currentX, $currentY, 'freesans', '', self::TITLE_SIZE, 'L', - $w, self::TITLE_SIZE, true, 0 + $usableWidth, self::TITLE_SIZE, true, 0 ); - $y += self::TITLE_SIZE + self::TITLE_MARGIN; + $currentY += self::TITLE_SIZE + self::TITLE_MARGIN; } foreach ($record->get('fields') as $label => $value) { static::writeText( $pdf, $label, - $x, $y, + $currentX, $currentY, 'freesans', '', self::LABEL_SIZE, 'L', - $w, self::LABEL_SIZE, true, 0 + $usableWidth, self::LABEL_SIZE, true, 0, 0 ); - $y += self::LABEL_SIZE + self::LABEL_MARGIN; + $currentY += self::LABEL_SIZE + self::LABEL_MARGIN; static::writeText( $pdf, $value, - $x, $y, + $currentX, $currentY, 'freemono', 'B', self::FIELD_SIZE, 'L', - $w, self::FIELD_SIZE, true, 0, 0.3 + $usableWidth, self::FIELD_SIZE, true, 0, 0.3 ); - $y += self::FIELD_SIZE + self::FIELD_MARGIN; + $currentY += self::FIELD_SIZE + self::FIELD_MARGIN; } } } \ No newline at end of file