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

Fixed CJK characters not rendering in new Label Engine [sc-24364] #14235

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions app/Http/Controllers/SettingsController.php
Expand Up @@ -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
Expand Down Expand Up @@ -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
]);
}

Expand All @@ -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');
Expand Down
12 changes: 6 additions & 6 deletions app/Models/Labels/DefaultLabel.php
Expand Up @@ -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
);
Expand All @@ -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
);
Expand All @@ -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
);
Expand All @@ -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
);
Expand All @@ -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
);
Expand All @@ -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
);
Expand Down
3 changes: 3 additions & 0 deletions app/Models/Labels/Label.php
Expand Up @@ -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'
Expand Down
10 changes: 5 additions & 5 deletions app/Models/Labels/Sheets/Avery/L7162_A.php
Expand Up @@ -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(
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -79,15 +79,15 @@ 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;

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;
Expand Down
8 changes: 4 additions & 4 deletions app/Models/Labels/Sheets/Avery/L7162_B.php
Expand Up @@ -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;
Expand All @@ -75,15 +75,15 @@ 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;

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;
Expand All @@ -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
);

Expand Down
10 changes: 5 additions & 5 deletions app/Models/Labels/Sheets/Avery/L7163_A.php
Expand Up @@ -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;
Expand All @@ -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(
Expand All @@ -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
);
}
Expand All @@ -77,15 +77,15 @@ 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;

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;
Expand Down
4 changes: 2 additions & 2 deletions app/Models/Labels/Sheets/Avery/_5267_A.php
Expand Up @@ -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
);
}
Expand All @@ -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
);
}
Expand Down
6 changes: 3 additions & 3 deletions app/Models/Labels/Sheets/Avery/_5520_A.php
Expand Up @@ -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;
Expand All @@ -64,15 +64,15 @@ 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;

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;
Expand Down
4 changes: 2 additions & 2 deletions app/Models/Labels/Tapes/Brother/TZe_12mm_A.php
Expand Up @@ -39,15 +39,15 @@ 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
);

if ($record->get('fields')->count() >= 1) {
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
);
}
Expand Down
10 changes: 5 additions & 5 deletions app/Models/Labels/Tapes/Brother/TZe_24mm_A.php
Expand Up @@ -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(
Expand All @@ -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
);
}
Expand All @@ -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;
Expand All @@ -70,15 +70,15 @@ 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;

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;
Expand Down