Open HirokazuNishi opened 4 years ago
@HirokazuNishi looks like strlen
uses mb_strlen
and split
uses binary safe split so this might be not the reason of the issue.
@lenaorobei for PDF generation, we have to mind character width , too. mb_strwidth can detect the given string contain only single bytes or not. The issue reason is, strlen and split functions in StringUtils doesn't check string width against double byte characters.
Same issue occurs when there are long product names in the invoice or in other PDFs. Is there any workaround for this?
@sukeshini-kot You need to define plugin against StringUtils.
@HirokazuNishi Thank you very much. Adding an around plugin to strlen() solved the issue.
public function aroundStrlen(
\Magento\Framework\Stdlib\StringUtils $subject,
\Closure $proceed,
$string
) {
if ($string !== null) {
if (mb_strlen($string, 'UTF-8') !== strlen($string)) {
// String contains multibyte characters
return strlen($string);
}
return $proceed($string);
}
return 0;
}
Preconditions
Expected result
Actual result
Issue reason
Magento\Framework\Stdlib\StringUtils has 2 methods strlen and split. These are useful for single byte characters for PDF generation. For pdf generation, we have to check the text contains double byte characters or not.