[reportlab-users] Arabic support

386 views
Skip to first unread message

Fran Boon

unread,
Aug 24, 2015, 10:07:06 AM8/24/15
to reportl...@lists2.reportlab.com
I am using the currently released ReportLab (3.2.0) for PDF support
within Sahana ( http://sahanafoundation.org )
All has gone fine until working with Arabic...the font is fine using
Unifont (http://unifoundry.com/pub/unifont-7.0.06/font-builds/unifont-7.0.06.ttf)
however the characters in each word are left-to-right so it's
nonsensical.


I found this old post but the linked page has disappeared:
http://two.pairlist.net/pipermail/reportlab-users/2010-October/009837.html


I found an open Ticket which suggests following up on this mailing list
https://bitbucket.org/rptlab/reportlab/issues/31/arabic-language-not-support-in-reportlab

It mentions a rtl-support patch that was being merged in...what is the
status of that?

This say that we need to use Pyfribidi:
https://pypi.python.org/pypi/pyfribidi/
(Have so far been unable to install this on Windows...downloaded
Visual C++ for Python but it doesn't find the fribidi source:properly:
Cannot open include file: 'fribidi-config.h')


I also found this on StackExchange:
http://stackoverflow.com/questions/8222517/use-of-arabic-rtl-in-reportlab

This says that we can use Python-BiDi:
https://pypi.python.org/pypi/python-bidi

This looks more promising than pyfribidi as it's pure python and easy
to install.
The example code given looks very straightforward too.

(I confess I'm not quite sure what ArabicWriter adds on top of this:
https://github.com/hasenj/arabic-writer/wiki)



Is there a branch of ReportLab with RTL support included that I can
test / contribute to?
Or should I add my own support to our ReportLab routines using Python-BiDi?

Thnaks a lot,
Fran.
_______________________________________________
reportlab-users mailing list
reportl...@lists2.reportlab.com
https://pairlist2.pair.net/mailman/listinfo/reportlab-users

Fran Boon

unread,
Aug 24, 2015, 10:23:48 AM8/24/15
to reportl...@lists2.reportlab.com
On 24 August 2015 at 15:07, Fran Boon <franc...@gmail.com> wrote:
> I am using the currently released ReportLab (3.2.0) for PDF support
> within Sahana ( http://sahanafoundation.org )
> All has gone fine until working with Arabic...the font is fine using
> Unifont (http://unifoundry.com/pub/unifont-7.0.06/font-builds/unifont-7.0.06.ttf)
> however the characters in each word are left-to-right so it's
> nonsensical.

> I found an open Ticket which suggests following up on this mailing list
> https://bitbucket.org/rptlab/reportlab/issues/31/arabic-language-not-support-in-reportlab
> It mentions a rtl-support patch that was being merged in...what is the
> status of that?

I think I found the branch which has this included:
https://bitbucket.org/rptlab/reportlab/src/f0426d8c4e7c1318f5c74181b5907a251ff2f302/?at=rtl-support

The BitBucket site is almost non-functional for me - seems that all
the JS/CSS is being Aborted when it tries to download from
Cloudfront...so I'm not able to do the 'Compare' that is available.

What is the holdup with getting this into the main tree?


> (I confess I'm not quite sure what ArabicWriter adds on top of this:
> https://github.com/hasenj/arabic-writer/wiki)

I now understabnd what this does, an alternative implmentation is here:
http://mpcabd.igeex.biz/python-arabic-text-reshaper/

I got these links from:
http://stackoverflow.com/questions/17166198/arabic-text-is-not-properly-wrapped-in-reportlabs-paragraph-flowable

F

Fran Boon

unread,
Aug 24, 2015, 4:18:38 PM8/24/15
to reportl...@lists2.reportlab.com
On 24 August 2015 at 15:07, Fran Boon <franc...@gmail.com> wrote:
> Is there a branch of ReportLab with RTL support included that I can
> test / contribute to?
> Or should I add my own support to our ReportLab routines using Python-BiDi?

I did the latter for now & it seems to work well enough for my needs :)

https://github.com/flavour/eden/blob/master/modules/s3/s3codecs/pdf.py#L138

Thanks,

Andy Robinson

unread,
Aug 24, 2015, 6:03:10 PM8/24/15
to reportlab-users
Currently, we do not support Arabic or other RTL languages.

To be honest, we need a developer with a need for this, or some
ability to read the language(s), to pick this up and make it work; it
is open source, after all. We had an Arabic-speaking developer long
ago but he moved on. If you are able to help out that would be great.
My colleague who know the most about it, Robin Becker, is away this
week but back on 1st September and can hopefully point you the right
way.

- Andy Robinson
ReportLab


On 24 August 2015 at 15:07, Fran Boon <franc...@gmail.com> wrote:

Robin Becker

unread,
Sep 1, 2015, 8:10:45 AM9/1/15
to reportlab-users
There is some support for RTL in trunk reportlab. In reportlab/rl_settings there
is a variable called rtlSupport (defaults to 0). If set to 1 using one of the
standard override methods then reportlab attempts to import the fribidi
libraries eg in reportlab/pdfgen/textobject.py

from pyfribidi2 import log2vis, ON as DIR_ON, LTR as DIR_LTR, RTL as DIR_RTL

in the _formatText method we are doing this

def _formatText(self, text):
"Generates PDF text output operator(s)"
if log2vis and self.direction in ('LTR','RTL'):
# Use pyfribidi to write the text in the correct visual order.
text = log2vis(text, directionsMap.get(self.direction.upper(),DIR_ON),clean=True)

if the libraries are not installed or cause an error on import you should get a
warning. I have fixed a bug related to the above so some people are using it.
This low level approach to using fribidi is clearly wrong. We should be doing it
at the parsing level, but that is hard since fribidi doesn't seem to allow for
annotated characters ie carrying the colour font boldness etc etc through a call
to log2vis isn't possible.
--
Robin Becker
On 24/08/2015 21:18, Fran Boon wrote:
> On 24 August 2015 at 15:07, Fran Boon <franc...@gmail.com> wrote:
>> Is there a branch of ReportLab with RTL support included that I can
>> test / contribute to?
>> Or should I add my own support to our ReportLab routines using Python-BiDi?
>
> I did the latter for now & it seems to work well enough for my needs :)
>
> https://github.com/flavour/eden/blob/master/modules/s3/s3codecs/pdf.py#L138
>
> Thanks,
> Fran.
.......
Reply all
Reply to author
Forward
0 new messages