Skip to content

Commit a3bfcc9

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 0b694bf + ca4ed60 commit a3bfcc9

File tree

2 files changed

+51
-14
lines changed

2 files changed

+51
-14
lines changed

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

Lines changed: 23 additions & 7 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);
98100

99-
foreach ($record->get('fields') as $field) {
101+
$perFieldHeight = (self::LABEL_SIZE + self::LABEL_MARGIN)
102+
+ (self::FIELD_SIZE + self::FIELD_MARGIN);
103+
104+
$baseHeight = $fieldCount * $perFieldHeight;
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;
114+
115+
foreach ($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
}

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

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,44 @@ public function write($pdf, $record)
5959
$currentX += $barcodeSize + self::BARCODE_MARGIN;
6060
$usableWidth -= $barcodeSize + self::BARCODE_MARGIN;
6161
}
62+
$fields = $record->get('fields');
63+
// Below rescales the size of the field box to fit, it feels like it could/should be abstracted one class above
64+
// to be usable on other labels but im unsure of how to implement that, since it uses a lot of private
65+
// constants.
6266

63-
foreach ($record->get('fields') as $field) {
67+
// Figure out how tall the label fields wants to be
68+
$fieldCount = count($fields);
69+
$perFieldHeight = (self::LABEL_SIZE + self::LABEL_MARGIN)
70+
+ (self::FIELD_SIZE + self::FIELD_MARGIN);
71+
72+
$baseHeight = $fieldCount * $perFieldHeight;
73+
// If it doesn't fit in the available height, scale everything down
74+
$scale = 1.0;
75+
if ($baseHeight > $usableHeight && $baseHeight > 0) {
76+
$scale = $usableHeight / $baseHeight;
77+
}
78+
79+
$labelSize = self::LABEL_SIZE * $scale;
80+
$labelMargin = self::LABEL_MARGIN * $scale;
81+
$fieldSize = self::FIELD_SIZE * $scale;
82+
$fieldMargin = self::FIELD_MARGIN * $scale;
83+
84+
foreach ($fields as $field) {
6485
static::writeText(
6586
$pdf, $field['label'],
6687
$currentX, $currentY,
67-
'freesans', '', self::LABEL_SIZE, 'L',
68-
$usableWidth, self::LABEL_SIZE, true, 0
88+
'freesans', '', $labelSize, 'L',
89+
$usableWidth, $labelSize, true, 0
6990
);
70-
$currentY += self::LABEL_SIZE + self::LABEL_MARGIN;
91+
$currentY += $labelSize + $labelMargin;
7192

7293
static::writeText(
7394
$pdf, $field['value'],
7495
$currentX, $currentY,
75-
'freemono', 'B', self::FIELD_SIZE, 'L',
76-
$usableWidth, self::FIELD_SIZE, true, 0, 0.01
96+
'freemono', 'B', $fieldSize, 'L',
97+
$usableWidth, $fieldSize, true, 0, 0.01
7798
);
78-
$currentY += self::FIELD_SIZE + self::FIELD_MARGIN;
99+
$currentY += $fieldSize + $fieldMargin;
79100
}
80101
}
81102
}

0 commit comments

Comments
 (0)