阿拉伯字体在dompdf中以相反的顺序显示 [英] arabic fonts display in reverse order in dompdf

查看:27
本文介绍了阿拉伯字体在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; 为任何应该显示 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.)

参考文献:

此外,我们还发现了一个问题,即在呈现单词时字符没有按预期连接在一起.这是我们还没有机会探索的问题.

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中以相反的顺序显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆