|
3 | 3 | namespace App\Models\Labels\Tapes\Dymo; |
4 | 4 |
|
5 | 5 |
|
| 6 | +use App\Helpers\Helper; |
| 7 | + |
6 | 8 | class LabelWriter_11354 extends LabelWriter |
7 | 9 | { |
8 | 10 | private const BARCODE1D_HEIGHT = 3.00; |
@@ -105,46 +107,37 @@ public function write($pdf, $record) |
105 | 107 | } |
106 | 108 |
|
107 | 109 | $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; |
119 | 110 |
|
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 | + ); |
131 | 125 |
|
132 | 126 | foreach ($fields as $field) { |
133 | 127 | static::writeText( |
134 | 128 | $pdf, $field['label'], |
135 | 129 | $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 |
138 | 132 | ); |
139 | | - $currentY += $labelSize + $labelMargin; |
140 | 133 |
|
141 | 134 | static::writeText( |
142 | 135 | $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 |
146 | 139 | ); |
147 | | - $currentY += $fieldSize + $fieldMargin; |
| 140 | + $currentY += $field_layout['rowAdvance']; |
148 | 141 | } |
149 | 142 | } |
150 | 143 |
|
|
0 commit comments