Skip to content

Commit 204d7b5

Browse files
committed
added scaling to L4736_A
1 parent 7dccfec commit 204d7b5

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

app/Models/Labels/Sheets/Avery/L4736_A.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,39 @@ public function write($pdf, $record)
9595
$currentX += $barcodeSize + self::BARCODE_MARGIN;
9696
$usableWidth -= $barcodeSize + self::BARCODE_MARGIN;
9797
}
98+
$fields = $record->get('fields');
99+
$fieldCount = count($fields);
100+
101+
$perFeldHeight = (self::LABEL_SIZE + self::LABEL_MARGIN)
102+
+ (self::FIELD_SIZE + self::FIELD_MARGIN);
103+
104+
$baseHeight = $fieldCount * $perFeldHeight;
105+
$scale = 1.0;
106+
if ($baseHeight > $usableHeight && $baseHeight > 0) {
107+
$scale = $usableHeight / $baseHeight;
108+
}
109+
110+
$labelSize = self::LABEL_SIZE * $scale;
111+
$labelMargin = self::LABEL_MARGIN * $scale;
112+
$fieldSize = self::FIELD_SIZE * $scale;
113+
$fieldMargin = self::FIELD_MARGIN * $scale;
98114

99115
foreach ($record->get('fields') as $field) {
100116
static::writeText(
101117
$pdf, $field['label'],
102118
$currentX, $currentY,
103-
'freesans', '', self::LABEL_SIZE, 'L',
104-
$usableWidth, self::LABEL_SIZE, true, 0
119+
'freesans', '', $labelSize, 'L',
120+
$usableWidth, $labelSize, true, 0
105121
);
106-
$currentY += self::LABEL_SIZE + self::LABEL_MARGIN;
122+
$currentY += $labelSize + $labelMargin;
107123

108124
static::writeText(
109125
$pdf, $field['value'],
110126
$currentX, $currentY,
111-
'freemono', 'B', self::FIELD_SIZE, 'L',
112-
$usableWidth, self::FIELD_SIZE, true, 0, 0.01
127+
'freemono', 'B', $fieldSize, 'L',
128+
$usableWidth, $fieldSize, true, 0, 0.01
113129
);
114-
$currentY += self::FIELD_SIZE + self::FIELD_MARGIN;
130+
$currentY += $fieldSize + $fieldMargin;
115131
}
116132

117133
}

0 commit comments

Comments
 (0)