forked from CGM_Public/pretix_original
PDF renderer: Support for arabic
This commit is contained in:
@@ -10,6 +10,8 @@ from functools import partial
|
||||
from io import BytesIO
|
||||
|
||||
import bleach
|
||||
from arabic_reshaper import ArabicReshaper
|
||||
from bidi.algorithm import get_display
|
||||
from django.conf import settings
|
||||
from django.contrib.staticfiles import finders
|
||||
from django.dispatch import receiver
|
||||
@@ -449,6 +451,16 @@ class Renderer:
|
||||
tags=["br"], attributes={}, styles=[], strip=True
|
||||
)
|
||||
)
|
||||
|
||||
# reportlab does not support RTL, ligature-heavy scripts like Arabic. Therefore, we use ArabicReshaper
|
||||
# to resolve all ligatures and python-bidi to switch RTL texts.
|
||||
configuration = {
|
||||
'delete_harakat': True,
|
||||
'support_ligatures': False,
|
||||
}
|
||||
reshaper = ArabicReshaper(configuration=configuration)
|
||||
text = "<br/>".join(get_display(reshaper.reshape(l)) for l in text.split("<br/>"))
|
||||
|
||||
p = Paragraph(text, style=style)
|
||||
p.wrapOn(canvas, float(o['width']) * mm, 1000 * mm)
|
||||
# p_size = p.wrap(float(o['width']) * mm, 1000 * mm)
|
||||
|
||||
@@ -62,3 +62,5 @@ django-redis==4.10.*
|
||||
redis==3.2.*
|
||||
django-phonenumber-field==3.0.*
|
||||
phonenumberslite==8.10.*
|
||||
python-bidi==0.4.* # Support for arabic in reportlab
|
||||
python-arabic-reshaper==2.0.15 # Support for Aabic in reportlab
|
||||
@@ -148,6 +148,8 @@ setup(
|
||||
'urllib3==1.24.*', # required by current requests
|
||||
'django-phonenumber-field==3.0.*',
|
||||
'phonenumberslite==8.10.*',
|
||||
'python-bidi==0.4.*', # Support for Arabic in reportlab
|
||||
'python-arabic-reshaper==2.0.15', # Support for Arabic in reportlab
|
||||
],
|
||||
extras_require={
|
||||
'dev': [
|
||||
|
||||
Reference in New Issue
Block a user