A free open source IT asset/license management system
Fixed CJK on labels
snipeb383cd949344
diff --git a/app/Models/Labels/DefaultLabel.php b/app/Models/Labels/DefaultLabel.phpindex fa60dafab3..0ac2eb14da 100644--- a/app/Models/Labels/DefaultLabel.php+++ b/app/Models/Labels/DefaultLabel.php@@ -229,7 +229,7 @@ class DefaultLabel extends RectangleSheetstatic::writeText($pdf, $record->get('title'),$textX1, 0,- 'freesans', 'b', $this->textSize, 'L',+ Helper::isCjk($record->get('title')) ? 'cid0cs' : 'freesans', 'b', $this->textSize, 'L',$textW, $this->textSize,true, 0);@@ -246,11 +246,12 @@ class DefaultLabel extends RectangleSheetstatic::writeText($pdf, (($field['label']) ? $field['label'].' ' : '') . $field['value'],$textX1, $textY,- 'freesans', '', $this->textSize, 'L',+ Helper::isCjk($field['label']) ? 'cid0cs' : 'freesans', '', $this->textSize, 'L',$textW, $this->textSize,true, 0);+$textY += $this->textSize + self::TEXT_MARGIN;$fieldsDone++;}diff --git a/app/Models/Labels/Label.php b/app/Models/Labels/Label.phpindex cff859f359..2c463e0921 100644--- a/app/Models/Labels/Label.php+++ b/app/Models/Labels/Label.php@@ -211,29 +211,36 @@ abstract class Label*/public final function writeText(TCPDF $pdf, $text, $x, $y, $font=null, $style=null, $size=null, $align='L', $width=null, $height=null, $squash=false, $border=0, $spacing=0){++$prevFamily = $pdf->getFontFamily();$prevStyle = $pdf->getFontStyle();$prevSizePt = $pdf->getFontSizePt();+$text = !empty($text) ? $text : '';$fontFamily = !empty($font) ? $font : $prevFamily;$fontStyle = !empty($style) ? $style : $prevStyle;- if ($size) { $fontSizePt = Helper::convertUnit($size, $this->getUnit(), 'pt', true);- } else { $fontSizePt = $prevSizePt;+++ if ($size) {+ $fontSizePt = Helper::convertUnit($size, $this->getUnit(), 'pt', true);+ } else {+ $fontSizePt = $prevSizePt;}$pdf->SetFontSpacing($spacing);$parts = collect(explode('**', $text))->map(- function ($part, $index) use ($pdf, $fontFamily, $fontStyle, $fontSizePt) {+ function ($part, $index) use ($pdf, $fontFamily, $fontStyle, $fontSizePt, $text) {$modStyle = ($index % 2 == 1) ? 'B' : $fontStyle;$pdf->setFont($fontFamily, $modStyle, $fontSizePt);return ['text' => $part,'text_width' => $pdf->GetStringWidth($part),- 'font_family' => $fontFamily,+ 'font_family' => Helper::isCjk($text) ? 'cid0cs' : $fontFamily,'font_style' => $modStyle,'font_size' => $fontSizePt,];diff --git a/app/View/Label.php b/app/View/Label.phpindex ee9a1ae2fd..96f88e0f5f 100644--- a/app/View/Label.php+++ b/app/View/Label.php@@ -74,6 +74,10 @@ class Label implements View[0 => $template->getWidth(), 1 => $template->getHeight(), 'Rotate' => $template->getRotation()]);+ // Required for CJK languages, otherwise the embedded font can get too massive+ $pdf->SetFontSubsetting(true);++// Reset parameters$pdf->SetPrintHeader(false);$pdf->SetPrintFooter(false);@@ -176,14 +180,14 @@ class Label implements View// For fields that have multiple options, we need to combine them// into a single field so all values are displayed.->reduce(function ($previous, $current) {- // On the first iteration we simply return the item.+ // On the first iteration, we simply return the item.// If there is only one item to be processed for the row// then this effectively skips everything below this if block.if (is_null($previous)) {return $current;}- // At this point we are dealing with a row with multiple items being displayed.+ // At this point, we are dealing with a row with multiple items being displayed.// We need to combine the label and value of the current item with the previous item.// The end result of this will be in this format: