magento / magento2-jp

Magento Community Project for providing best experience for Japanese market
Open Software License 3.0
24 stars 34 forks source link

Long address texts are overlapped on invoice/creditmemo pdf #107

Open HirokazuNishi opened 4 years ago

HirokazuNishi commented 4 years ago

Preconditions

  1. Install Magento2.3.4 with sample data.
  2. Install CommunityEngineering_ConfigurablePdfFont.
  3. Create customer account with long address text data.
  4. Create order.
  5. Create invoice.

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.

lenaorobei commented 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.

HirokazuNishi commented 4 years ago

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

sukeshini-kot commented 2 years ago

Same issue occurs when there are long product names in the invoice or in other PDFs. Is there any workaround for this?

HirokazuNishi commented 2 years ago

@sukeshini-kot You need to define plugin against StringUtils.

sukeshini-kot commented 2 years ago

@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;
    }