From 851ae46ea96e50897513c97e9ee9bbdab028689b Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 29 Apr 2025 10:45:29 -0700 Subject: [PATCH 1/2] reworked fix for for 24mm_D label indent errior --- .../Labels/Tapes/Brother/TZe_24mm_D.php | 49 ++++++++++++------- app/View/Label.php | 11 ++++- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/app/Models/Labels/Tapes/Brother/TZe_24mm_D.php b/app/Models/Labels/Tapes/Brother/TZe_24mm_D.php index 5ecd86c97..990a615e5 100644 --- a/app/Models/Labels/Tapes/Brother/TZe_24mm_D.php +++ b/app/Models/Labels/Tapes/Brother/TZe_24mm_D.php @@ -70,27 +70,38 @@ class TZe_24mm_D extends TZe_24mm } foreach ($record->get('fields') as $field) { - // Write label and value on the same line - // Calculate label width with proportional character spacing - $labelWidth = $pdf->GetStringWidth($field['label'], 'freemono', '', self::LABEL_SIZE); - $charCount = strlen($field['label']); - $spacingPerChar = 0.5; - $totalSpacing = $charCount * $spacingPerChar; - $adjustedWidth = $labelWidth + $totalSpacing; + if (!empty($field['label']) && $field['label'] !== "\u{200B}") { + // Write label and value on the same line + // Calculate label width with proportional character spacing + $labelWidth = $pdf->GetStringWidth($field['label'], 'freemono', '', self::LABEL_SIZE); + $charCount = strlen($field['label']); + $spacingPerChar = 0.5; + $totalSpacing = $charCount * $spacingPerChar; + $adjustedWidth = $labelWidth + $totalSpacing; - static::writeText( - $pdf, $field['label'], - $currentX, $currentY, - 'freemono', 'B', self::LABEL_SIZE, 'L', - $adjustedWidth, self::LABEL_SIZE, true, 0, $spacingPerChar - ); + static::writeText( + $pdf, $field['label'], + $currentX, $currentY, + 'freemono', 'B', self::LABEL_SIZE, 'L', + $adjustedWidth, self::LABEL_SIZE, true, 0, $spacingPerChar + ); - static::writeText( - $pdf, $field['value'], - $currentX + $adjustedWidth + 2, $currentY, - 'freemono', 'B', self::FIELD_SIZE, 'L', - $usableWidth - $adjustedWidth - 2, self::FIELD_SIZE, true, 0, 0.3 - ); + static::writeText( + $pdf, $field['value'], + $currentX + $adjustedWidth + 2, $currentY, + 'freemono', 'B', self::FIELD_SIZE, 'L', + $usableWidth - $adjustedWidth - 2, self::FIELD_SIZE, true, 0, 0.3 + ); + } else { + + // Label is empty, so write value only. + static::writeText( + $pdf, $field['value'], + $currentX, $currentY, // No offset + 'freemono', 'B', self::FIELD_SIZE, 'L', + $usableWidth, self::FIELD_SIZE, true, 0, 0.3 + ); + } $currentY += max(self::LABEL_SIZE, self::FIELD_SIZE) + self::FIELD_MARGIN; } diff --git a/app/View/Label.php b/app/View/Label.php index 11bb24aab..37fdc6de9 100644 --- a/app/View/Label.php +++ b/app/View/Label.php @@ -177,10 +177,13 @@ class Label implements View // The end result of this will be in this format: // {labelOne} {valueOne} | {labelTwo} {valueTwo} | {labelThree} {valueThree} $previous['value'] = trim(implode(' | ', [ - implode(' ', [null, $previous['value']]), + implode(' ', [$previous['label'], $previous['value']]), implode(' ', [$current['label'], $current['value']]), ])); + // We'll set the label to an empty string since we + // injected the label into the value field above. + $previous['label'] = ''; return $previous; }); @@ -200,6 +203,12 @@ class Label implements View $filename = $assets->count() > 1 ? 'assets.pdf' : $assets->first()->asset_tag.'.pdf'; $pdf->Output($filename, 'I'); } + protected function adjustXIfLabelEmpty($pdf, $field) + { + if (empty($field['label']) || $field['label'] === "\u{200B}") { + $pdf->SetX($pdf->GetX() - 2); + } + } /** * Add a piece of data. From 2e0913bb3bef9f8bd32c62dfef73895923c950bc Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 29 Apr 2025 10:49:19 -0700 Subject: [PATCH 2/2] remove unused method --- app/View/Label.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/View/Label.php b/app/View/Label.php index 37fdc6de9..f8d2b48ac 100644 --- a/app/View/Label.php +++ b/app/View/Label.php @@ -203,12 +203,6 @@ class Label implements View $filename = $assets->count() > 1 ? 'assets.pdf' : $assets->first()->asset_tag.'.pdf'; $pdf->Output($filename, 'I'); } - protected function adjustXIfLabelEmpty($pdf, $field) - { - if (empty($field['label']) || $field['label'] === "\u{200B}") { - $pdf->SetX($pdf->GetX() - 2); - } - } /** * Add a piece of data.