Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure the columns and rows can never be 0 #13489

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions app/Models/Labels/DefaultLabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class DefaultLabel extends RectangleSheet
private int $columns;
private int $rows;


public function __construct() {
$settings = Setting::getSettings();

Expand All @@ -62,6 +62,16 @@ public function __construct() {

$this->columns = ($usableWidth + $this->labelSpacingH) / ($this->labelWidth + $this->labelSpacingH);
$this->rows = ($usableHeight + $this->labelSpacingV) / ($this->labelHeight + $this->labelSpacingV);

// Make sure the columns and rows are never zero, since that scenario should never happen
if ($this->columns == 0) {
$this->columns = 1;
}

if ($this->rows == 0) {
$this->rows = 1;
}

}

public function getUnit() { return 'in'; }
Expand All @@ -85,7 +95,7 @@ public function getLabelMarginTop() { return 0; }
public function getLabelMarginBottom() { return 0; }
public function getLabelMarginLeft() { return 0; }
public function getLabelMarginRight() { return 0; }

public function getLabelColumnSpacing() { return $this->labelSpacingH; }
public function getLabelRowSpacing() { return $this->labelSpacingV; }

Expand All @@ -106,7 +116,7 @@ public function write($pdf, $record) {
$textY = 0;
$textX1 = 0;
$textX2 = $this->getLabelWidth();

// 1D Barcode
if ($record->get('barcode1d')) {
static::write1DBarcode(
Expand All @@ -115,7 +125,7 @@ public function write($pdf, $record) {
$this->getLabelWidth() - 0.1, self::BARCODE1D_SIZE
);
}

// 2D Barcode
if ($record->get('barcode2d')) {
static::write2DBarcode(
Expand Down