Skip to content

A free open source IT asset/license management system

adds titile position to custom sheet labels

Godfrey M0ac50d6be0c0
diff --git a/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelContentProperties.php b/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelContentProperties.php
index 5520c6871d..098ce157ae 100644
--- a/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelContentProperties.php
+++ b/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelContentProperties.php
@@ -50,6 +50,7 @@ trait HasCustomLabelContentProperties
protected float $textSizeMod = 1.0;
protected float $textAreaOffsetY = 0.0;
protected string $textRenderMode = 'normal';
+ protected string $titlePosition = 'inline';
protected ?float $textAreaWidth = null;
protected ?float $textAreaHeight = null;
@@ -119,6 +120,10 @@ trait HasCustomLabelContentProperties
return $this->titleOffsetX;
}
+ public function getTitlePosition(): string
+ {
+ return $this->titlePosition;
+ }
public function getTitleFont(): string
{
return $this->titleFont;
diff --git a/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelEditorConfig.php b/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelEditorConfig.php
index 94b4070470..9555341fee 100644
--- a/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelEditorConfig.php
+++ b/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelEditorConfig.php
@@ -28,6 +28,7 @@ trait HasCustomLabelEditorConfig
'title_font_size' => $this->getTitleSize(),
'title_margin' => $this->getTitleMargin(),
'title_offset_x' => $this->getTitleOffsetX(),
+ 'title_position' => $this->getTitlePosition(),
// Fields
'field_label_font' => $this->getFieldLabelFont(),
diff --git a/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelEditorSections.php b/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelEditorSections.php
index d1ca66084b..aa11f40d5b 100644
--- a/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelEditorSections.php
+++ b/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelEditorSections.php
@@ -101,6 +101,14 @@ trait HasCustomLabelEditorSections
'title_font_size' => ['type' => 'number'],
'title_margin' => ['type' => 'number'],
'title_offset_x' => ['type' => 'number'],
+ 'title_position' => [
+ 'type' => 'select',
+ 'options' => [
+ 'inline' => 'admin/labels/general.options.inline',
+ 'top' => 'admin/labels/general.options.top',
+
+ ],
+ ],
],
],
diff --git a/app/Models/Labels/CustomLabels/Concerns/SeedsCustomLabelFromTemplate.php b/app/Models/Labels/CustomLabels/Concerns/SeedsCustomLabelFromTemplate.php
index 58f0e22d0f..3ca5b927ad 100644
--- a/app/Models/Labels/CustomLabels/Concerns/SeedsCustomLabelFromTemplate.php
+++ b/app/Models/Labels/CustomLabels/Concerns/SeedsCustomLabelFromTemplate.php
@@ -224,6 +224,7 @@ trait SeedsCustomLabelFromTemplate
'tag_font' => 'tagFont',
'title_font' => 'titleFont',
+ 'title_position' => 'titlePosition',
'field_alignment' => 'fieldAlignment', // Tape only
'field_label_font' => 'fieldLabelFont',
diff --git a/app/Models/Labels/CustomLabels/CustomSheetLabel.php b/app/Models/Labels/CustomLabels/CustomSheetLabel.php
index 003bb9c226..518d31d0f8 100644
--- a/app/Models/Labels/CustomLabels/CustomSheetLabel.php
+++ b/app/Models/Labels/CustomLabels/CustomSheetLabel.php
@@ -243,7 +243,7 @@ abstract class CustomSheetLabel extends RectangleSheet
/*
|--------------------------------------------------------------------------
- |Reserve bottom strip for 1D barcode
+ | Reserve bottom strip for 1D barcode
|--------------------------------------------------------------------------
*/
if ($record->has('barcode1d') && $this->getSupport1DBarcode()) {
@@ -260,18 +260,104 @@ abstract class CustomSheetLabel extends RectangleSheet
];
$layout['body']['y2'] -= ($barcodeHeight + $barcodeMargin);
- $layout['body']['y2'] = max($layout['body']['y1'], $layout['body']['y2']);
- $layout['body']['h'] = max(0, $layout['body']['y2'] - $layout['body']['y1']);
+ $layout['body']['y2'] = max(
+ $layout['body']['y1'],
+ $layout['body']['y2']
+ );
+
+ $layout['body']['h'] = max(
+ 0,
+ $layout['body']['y2'] - $layout['body']['y1']
+ );
}
/*
|--------------------------------------------------------------------------
- | add Logo, 2D Barcode, and Tag to the layout
+ | Resolve title + fields
|--------------------------------------------------------------------------
*/
- $logoBox = $this->resolveLogoBox($record, $layout['body']);
- $barcode2dBox = $this->resolve2DBarcodeBox($record, $layout['body'], $logoBox);
- $tagBox = $this->resolveTagBox($record, $layout['body'], $barcode2dBox, $logoBox);
+ $title = $this->resolveLayoutTitle($record);
+ $fields = $this->resolveLayoutFields($record);
+
+ $titlePosition = $this->getTitlePosition();
+
+ /*
+ |--------------------------------------------------------------------------
+ | Working body
+ |--------------------------------------------------------------------------
+ */
+ $contentBody = $layout['body'];
+
+ /*
+ |--------------------------------------------------------------------------
+ | Reserve top strip for title
+ |--------------------------------------------------------------------------
+ */
+ if (
+ $title !== null
+ && $title !== ''
+ && $titlePosition === 'top'
+ ) {
+ $titleSize = max(0, $this->getTitleSize());
+ $titleAdvance = $titleSize + max(0, $this->getTitleMargin());
+
+ /*
+ * Title itself occupies the original top of the body.
+ */
+ $layout['title'] = [
+ 'x' => $layout['body']['x1'] + $this->getTitleOffsetX(),
+ 'y' => $layout['body']['y1'],
+ 'w' => max(
+ 0,
+ $layout['body']['x2']
+ - ($layout['body']['x1'] + $this->getTitleOffsetX())
+ ),
+ 'h' => $titleSize,
+ 'font_size' => $titleSize,
+ 'advance' => $titleAdvance,
+ ];
+
+ /*
+ * Everything else begins below the title.
+ */
+ $contentBody['y1'] += $titleAdvance;
+ $contentBody['y1'] = min(
+ $contentBody['y1'],
+ $contentBody['y2']
+ );
+
+ $contentBody['h'] = max(
+ 0,
+ $contentBody['y2'] - $contentBody['y1']
+ );
+ }
+
+ /*
+ |--------------------------------------------------------------------------
+ | Logo, 2D barcode, and tag
+ |--------------------------------------------------------------------------
+ |
+ | IMPORTANT:
+ | Use $contentBody here, not $layout['body'].
+ |--------------------------------------------------------------------------
+ */
+ $logoBox = $this->resolveLogoBox(
+ $record,
+ $contentBody
+ );
+
+ $barcode2dBox = $this->resolve2DBarcodeBox(
+ $record,
+ $contentBody,
+ $logoBox
+ );
+
+ $tagBox = $this->resolveTagBox(
+ $record,
+ $contentBody,
+ $barcode2dBox,
+ $logoBox
+ );
$layout['logo'] = $logoBox;
$layout['barcode2d'] = $barcode2dBox;
@@ -283,7 +369,7 @@ abstract class CustomSheetLabel extends RectangleSheet
|--------------------------------------------------------------------------
*/
$layout['text'] = $this->resolveTextBox(
- $layout['body'],
+ $contentBody,
array_filter([
$layout['logo'],
$layout['barcode2d'],
@@ -291,18 +377,29 @@ abstract class CustomSheetLabel extends RectangleSheet
])
);
+ $layout['text'] = $this->applyTextAreaConstraints(
+ $layout['text']
+ );
+
+ $textY = $layout['text']['y1'];
+ $bottomLimit = $layout['text']['y2'];
+ $availableHeight = max(
+ 0,
+ $bottomLimit - $textY
+ );
+
/*
|--------------------------------------------------------------------------
- | Title + fields inside text box
+ | Calculate field scaling
+ |--------------------------------------------------------------------------
+ |
+ | If the title is on top, its space has already been reserved.
+ | Do not make labelFieldLayoutScaling() reserve it again.
|--------------------------------------------------------------------------
*/
- $title = $this->resolveLayoutTitle($record);
- $fields = $this->resolveLayoutFields($record);
-
- $layout['text'] = $this->applyTextAreaConstraints($layout['text']);
- $textY = $layout['text']['y1'];
- $bottomLimit = $layout['text']['y2'];
- $availableHeight = max(0, $bottomLimit - $textY);
+ $scalingTitle = $titlePosition === 'top'
+ ? null
+ : $title;
$fieldLayout = Helper::labelFieldLayoutScaling(
$pdf,
@@ -313,20 +410,31 @@ abstract class CustomSheetLabel extends RectangleSheet
$this->getLabelSize(),
$this->getFieldSize(),
$this->getFieldMargin(),
- $title,
+ $scalingTitle,
$this->getTitleSize(),
$this->getTitleMargin(),
$this->getLabelMargin(),
$this->getFieldMargin()
);
- if ($fieldLayout['hasTitle']) {
+ /*
+ |--------------------------------------------------------------------------
+ | Normal / inline title
+ |--------------------------------------------------------------------------
+ */
+ if (
+ $titlePosition !== 'top'
+ && $fieldLayout['hasTitle']
+ ) {
$x = $layout['text']['x1'] + $this->getTitleOffsetX();
$layout['title'] = [
'x' => $x,
'y' => $textY,
- 'w' => max(0, $layout['text']['x2'] - $x),
+ 'w' => max(
+ 0,
+ $layout['text']['x2'] - $x
+ ),
'h' => $fieldLayout['titleSize'],
'font_size' => $fieldLayout['titleSize'],
'advance' => $fieldLayout['titleAdvance'],
@@ -335,8 +443,21 @@ abstract class CustomSheetLabel extends RectangleSheet
$textY += $fieldLayout['titleAdvance'];
}
- $labelWidth = min($fieldLayout['labelWidth'], $layout['text']['w'] * 0.45);
- $gap = max(0.8, $this->getFieldMargin() * max($fieldLayout['scale'], 0.5));
+ /*
+ |--------------------------------------------------------------------------
+ | Fields
+ |--------------------------------------------------------------------------
+ */
+ $labelWidth = min(
+ $fieldLayout['labelWidth'],
+ $layout['text']['w'] * 0.45
+ );
+
+ $gap = max(
+ 0.8,
+ $this->getFieldMargin()
+ * max($fieldLayout['scale'], 0.5)
+ );
$layout['fields'] = $this->makeFieldsLayout(
$layout['text'],
diff --git a/app/Models/Labels/Sheets/Avery/_5520_A.php b/app/Models/Labels/Sheets/Avery/_5520_A.php
index f77659ab27..a05f9f9c7e 100644
--- a/app/Models/Labels/Sheets/Avery/_5520_A.php
+++ b/app/Models/Labels/Sheets/Avery/_5520_A.php
@@ -149,6 +149,7 @@ class _5520_A extends _5520
{
return [
'barcode_margin' => $this->getBarcodeMargin(),
+ 'barcode_2d_size' => $this->getLabelPrintableArea()->h - (self::TITLE_SIZE + self::TITLE_MARGIN),
'tag_font_size' => $this->getTagSize(),
'title_font_size' => $this->getTitleSize(),
'title_margin' => $this->getTitleMargin(),
@@ -159,6 +160,8 @@ class _5520_A extends _5520
'title_font' => $this->getTitleFont(),
'field_label_font' => $this->getFieldLabelFont(),
'field_value_font' => $this->getFieldValueFont(),
+ 'title_position' => 'top',
+ 'title_offset_x' => 0.590551,
];
}
diff --git a/resources/lang/en-US/admin/labels/general.php b/resources/lang/en-US/admin/labels/general.php
index da0a57bdf9..8c89495865 100644
--- a/resources/lang/en-US/admin/labels/general.php
+++ b/resources/lang/en-US/admin/labels/general.php
@@ -53,6 +53,7 @@ return [
'title_font_size' => 'Font Size',
'title_margin' => 'Margin',
'title_offset_x' => 'Offset X',
+ 'title_position' => 'Title Position',
'field_label_font' => 'Font',
'field_label_font_size' => 'Font Size',
'field_label_margin' => 'Margin',
@@ -76,6 +77,7 @@ return [
'top' => 'Top',
'middle' => 'Middle',
'bottom' => 'Bottom',
+ 'inline' => 'Inline',
],
'create_label' => 'Create Label',
'label_type' => 'Label Type',