阿拉伯字体在dompdf中以相反的顺序显示

阿拉伯字体在dompdf中以相反的顺序显示

本文介绍了阿拉伯字体在dompdf中以相反的顺序显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用dompdf来使用dompdf转换html页面,但是它以相反的顺序显示阿拉伯文本

I am using dompdf to convert a html page using dompdf, but it is showing arabic text in reverse order

例如,如果文本是

ايبنسيالرمس

ايبنسيالرمس

然后它显示为

PDF中的مرلايسنبيا

مرلايسنبيا in PDF

知道为什么吗?

推荐答案

dompdf当前不支持方向性,因此关于字符流,RTL语言将无法正确显示.尽管确实需要修改dompdf代码,但仍有一种可以按正确顺序显示字符的技巧.

dompdf does not currently support directionality, so RTL languages will not display correctly in regard to character flow. There is a hack for displaying characters in the correct order, though it does require modification of the dompdf code.

如果您想尝试修改,则需要两个步骤.首先,用direction: rtl; text-align: right;设置应显示RTL的所有文本的样式.然后,在文件dompdf/include/text_renderer.cls.php中,在$canvas->text()(或任何变体,例如$this->_canvas->text())的每个实例之前添加以下行:

If you would like to try the modification two steps are required. First, style any text that should display RTL with direction: rtl; text-align: right;. Then, in the file dompdf/include/text_renderer.cls.php add the following lines before each instance of $canvas->text() (or any variant, such as $this->_canvas->text()):

if (strtolower($style->direction) == 'rtl') {
  preg_match_all('/./us', $text, $ar);
  $text = join('',array_reverse($ar[0]));
}

(您可能必须更改$text变量的名称以匹配代码中使用的名称.)

(You may have to change the name of the $text variable to match what's used in the code.)

参考:

  • https://github.com/dompdf/dompdf/issues/426
  • https://groups.google.com/d/topic/dompdf/qfWb24ct7Ts/discussion

此外,我们还看到了一个问题,即在渲染单词时字符无法按预期的方式连接在一起.这是我们尚未有机会探讨的问题.

Additionally we've seen an issues where characters don't join together as expected when rendering words. This is an issue we haven't had a chance to explore yet.

参考:

目前,要完全支持方向性,您最好的选择是使用无头浏览器,例如 PhantomJS .

Your best option right now for full support of directionality is to use a headless browser, e.g. PhantomJS.

这篇关于阿拉伯字体在dompdf中以相反的顺序显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 00:00