A free open source IT asset/license management system
add title to layout helper, update lw2112283
Godfrey M61bc570d5958
diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.phpindex 7e44c29adb..46551bc84c 100644--- a/app/Helpers/Helper.php+++ b/app/Helpers/Helper.php@@ -1757,18 +1757,26 @@ class Helperfloat $baseLabelSize,float $baseFieldSize,float $baseFieldMargin,+ ?string $title = null,+ float $baseTitleSize = 0.0,+ float $baseTitleMargin = 0.0,float $baseLabelPadding = 1.5,float $baseGap = 1.5,float $maxScale = 1.8,string $labelFont = 'freesans',+) : array{$fieldCount = count($fields);$perFieldHeight = max($baseLabelSize, $baseFieldSize) + $baseFieldMargin;- $baseHeight = $fieldCount * $perFieldHeight;+ $baseFieldsHeight = $fieldCount * $perFieldHeight;++ $hasTitle = is_string($title) && trim($title) !== '';+ $baseTitleHeight = $hasTitle ? ($baseTitleSize + $baseTitleMargin) : 0.0;+ $baseTotalHeight = $baseTitleHeight + $baseFieldsHeight;$scale = 1.0;- if ($baseHeight > 0 && $usableHeight > 0) {- $scale = $usableHeight / $baseHeight;+ if ($baseTotalHeight > 0 && $usableHeight > 0) {+ $scale = $usableHeight / $baseTotalHeight;}$scale = min($scale, $maxScale);@@ -1778,6 +1786,10 @@ class Helper$fieldMargin = $baseFieldMargin * $scale;$rowAdvance = max($labelSize, $fieldSize) + $fieldMargin;+ $titleSize = $hasTitle ? ($baseTitleSize * $scale) : 0.0;+ $titleMargin = $hasTitle ? ($baseTitleMargin * $scale) : 0.0;+ $titleAdvance = $hasTitle ? ($titleSize + $titleMargin) : 0.0;+$pdf->SetFont($labelFont, '', $baseLabelSize);$maxLabelWidthPerUnit = 0;@@ -1796,6 +1808,11 @@ class Helperreturn compact('scale',+ 'hasTitle',+ 'scale',+ 'titleSize',+ 'titleMargin',+ 'titleAdvance','labelSize','fieldSize','fieldMargin',diff --git a/app/Models/Labels/Tapes/Dymo/LabelWriter_2112283.php b/app/Models/Labels/Tapes/Dymo/LabelWriter_2112283.phpindex 3fc91912e2..d7dde401b9 100644--- a/app/Models/Labels/Tapes/Dymo/LabelWriter_2112283.php+++ b/app/Models/Labels/Tapes/Dymo/LabelWriter_2112283.php@@ -83,27 +83,20 @@ class LabelWriter_2112283 extends LabelWriter$usableWidth -= $barcodeSize + self::BARCODE_MARGIN;}- if ($record->has('title')) {- static::writeText(- $pdf, $record->get('title'),- $currentX, $currentY,- 'freesans', 'b', self::TITLE_SIZE, 'L',- $usableWidth, self::TITLE_SIZE, true, 0- );- $currentY += self::TITLE_SIZE + self::TITLE_MARGIN;- }-+ $title = $record->has('title') ? $record->get('title') : null;$fields = $record->get('fields');- // Below rescales the size of the field box to fit, it feels like it could/should be abstracted one class above- // to be usable on other labels but im unsure of how to implement that, since it uses a lot of private- // constants.+ $maxFields = $this->getSupportFields();+ $fields = collect($fields);+ if ($title) {+ $maxFields = max(0, $maxFields - 1); // title consumes one row’s worth of space+ }- // Figure out how tall the label fields wants to be- $fieldCount = count($fields);+ $fields = $fields->take($maxFields)->values();$usableHeight = $pa->h- self::TAG_SIZE // bottom tag text- self::BARCODE_MARGIN; // gap between fields and 1D+$field_layout = Helper::labelFieldLayoutScaling(pdf: $pdf,fields: $fields,@@ -113,29 +106,42 @@ class LabelWriter_2112283 extends LabelWriterbaseLabelSize: self::LABEL_SIZE,baseFieldSize: self::FIELD_SIZE,baseFieldMargin: self::FIELD_MARGIN,+ title: $title,+ baseTitleSize: self::TITLE_SIZE,+ baseTitleMargin: self::TITLE_MARGIN,baseLabelPadding: 1.5,baseGap: 1.5,maxScale: 1.8,labelFont: 'freesans',);+ extract($field_layout);+ if ($hasTitle) {+ static::writeText(+ $pdf, $title,+ $currentX, $currentY,+ 'freesans', 'b', $titleSize, 'L',+ $usableWidth, $titleSize, true, 0+ );+ $currentY += $titleAdvance;+ }foreach ($fields as $field) {$labelText = rtrim($field['label'], ':') . ':';static::writeText($pdf, $labelText,$currentX, $currentY,- 'freesans', '', $field_layout['labelSize'], 'L',- $field_layout['labelWidth'], $field_layout['rowAdvance'], true, 0+ 'freesans', '', $labelSize, 'L',+ $labelWidth, $rowAdvance, true, 0);static::writeText($pdf, $field['value'],$field_layout['valueX'], $currentY,- 'freemono', 'B', $field_layout['fieldSize'], 'L',- $field_layout['valueWidth'], $field_layout['rowAdvance'], true, 0, 0.01+ 'freemono', 'B', $fieldSize, 'L',+ $valueWidth, $rowAdvance, true, 0, 0.01);- $currentY += $field_layout['rowAdvance'];+ $currentY += $rowAdvance;}if ($record->has('barcode1d')) {static::write1DBarcode(