diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 31ea724c0e94..f99374e871c7 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -29,6 +29,7 @@ use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Validator; use Carbon\Carbon; +use TCPDF_FONTS; /** * This controller handles all actions related to Settings for @@ -812,9 +813,42 @@ public function getPhpInfo() */ public function getLabels() { + $fontlist = []; + // this is lifted pretty directly from TCPDF itself; unfortunately + // this method is not exposed, so I had to just steal it :( + if (($fontsdir = opendir(TCPDF_FONTS::_getfontpath())) !== false) { + while (($fontfile = readdir($fontsdir)) !== false) { + if (substr($fontfile, -4) == '.php') { + // these are the variables that are going to get loaded up when we do require() + $name=''; + $type=''; + $up=0; + $ut=0; + $dw=0; + $diff=''; + $originalsize=0; + $enc=''; + $file=''; + $ctg=''; + $desc=[]; + $cbbox=''; + // end require() variables + require(TCPDF_FONTS::_getfontpath()."/".$fontfile); // YUCK!!! + \Log::debug("name is: ".@$name." and "); + if(!$name) { + continue; //these are utility files; not real fonts? + } + $fontlist[strtolower(basename($fontfile, '.php'))] = $name; + } + } + closedir($fontsdir); + } + asort($fontlist, SORT_FLAG_CASE|SORT_STRING); + return view('settings.labels', [ 'setting' => Setting::getSettings(), 'customFields' => CustomField::all(), + 'fonts' => $fontlist ]); } @@ -840,6 +874,8 @@ public function postLabels(Request $request) $setting->label2_2d_type = $request->input('label2_2d_type'); $setting->label2_2d_target = $request->input('label2_2d_target'); $setting->label2_fields = $request->input('label2_fields'); + $setting->label2_mono_font = $request->input('label2_mono_font'); + $setting->label2_variable_font = $request->input('label2_variable_font'); $setting->labels_per_page = $request->input('labels_per_page'); $setting->labels_width = $request->input('labels_width'); $setting->labels_height = $request->input('labels_height'); diff --git a/app/Models/Labels/DefaultLabel.php b/app/Models/Labels/DefaultLabel.php index f06c4582f926..0de8b5b24581 100644 --- a/app/Models/Labels/DefaultLabel.php +++ b/app/Models/Labels/DefaultLabel.php @@ -153,7 +153,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $record->get('title'), $textX1, 0, - 'freesans', 'b', $this->textSize, 'L', + $this->variable_font, 'b', $this->textSize, 'L', $textW, $this->textSize, true, 0 ); @@ -167,7 +167,7 @@ public function write($pdf, $record) { static::writeText( $pdf, 'N: '.$asset->name, $textX1, $textY, - 'freesans', '', $this->textSize, 'L', + $this->variable_font, '', $this->textSize, 'L', $textW, $this->textSize, true, 0 ); @@ -180,7 +180,7 @@ public function write($pdf, $record) { static::writeText( $pdf, 'C: '.$asset->company->name, $textX1, $textY, - 'freesans', '', $this->textSize, 'L', + $this->variable_font, '', $this->textSize, 'L', $textW, $this->textSize, true, 0 ); @@ -193,7 +193,7 @@ public function write($pdf, $record) { static::writeText( $pdf, 'T: '.$asset->asset_tag, $textX1, $textY, - 'freesans', '', $this->textSize, 'L', + $this->variable_font, '', $this->textSize, 'L', $textW, $this->textSize, true, 0 ); @@ -206,7 +206,7 @@ public function write($pdf, $record) { static::writeText( $pdf, 'S: '.$asset->serial, $textX1, $textY, - 'freesans', '', $this->textSize, 'L', + $this->variable_font, '', $this->textSize, 'L', $textW, $this->textSize, true, 0 ); @@ -219,7 +219,7 @@ public function write($pdf, $record) { static::writeText( $pdf, 'M: '.$asset->model->name, $textX1, $textY, - 'freesans', '', $this->textSize, 'L', + $this->variable_font, '', $this->textSize, 'L', $textW, $this->textSize, true, 0 ); diff --git a/app/Models/Labels/Label.php b/app/Models/Labels/Label.php index b727c1cb1898..df2e475e3a27 100644 --- a/app/Models/Labels/Label.php +++ b/app/Models/Labels/Label.php @@ -16,6 +16,9 @@ */ abstract class Label { + public string $variable_font; + public string $mono_font; + /** * Returns the unit of measure used * 'pt', 'mm', 'cm', 'in' diff --git a/app/Models/Labels/Sheets/Avery/L7162_A.php b/app/Models/Labels/Sheets/Avery/L7162_A.php index 0b3312ba7ce4..9faf8f8a352a 100644 --- a/app/Models/Labels/Sheets/Avery/L7162_A.php +++ b/app/Models/Labels/Sheets/Avery/L7162_A.php @@ -45,7 +45,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $record->get('tag'), $pa->x1, $pa->y2 - self::TAG_SIZE, - 'freemono', 'b', self::TAG_SIZE, 'C', + $this->mono_font, 'b', self::TAG_SIZE, 'C', //was 'freemono' $barcodeSize, self::TAG_SIZE, true, 0 ); static::write2DBarcode( @@ -59,7 +59,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $record->get('tag'), $pa->x1, $pa->y1, - 'freemono', 'b', self::TITLE_SIZE, 'L', + $this->mono_font, 'b', self::TITLE_SIZE, 'L', //was 'freemono' $barcodeSize, self::TITLE_SIZE, true, 0 ); $titleShiftX = $barcodeSize; @@ -69,7 +69,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $record->get('title'), $currentX + $titleShiftX, $currentY, - 'freesans', '', self::TITLE_SIZE, 'L', + $this->variable_font, '', self::TITLE_SIZE, 'L', //was 'freesans' $usableWidth, self::TITLE_SIZE, true, 0 ); $currentY += self::TITLE_SIZE + self::TITLE_MARGIN; @@ -79,7 +79,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $field['label'], $currentX, $currentY, - 'freesans', '', self::LABEL_SIZE, 'L', + $this->variable_font, '', self::LABEL_SIZE, 'L', // also was 'freesans' $usableWidth, self::LABEL_SIZE, true, 0 ); $currentY += self::LABEL_SIZE + self::LABEL_MARGIN; @@ -87,7 +87,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $field['value'], $currentX, $currentY, - 'freemono', 'B', self::FIELD_SIZE, 'L', + $this->mono_font, 'B', self::FIELD_SIZE, 'L', // also was freemono? $usableWidth, self::FIELD_SIZE, true, 0, 0.3 ); $currentY += self::FIELD_SIZE + self::FIELD_MARGIN; diff --git a/app/Models/Labels/Sheets/Avery/L7162_B.php b/app/Models/Labels/Sheets/Avery/L7162_B.php index 268754e04f45..952c3420a70e 100644 --- a/app/Models/Labels/Sheets/Avery/L7162_B.php +++ b/app/Models/Labels/Sheets/Avery/L7162_B.php @@ -65,7 +65,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $record->get('title'), $currentX, $currentY, - 'freesans', '', self::TITLE_SIZE, 'L', + $this->variable_font, '', self::TITLE_SIZE, 'L', $usableWidth, self::TITLE_SIZE, true, 0 ); $currentY += self::TITLE_SIZE + self::TITLE_MARGIN; @@ -75,7 +75,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $field['label'], $currentX, $currentY, - 'freesans', '', self::LABEL_SIZE, 'L', + $this->variable_font, '', self::LABEL_SIZE, 'L', $usableWidth, self::LABEL_SIZE, true, 0 ); $currentY += self::LABEL_SIZE + self::LABEL_MARGIN; @@ -83,7 +83,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $field['value'], $currentX, $currentY, - 'freemono', 'B', self::FIELD_SIZE, 'L', + $this->mono_font, 'B', self::FIELD_SIZE, 'L', $usableWidth, self::FIELD_SIZE, true, 0, 0.3 ); $currentY += self::FIELD_SIZE + self::FIELD_MARGIN; @@ -92,7 +92,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $record->get('tag'), $currentX, $pa->y2 - self::BARCODE_SIZE - self::BARCODE_MARGIN - self::TAG_SIZE, - 'freemono', 'b', self::TAG_SIZE, 'R', + $this->mono_font, 'b', self::TAG_SIZE, 'R', $usableWidth, self::TAG_SIZE, true, 0, 0.3 ); diff --git a/app/Models/Labels/Sheets/Avery/L7163_A.php b/app/Models/Labels/Sheets/Avery/L7163_A.php index 6dc33f64dd44..3d6d0e1d4d09 100644 --- a/app/Models/Labels/Sheets/Avery/L7163_A.php +++ b/app/Models/Labels/Sheets/Avery/L7163_A.php @@ -42,7 +42,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $record->get('title'), $currentX, $currentY, - 'freesans', '', self::TITLE_SIZE, 'C', + $this->variable_font, '', self::TITLE_SIZE, 'C', $usableWidth, self::TITLE_SIZE, true, 0 ); $currentY += self::TITLE_SIZE + self::TITLE_MARGIN; @@ -54,7 +54,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $record->get('tag'), $pa->x1, $pa->y2 - self::TAG_SIZE, - 'freemono', 'b', self::TAG_SIZE, 'C', + $this->mono_font, 'b', self::TAG_SIZE, 'C', $barcodeSize, self::TAG_SIZE, true, 0 ); static::write2DBarcode( @@ -68,7 +68,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $record->get('tag'), $pa->x1, $pa->y2 - self::TAG_SIZE, - 'freemono', 'b', self::TAG_SIZE, 'R', + $this->mono_font, 'b', self::TAG_SIZE, 'R', $usableWidth, self::TAG_SIZE, true, 0 ); } @@ -77,7 +77,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $field['label'], $currentX, $currentY, - 'freesans', '', self::LABEL_SIZE, 'L', + $this->variable_font, '', self::LABEL_SIZE, 'L', $usableWidth, self::LABEL_SIZE, true, 0 ); $currentY += self::LABEL_SIZE + self::LABEL_MARGIN; @@ -85,7 +85,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $field['value'], $currentX, $currentY, - 'freemono', 'B', self::FIELD_SIZE, 'L', + $this->mono_font, 'B', self::FIELD_SIZE, 'L', $usableWidth, self::FIELD_SIZE, true, 0, 0.5 ); $currentY += self::FIELD_SIZE + self::FIELD_MARGIN; diff --git a/app/Models/Labels/Sheets/Avery/_5267_A.php b/app/Models/Labels/Sheets/Avery/_5267_A.php index efe0855d5e9f..dcdb6c83d419 100644 --- a/app/Models/Labels/Sheets/Avery/_5267_A.php +++ b/app/Models/Labels/Sheets/Avery/_5267_A.php @@ -43,7 +43,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $record->get('title'), $pa->x1, $pa->y1, - 'freesans', '', self::TITLE_SIZE, 'L', + $this->variable_font, '', self::TITLE_SIZE, 'L', $pa->w, self::TITLE_SIZE, true, 0 ); } @@ -55,7 +55,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $field['value'], $pa->x1, $fieldY, - 'freemono', 'B', self::FIELD_SIZE, 'C', + $this->mono_font, 'B', self::FIELD_SIZE, 'C', $pa->w, self::FIELD_SIZE, true, 0, 0.01 ); } diff --git a/app/Models/Labels/Sheets/Avery/_5520_A.php b/app/Models/Labels/Sheets/Avery/_5520_A.php index 199566d2485b..b3b9bfd65d4e 100644 --- a/app/Models/Labels/Sheets/Avery/_5520_A.php +++ b/app/Models/Labels/Sheets/Avery/_5520_A.php @@ -42,7 +42,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $record->get('title'), $pa->x1, $pa->y1, - 'freesans', '', self::TITLE_SIZE, 'C', + $this->variable_font, '', self::TITLE_SIZE, 'C', $pa->w, self::TITLE_SIZE, true, 0 ); $currentY += self::TITLE_SIZE + self::TITLE_MARGIN; @@ -64,7 +64,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $field['label'], $currentX, $currentY, - 'freesans', '', self::LABEL_SIZE, 'L', + $this->variable_font, '', self::LABEL_SIZE, 'L', $usableWidth, self::LABEL_SIZE, true, 0 ); $currentY += self::LABEL_SIZE + self::LABEL_MARGIN; @@ -72,7 +72,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $field['value'], $currentX, $currentY, - 'freemono', 'B', self::FIELD_SIZE, 'L', + $this->mono_font, 'B', self::FIELD_SIZE, 'L', $usableWidth, self::FIELD_SIZE, true, 0, 0.01 ); $currentY += self::FIELD_SIZE + self::FIELD_MARGIN; diff --git a/app/Models/Labels/Tapes/Brother/TZe_12mm_A.php b/app/Models/Labels/Tapes/Brother/TZe_12mm_A.php index f89cfc5d47ef..d5cecc9d131b 100644 --- a/app/Models/Labels/Tapes/Brother/TZe_12mm_A.php +++ b/app/Models/Labels/Tapes/Brother/TZe_12mm_A.php @@ -39,7 +39,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $record->get('tag'), $pa->x1, $currentY, - 'freemono', 'b', $fontSize, 'L', + $this->mono_font, 'b', $fontSize, 'L', $tagWidth, $usableHeight, true, 0, 0 ); @@ -47,7 +47,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $record->get('fields')->values()->get(0)['value'], $pa->x1 + ($tagWidth), $currentY, - 'freemono', 'b', $fontSize, 'R', + $this->mono_font, 'b', $fontSize, 'R', $fieldWidth, $usableHeight, true, 0, 0 ); } diff --git a/app/Models/Labels/Tapes/Brother/TZe_24mm_A.php b/app/Models/Labels/Tapes/Brother/TZe_24mm_A.php index ea4c6c9dfba2..d6b70e74d5c6 100644 --- a/app/Models/Labels/Tapes/Brother/TZe_24mm_A.php +++ b/app/Models/Labels/Tapes/Brother/TZe_24mm_A.php @@ -37,7 +37,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $record->get('tag'), $pa->x1, $pa->y2 - self::TAG_SIZE, - 'freemono', 'b', self::TAG_SIZE, 'C', + $this->mono_font, 'b', self::TAG_SIZE, 'C', $barcodeSize, self::TAG_SIZE, true, 0 ); static::write2DBarcode( @@ -51,7 +51,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $record->get('tag'), $pa->x1, $pa->y2 - self::TAG_SIZE, - 'freemono', 'b', self::TAG_SIZE, 'R', + $this->mono_font, 'b', self::TAG_SIZE, 'R', $usableWidth, self::TAG_SIZE, true, 0 ); } @@ -60,7 +60,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $record->get('title'), $currentX, $currentY, - 'freesans', '', self::TITLE_SIZE, 'L', + $this->variable_font, '', self::TITLE_SIZE, 'L', $usableWidth, self::TITLE_SIZE, true, 0 ); $currentY += self::TITLE_SIZE + self::TITLE_MARGIN; @@ -70,7 +70,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $field['label'], $currentX, $currentY, - 'freesans', '', self::LABEL_SIZE, 'L', + $this->variable_font, '', self::LABEL_SIZE, 'L', $usableWidth, self::LABEL_SIZE, true, 0, 0 ); $currentY += self::LABEL_SIZE + self::LABEL_MARGIN; @@ -78,7 +78,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $field['value'], $currentX, $currentY, - 'freemono', 'B', self::FIELD_SIZE, 'L', + $this->mono_font, 'B', self::FIELD_SIZE, 'L', $usableWidth, self::FIELD_SIZE, true, 0, 0.3 ); $currentY += self::FIELD_SIZE + self::FIELD_MARGIN; diff --git a/app/Models/Labels/Tapes/Dymo/LabelWriter_30252.php b/app/Models/Labels/Tapes/Dymo/LabelWriter_30252.php index d5f0e8d12229..0b03ae1e1fa8 100644 --- a/app/Models/Labels/Tapes/Dymo/LabelWriter_30252.php +++ b/app/Models/Labels/Tapes/Dymo/LabelWriter_30252.php @@ -40,7 +40,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $record->get('tag'), $pa->x1, $pa->y2 - self::TAG_SIZE, - 'freemono', 'b', self::TAG_SIZE, 'C', + $this->mono_font, 'b', self::TAG_SIZE, 'C', $barcodeSize, self::TAG_SIZE, true, 0 ); static::write2DBarcode( @@ -54,7 +54,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $record->get('tag'), $pa->x1, $pa->y2 - self::TAG_SIZE, - 'freemono', 'b', self::TAG_SIZE, 'R', + $this->mono_font, 'b', self::TAG_SIZE, 'R', $usableWidth, self::TAG_SIZE, true, 0 ); } @@ -63,7 +63,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $record->get('title'), $currentX, $currentY, - 'freesans', '', self::TITLE_SIZE, 'L', + $this->variable_font, '', self::TITLE_SIZE, 'L', $usableWidth, self::TITLE_SIZE, true, 0 ); $currentY += self::TITLE_SIZE + self::TITLE_MARGIN; @@ -73,7 +73,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $field['label'], $currentX, $currentY, - 'freesans', '', self::LABEL_SIZE, 'L', + $this->variable_font, '', self::LABEL_SIZE, 'L', $usableWidth, self::LABEL_SIZE, true, 0, 0 ); $currentY += self::LABEL_SIZE + self::LABEL_MARGIN; @@ -81,7 +81,7 @@ public function write($pdf, $record) { static::writeText( $pdf, $field['value'], $currentX, $currentY, - 'freemono', 'B', self::FIELD_SIZE, 'L', + $this->mono_font, 'B', self::FIELD_SIZE, 'L', $usableWidth, self::FIELD_SIZE, true, 0, 0.3 ); $currentY += self::FIELD_SIZE + self::FIELD_MARGIN; diff --git a/app/View/Label.php b/app/View/Label.php index 83184e4b0491..e8ae22fd933c 100644 --- a/app/View/Label.php +++ b/app/View/Label.php @@ -35,7 +35,7 @@ public function __construct() { */ public function render(callable $callback = null) { - $settings = $this->data->get('settings'); + $settings = $this->data->get('settings'); //this has *ALL* settings!!! $assets = $this->data->get('assets'); $offset = $this->data->get('offset'); $template = $this->data->get('template'); @@ -64,6 +64,9 @@ public function render(callable $callback = null) [ $template->getWidth(), $template->getHeight() ] ); + // Required for CJK languages; otherwise the embedded font can get too massive + $pdf->SetFontSubsetting(true); + // Reset parameters $pdf->SetPrintHeader(false); $pdf->SetPrintFooter(false); @@ -75,6 +78,9 @@ public function render(callable $callback = null) $pdf->SetSubject('Asset Labels'); $template->preparePDF($pdf); + $template->variable_font = $settings->label2_variable_font; + $template->mono_font = $settings->label2_mono_font; + // Get fields from settings $fieldDefinitions = collect(explode(';', $settings->label2_fields)) ->filter(fn($fieldString) => !empty($fieldString)) @@ -170,6 +176,7 @@ public function render(callable $callback = null) $template->writeAll($pdf, $data); $filename = $assets->count() > 1 ? 'assets.pdf' : $assets->first()->asset_tag.'.pdf'; + $pdf->Output($filename, 'I'); } diff --git a/database/migrations/2024_02_08_165209_add_fonts_to_settings.php b/database/migrations/2024_02_08_165209_add_fonts_to_settings.php new file mode 100644 index 000000000000..92f4eb93d6b4 --- /dev/null +++ b/database/migrations/2024_02_08_165209_add_fonts_to_settings.php @@ -0,0 +1,35 @@ +string('label2_variable_font')->default('freesans'); + $table->string('label2_mono_font')->default('freemono'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('settings', function (Blueprint $table) { + // + $table->dropColumn(['label2_variable_font','label2_mono_font']); + }); + } +} diff --git a/resources/lang/en-US/admin/settings/general.php b/resources/lang/en-US/admin/settings/general.php index 33cfd7b416fb..ba2ca8c87a0f 100644 --- a/resources/lang/en-US/admin/settings/general.php +++ b/resources/lang/en-US/admin/settings/general.php @@ -349,6 +349,10 @@ 'label2_2d_target_help' => 'The URL the 2D barcode points to when scanned', 'label2_fields' => 'Field Definitions', 'label2_fields_help' => 'Fields can be added, removed, and reordered in the left column. For each field, multiple options for Label and DataSource can be added, removed, and reordered in the right column.', + 'label2_variable_width_font' => 'Variable-width font', + 'label2_variable_width_font_hint' => '"FreeSans" is the default', + 'label2_fixed_width_font' => 'Fixed-width font', + 'label2_fixed_width_font_hint' => '"FreeMono" is the default', 'help_asterisk_bold' => 'Text entered as **text** will be displayed as bold', 'help_blank_to_use' => 'Leave blank to use the value from :setting_name', 'help_default_will_use' => ':default will use the value from :setting_name.
Note that the value of the barcodes must comply with the respective barcode spec in order to be successfully generated. Please see the documentation for more details. ', diff --git a/resources/views/settings/labels.blade.php b/resources/views/settings/labels.blade.php index a6edd29154be..9e34c761cd89 100644 --- a/resources/views/settings/labels.blade.php +++ b/resources/views/settings/labels.blade.php @@ -122,6 +122,29 @@ class="table table-striped snipe-table" + +
+
+ {{ Form::label('label2_variable_font',trans('admin/settings/general.label2_variable_width_font'), ['class' => 'control-label']) }} +
+
+ {{ Form::select('label2_variable_font', $fonts, old('label2_variable_font', $setting->label2_variable_font), [ 'class'=>'select2 col-md-3', 'aria-label'=>'label2_variable_font' ]) }} + {{ trans('admin/settings/general.label2_variable_width_font_hint') }} +
+
+ + +
+
+ {{ Form::label('label2_mono_font',trans('admin/settings/general.label2_fixed_width_font'), ['class' => 'control-label']) }} +
+
+ {{ Form::select('label2_mono_font', $fonts, old('label2_mono_font', $setting->label2_mono_font), [ 'class'=>'select2 col-md-3', 'aria-label'=>'label2_mono_font' ]) }} + {{ trans('admin/settings/general.label2_fixed_width_font_hint') }} +
+
+ +
has('label2_asset_logo') ? 'error' : '' }}">