- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设我有这段阿拉伯语片段:
إذاأخذstأخذأخذأخذأخذأخذأخذااإإططططlistianteطططط。
在英语中,这应该是这样的意思:“如果我们考虑到气候变率和年际变率的性质,以及那些长期缺乏测量和计算准确性的因素……。”
现在我想将其呈现为 Reportlab PDF 文档(python):
arabic_text = u'إذا أخذنا بعين الإعتبار طبيعة تقلب المناخ و المتغيرات البينية السنوية و تلك على المدى الطويل إضافة إلى عدم دقة القياسات والحسابات المتبعة'
arabic_text = arabic_reshaper.reshape(arabic_text) # join characters
arabic_text = get_display(arabic_text) # change orientation by using bidi
pdf_file=open('disclaimer.pdf','w')
pdf_doc = SimpleDocTemplate(pdf_file, pagesize=A4)
pdfmetrics.registerFont(TTFont('Arabic-normal', '../fonts/KacstOne.ttf'))
style = ParagraphStyle(name='Normal', fontName='Arabic-normal', fontSize=12, leading=12. * 1.2)
style.alignment=TA_RIGHT
pdf_doc.build([Paragraph(arabic_text, style)])
pdf_file.close()
结果在这里https://www.dropbox.com/s/gdyt6930jlad8id/disclaimer.pdf .您可以看到文本本身是正确且可读的(至少对于 Google 翻译而言),但未按 RTL 脚本的预期换行。
最佳答案
如果您使用 this branch of Report lab that adds RTL support
并从您的代码中删除这一行:
arabic_text = get_display(arabic_text) # change orientation by using bidi
您的代码将正常运行
因为它们已经通过使用 PyFriBiDi 的分支解决了如你所见here :
Some users from the community notably Ury Marshak, Moshe Wagner and Hosam Aly have contributed batches to get PyFriBibi working with ReportLab. We have created an SVN branch for this development and it is available at ...
(该页面上的 SVN 链接不再有效,因此您应该使用我提供的 bitbucket 链接!)
我已经成功地运行了你的代码的这个修改版本并产生了正确的结果:
from libs import arabic_reshaper
from bidi.algorithm import get_display
from reportlab.platypus import SimpleDocTemplate, Paragraph
from reportlab.pdfbase import pdfmetrics
from reportlab.lib.styles import ParagraphStyle
from reportlab.lib.enums import TA_RIGHT
from reportlab.lib.pagesizes import A4
from reportlab.pdfbase.ttfonts import TTFont
arabic_text = u'إذا أخذنا بعين الإعتبار طبيعة تقلب المناخ و المتغيرات البينية السنوية و تلك على المدى الطويل إضافة إلى عدم دقة القياسات والحسابات المتبعة'
arabic_text = arabic_reshaper.reshape(arabic_text) # join characters
# arabic_text = get_display(arabic_text) # change orientation by using bidi
pdf_file=open('disclaimer.pdf','w')
pdf_doc = SimpleDocTemplate(pdf_file, pagesize=A4)
pdfmetrics.registerFont(TTFont('Arabic-normal', 'fonts/misc/KacstOne.ttf'))
style = ParagraphStyle(name='Normal', fontName='Arabic-normal', fontSize=12, leading=12. * 1.2)
style.alignment=TA_RIGHT
pdf_doc.build([Paragraph(arabic_text, style)])
pdf_file.close()
关于python - 阿拉伯语文本未正确包装在 reportlab 的段落中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17166198/
我正在使用 Solr 以 3 种语言(阿拉伯语、法语和英语)索引文档,我使用了这个 fieldType :
当我在设备(它的语言是阿拉伯语)中运行我的应用程序时,我感到震惊的是,应该在正确方向的对象会向左移动,反之亦然。 后来我意识到是阿拉伯语本地化的自动布局导致了这个问题。 我以编程方式设置自动布局如下:
我想一个字母一个字母地拆分阿拉伯语单词,将它们涂成不同的颜色并在其上添加事件处理程序。 Image, how it looks like 我实现了关于绘画的部分想法,并处理了辅音字母 (harf),但
我关注 this教程,一切都很好,我预处理和训练我的模型但是当我想找到与以下代码的相似之处时: model = gensim.models.Word2Vec.load("wiki.fa.word2ve
我在使用阿拉伯语文本进行变音符号不敏感搜索时遇到问题。 我已经为相关表格测试了多种设置:utf8 和 utf16 编码以及 utf8_general_ci、utf16_general_ci 和 utf
我正在评估 NLTK 在分析和提取情绪的研究中处理阿拉伯文本的能力。 问题如下: NTLK 是否能够处理并允许分析阿拉伯文本? python 是否能够操作\标记阿拉伯文本? 我能否使用 Python
我正在使用 PHPMailer API 发送电子邮件。我想知道如何用阿拉伯语(非英语)发送主题 $mail->CharSet = 'utf-8'; $array= FetchTable('cos
在过去的 15 天或更长时间里,我一直在为一个奇怪的问题而苦苦挣扎。实际上我有一些阿拉伯语文本,但也有一些英文文本。 MY NAME "some arabic text" "some arabic t
我想用阿拉伯语制作一个 flutter 日期选择器,但有一些变化,这是我的代码: locale: Locale('ar', 'MA'), localizationsDelegates: [
我一直在努力为移动应用程序寻找良好的国际日历支持(包括 Hirji)。我的主要限制是 JVM 是 1.3 并且我们只有 AWT。有一个选项可以转移到另一个为我们提供 SWT 的 JVM,但我似乎找不到
我的应用程序是用英语和阿拉伯语两种不同版本开发的。 我在 iText 中使用 rowspan 和 colspan 创建了 pdf 表格,这在英文版中运行良好,但在阿拉伯语版 rowspan 中不起作用
我想将阿拉伯语单词分割成单个字符。基于直方图/配置文件,我假设我可以通过根据其基线(它具有相似的像素值)剪切/分割字符来进行分割过程。 但是,不幸的是,我仍然坚持构建适当的代码,以使其工作。 % Or
我在 JavaScript 函数中遇到了问题 var tDate = new Intl.DateTimeFormat("ar-US", { day: 'numeric', month: 'lo
我已经编写了 java 代码,我希望在 PdfPTable 上显示阿拉伯文字,该 PdfPTable 被用于 itext 文档以创建 PDF 文档 如附图“???”是阿拉伯代码' PdfPTable
简单地说,有没有支持Lucene.Net的Arabic Analyzer。因为我想索引大量的阿拉伯语 txt 文件。我可以使用标准分析器或空白分析器来解析阿拉伯文文件吗? analyzer = new
我正在使用 Vuejs,我想防止输入标签显示用户的字符并将其替换为我自己的字符(这是一些数字)。 我已经在计算中使用了@onchange 和 Watch 以及 getter 和 setter。问题是字
我正在研究 RTL 功能。我从数据库中获取字符串值作为 (f1 (firstname。但我想要 f1 (firstname) 这是我的 javascript 代码。下面的代码运行良好 EN语言。它不仅
我已经下载了阿拉伯语格式的阿拉伯语语言包和编辑器显示,但是当我纠正一些它不是用正确的方向写它总是从左方向开始,阿拉伯语总是从右方向开始但是这是行不通的.. 我的代码——
我使用的是 3.8.2 版本,插入新记录时,utf8 字符串在数据库中显示为问号 (?),但它会正确显示旧记录(使用 phpmyadmin 插入)。 这是我如何初始化 MySQLPool fun in
我有一个阿拉伯语短信模板,其中包含客户支持号码的占位符,并将占位符替换为实际电话号码(例如 +987654400)。替换时加号 (+) 错位在数字末尾,如 987654400+ 示例代码: >>> >
我是一名优秀的程序员,十分优秀!