4

I'm trying to generate a report using reportlab, and the report language is Arabic. but the problem is reportlab doesn't support BIDI (Bidirection) Display because of the lack BIDI Algorithm support in Python. after alot of googling I found that there is a wrapper around Gnome Fribidi called PyFribidi. but it compiled and runs only on Linux, I tried to build it on windows using mingwin but the compilation fails because a lot of linux libs not found.

My question is, is there any Unicode bi-direction algorithm implementation in python, that runs on windows?

thanks.

MBarsi
  • 2,417
  • 1
  • 18
  • 18

4 Answers4

4

Python BiDi is a great BiDi algorithm implementation, but it just support bi-direction (As Is) without fixing the contextual form of arabic script, to solve contextual form problem, you should use python-bidi module with an arabic reshaper library called python-arabic-reshaper.

example : (from => http://mpcabd.igeex.biz/python-arabic-text-reshaper/)

import arabic_reshaper
from bidi.algorithm import get_display

#...
reshaped_text = arabic_reshaper.reshape(u'اللغة العربية رائعة')
bidi_text = get_display(reshaped_text)
pass_arabic_text_to_render(bidi_text)
#...

it fixes my problem perfectly, and both packages are pure python implementation.

MBarsi
  • 2,417
  • 1
  • 18
  • 18
2

In the meantime I implemented Arabic shaping in Python:

https://github.com/behdad/pyarabicshaping

behdad
  • 346
  • 1
  • 4
1

Here is another pure Python implementation of the Unicode bidi algorithm: http://code.google.com/p/pybidi/

behdad
  • 346
  • 1
  • 4
1

python-bidi http://pypi.python.org/pypi/python-bidi/ is a pure python API so presumably it should work fine on windows.

You need to use the RL branch of reportlab and changes any calls to pyfribidi with calls to python-bidi. This link might help http://code.pediapress.com/wiki/wiki/RightToLeft

Meitham
  • 9,178
  • 5
  • 34
  • 45
  • python-bidi is a great solution, I tried it before, it's perfect for hebrew, but arabic script needs special care about the char shape accourding to its position in the word. for optimum solution i found it after more than a year, please look at my answer=> http://en.wikipedia.org/wiki/Arabic_script_in_Unicode#Contextual_forms – MBarsi Sep 28 '12 at 21:19
  • python-bidi only reverse the characters if needed. it won't do the job for Arabic or Persian languages. the actual problem is explained with pictures in [this link](https://github.com/mpcabd/python-arabic-reshaper) – Shamim Oct 23 '18 at 09:48