3
0
mirror of https://github.com/snipe/snipe-it.git synced 2025-10-29 11:21:21 +00:00

Fixed CJK on labels

This commit is contained in:
snipe 2025-09-16 12:10:01 +01:00
parent c7d8203da9
commit b383cd9493
3 changed files with 20 additions and 8 deletions

View File

@ -229,7 +229,7 @@ class DefaultLabel extends RectangleSheet
static::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 RectangleSheet
static::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++;
}

View File

@ -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,
];

View File

@ -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: