Hello,
It seems like you’re discussing a modification to the PDF generation process for WordPress, particularly with regards to handling RTL (right-to-left) text and mixed content (including Arabic characters, numbers, and letters) in the PDF template files. If you want to enhance the functionality to only apply RTL formatting to Arabic characters while leaving other characters unchanged, you can modify the logic as follows:
php // pdf-generator-for-wp/package/lib/dompdf/vendor/dompdf/dompdf/src/Renderer/Text.php // line no 83 if (strtolower($style->direction) === 'rtl') { // Separate Arabic characters from the text using a regular expression preg_match_all('/[\p{Arabic}]/u', $text, $arabicCharacters); // Reverse Arabic characters and keep other characters unchanged $text = preg_replace_callback('/[\p{Arabic}]/u', function($match) { return strrev($match[0]); }, $text); // Join Arabic characters with unchanged characters $text = join('',array_reverse($arabicCharacters[0])); }
Explanation:
- The regular expression
'/[\p{Arabic}]/u'
is used to match Arabic characters within the text.
- We then use
preg_replace_callback()
to reverse each Arabic character found in the text while leaving non-Arabic characters unchanged.
- Finally, we join the reversed Arabic characters with other characters and assign the result back to the
$text
variable.
This modification ensures that only Arabic characters are reversed for RTL formatting, while other characters such as numbers and letters remain unchanged in their original order.
Make sure to test this modification thoroughly to ensure it works as expected with your PDF generation process in WordPress.
Regards,
-
This reply was modified 1 year, 1 month ago by
WP Swings.