Skip to content

Commit 0783576

Browse files
CalvinSchwartzrealchrisolin
authored andcommitted
adds support for Avery 3490
1 parent 91d3848 commit 0783576

File tree

2 files changed

+156
-0
lines changed

2 files changed

+156
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
namespace App\Models\Labels\Sheets\Avery;
4+
5+
use App\Helpers\Helper;
6+
use App\Models\Labels\RectangleSheet;
7+
8+
abstract class _3490 extends RectangleSheet
9+
{
10+
11+
private const PAPER_FORMAT = 'A4';
12+
private const PAPER_ORIENTATION = 'P';
13+
14+
/* Data in pt from Word Template */
15+
private const COLUMN1_X = 5.00;
16+
private const COLUMN2_X = 198.4;
17+
private const ROW1_Y = 10.00;
18+
private const ROW2_Y = 112.00;
19+
private const LABEL_W = 193.4;
20+
private const LABEL_H = 102.00;
21+
22+
23+
private float $pageWidth;
24+
private float $pageHeight;
25+
private float $pageMarginLeft;
26+
private float $pageMarginTop;
27+
28+
private float $columnSpacing;
29+
private float $rowSpacing;
30+
31+
private float $labelWidth;
32+
private float $labelHeight;
33+
34+
public function __construct() {
35+
$paperSize = static::fromFormat(self::PAPER_FORMAT, self::PAPER_ORIENTATION, $this->getUnit(), 2);
36+
$this->pageWidth = $paperSize->width;
37+
$this->pageHeight = $paperSize->height;
38+
39+
$this->pageMarginLeft = Helper::convertUnit(self::COLUMN1_X, 'pt', $this->getUnit());
40+
$this->pageMarginTop = Helper::convertUnit(self::ROW1_Y, 'pt', $this->getUnit());
41+
42+
$columnSpacingPt = self::COLUMN2_X - self::COLUMN1_X - self::LABEL_W;
43+
$this->columnSpacing = Helper::convertUnit($columnSpacingPt, 'pt', $this->getUnit());
44+
$rowSpacingPt = self::ROW2_Y - self::ROW1_Y - self::LABEL_H;
45+
$this->rowSpacing = Helper::convertUnit($rowSpacingPt, 'pt', $this->getUnit());
46+
47+
$this->labelWidth = Helper::convertUnit(self::LABEL_W, 'pt', $this->getUnit());
48+
$this->labelHeight = Helper::convertUnit(self::LABEL_H, 'pt', $this->getUnit());
49+
}
50+
51+
public function getPageWidth() { return $this->pageWidth; }
52+
public function getPageHeight() { return $this->pageHeight; }
53+
54+
public function getPageMarginTop() { return $this->pageMarginTop; }
55+
public function getPageMarginBottom() { return $this->pageMarginTop; }
56+
public function getPageMarginLeft() { return $this->pageMarginLeft; }
57+
public function getPageMarginRight() { return $this->pageMarginLeft; }
58+
59+
public function getColumns() { return 3; }
60+
public function getRows() { return 10; }
61+
62+
public function getLabelColumnSpacing() { return $this->columnSpacing; }
63+
public function getLabelRowSpacing() { return $this->rowSpacing; }
64+
65+
public function getLabelWidth() { return $this->labelWidth; }
66+
public function getLabelHeight() { return $this->labelHeight; }
67+
68+
public function getLabelBorder() { return 0; }
69+
}
70+
71+
?>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
namespace App\Models\Labels\Sheets\Avery;
4+
5+
6+
class _3490_A extends _3490
7+
{
8+
private const BARCODE_MARGIN = 0.075;
9+
private const TAG_SIZE = 0.125;
10+
private const TITLE_SIZE = 0.140;
11+
private const TITLE_MARGIN = 0.040;
12+
private const LABEL_SIZE = 0.090;
13+
private const LABEL_MARGIN = -0.015;
14+
private const FIELD_SIZE = 0.150;
15+
private const FIELD_MARGIN = 0.012;
16+
17+
public function getUnit() { return 'in'; }
18+
19+
public function getLabelMarginTop() { return 0.06; }
20+
public function getLabelMarginBottom() { return 0.06; }
21+
public function getLabelMarginLeft() { return 0.06; }
22+
public function getLabelMarginRight() { return 0.06; }
23+
24+
public function getSupportAssetTag() { return false; }
25+
public function getSupport1DBarcode() { return false; }
26+
public function getSupport2DBarcode() { return true; }
27+
public function getSupportFields() { return 3; }
28+
public function getSupportLogo() { return false; }
29+
public function getSupportTitle() { return true; }
30+
31+
public function preparePDF($pdf) {}
32+
33+
public function write($pdf, $record) {
34+
$pa = $this->getLabelPrintableArea();
35+
36+
$currentX = $pa->x1;
37+
$currentY = $pa->y1;
38+
$usableWidth = $pa->w;
39+
$usableHeight = $pa->h;
40+
41+
if ($record->has('title')) {
42+
static::writeText(
43+
$pdf, $record->get('title'),
44+
$pa->x1, $pa->y1,
45+
'freesans', '', self::TITLE_SIZE, 'C',
46+
$pa->w, self::TITLE_SIZE, true, 0
47+
);
48+
$currentY += self::TITLE_SIZE + self::TITLE_MARGIN;
49+
$usableHeight -= self::TITLE_SIZE + self::TITLE_MARGIN;
50+
}
51+
52+
$barcodeSize = $usableHeight;
53+
if ($record->has('barcode2d')) {
54+
static::write2DBarcode(
55+
$pdf, $record->get('barcode2d')->content, $record->get('barcode2d')->type,
56+
$currentX, $currentY,
57+
$barcodeSize, $barcodeSize
58+
);
59+
$currentX += $barcodeSize + self::BARCODE_MARGIN;
60+
$usableWidth -= $barcodeSize + self::BARCODE_MARGIN;
61+
}
62+
63+
foreach ($record->get('fields') as $field) {
64+
static::writeText(
65+
$pdf, $field['label'],
66+
$currentX, $currentY,
67+
'freesans', '', self::LABEL_SIZE, 'L',
68+
$usableWidth, self::LABEL_SIZE, true, 0
69+
);
70+
$currentY += self::LABEL_SIZE + self::LABEL_MARGIN;
71+
72+
static::writeText(
73+
$pdf, $field['value'],
74+
$currentX, $currentY,
75+
'freemono', 'B', self::FIELD_SIZE, 'L',
76+
$usableWidth, self::FIELD_SIZE, true, 0, 0.01
77+
);
78+
$currentY += self::FIELD_SIZE + self::FIELD_MARGIN;
79+
}
80+
81+
}
82+
}
83+
84+
85+
?>

0 commit comments

Comments
 (0)