Skip to content

Commit d96d0b1

Browse files
committed
applied to LabelWriter_11354
1 parent 02c2374 commit d96d0b1

1 file changed

Lines changed: 22 additions & 29 deletions

File tree

app/Models/Labels/Tapes/Dymo/LabelWriter_11354.php

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace App\Models\Labels\Tapes\Dymo;
44

55

6+
use App\Helpers\Helper;
7+
68
class LabelWriter_11354 extends LabelWriter
79
{
810
private const BARCODE1D_HEIGHT = 3.00;
@@ -105,46 +107,37 @@ public function write($pdf, $record)
105107
}
106108

107109
$fields = $record->get('fields');
108-
// Below rescales the size of the field box to fit, it feels like it could/should be abstracted one class above
109-
// to be usable on other labels but im unsure of how to implement that, since it uses a lot of private
110-
// constants.
111-
112-
// Figure out how tall the label fields wants to be
113-
$fieldCount = count($fields);
114-
$perFieldHeight = (self::LABEL_SIZE + self::LABEL_MARGIN)
115-
+ (self::FIELD_SIZE + self::FIELD_MARGIN);
116-
$usableHeight = $pa->h
117-
- self::TAG_SIZE
118-
- self::BARCODE_MARGIN;
119110

120-
$baseHeight = $fieldCount * $perFieldHeight;
121-
// If it doesn't fit in the available height, scale everything down
122-
$scale = 1.0;
123-
if ($baseHeight > $usableHeight && $baseHeight > 0) {
124-
$scale = $usableHeight / $baseHeight;
125-
}
126-
127-
$labelSize = self::LABEL_SIZE * $scale;
128-
$labelMargin = self::LABEL_MARGIN * $scale;
129-
$fieldSize = self::FIELD_SIZE * $scale;
130-
$fieldMargin = self::FIELD_MARGIN * $scale;
111+
$field_layout = Helper::labelFieldLayoutScaling(
112+
pdf: $pdf,
113+
fields: $fields,
114+
currentX: $currentX,
115+
usableWidth: $usableWidth,
116+
usableHeight: $usableHeight,
117+
baseLabelSize: self::LABEL_SIZE,
118+
baseFieldSize: self::FIELD_SIZE,
119+
baseFieldMargin: self::FIELD_MARGIN,
120+
baseLabelPadding: 1.5,
121+
baseGap: 1.5,
122+
maxScale: 1.8,
123+
labelFont: 'freesans',
124+
);
131125

132126
foreach ($fields as $field) {
133127
static::writeText(
134128
$pdf, $field['label'],
135129
$currentX, $currentY,
136-
'freesans', '', $labelSize, 'L',
137-
$usableWidth, $labelSize, true, 0
130+
'freesans', '', $field_layout['labelSize'], 'L',
131+
$field_layout['labelWidth'], $field_layout['rowAdvance'], true, 0
138132
);
139-
$currentY += $labelSize + $labelMargin;
140133

141134
static::writeText(
142135
$pdf, $field['value'],
143-
$currentX, $currentY,
144-
'freemono', 'B', $fieldSize, 'L',
145-
$usableWidth, $fieldSize, true, 0, 0.01
136+
$field_layout['valueX'], $currentY,
137+
'freemono', 'B', $field_layout['fieldSize'], 'L',
138+
$field_layout['valueWidth'], $field_layout['rowAdvance'], true, 0, 0.01
146139
);
147-
$currentY += $fieldSize + $fieldMargin;
140+
$currentY += $field_layout['rowAdvance'];
148141
}
149142
}
150143

0 commit comments

Comments
 (0)