The standard reshaper+bidi recipe now breaks Arabic on any HarfBuzz stack
arabic_reshaper + python-bidi before drawing is the standard advice for rendering
Arabic in Python. On any renderer that already performs complex-text layout it corrupts
the output.
| the word "welcome" | rendered as |
|---|---|
| correct (no preprocessing) | مرحبا بكم |
| after reshaper + bidi | مكب ابحرم |
Pillow 12 links Raqm/HarfBuzz, so shaping and the bidi reorder already happen. Applying
the recipe makes them happen twice.
3 fonts x 5 strings x 4 rendering paths, scored on shape similarity against a
verified-correct reference:
modern engine, text as-is 15 identical, 0 broken
modern engine + reshaper + bidi 0 identical, 14 broken
no shaping engine, text as-is 0 identical, 15 broken
no shaping engine + reshaper + bidi 9 recognisable, 6 broken
The last row is the part a pass/fail would hide: on a renderer without shaping the
recipe is a PARTIAL rescue. Plain Arabic recovers; digits, embedded Latin and diacritics
still fail, because positioning combining marks and resolving bidirectional runs needs
real shaping regardless of pre-processing.
So the question is not "does Arabic need reshaping" but "does this path already do
complex-text layout" - yes means reshaping breaks it, no means it is required.
Separate trap found in the font tables: SF Arabic and Geeza Pro contain no Latin letters
or digits at all, so في عام 2026 renders the year as .notdef boxes while looking
correct to anyone not reading the number.
Check: PIL.features.check("raqm").
Write-up: https://syamjithnk.com/arabic-text-rendering
Edited: the two Arabic strings were originally on one line either side of an arrow.
The bidi algorithm reorders that, so it read as the broken form producing the correct
one - the very failure this dataset documents. They are in a table now, one per row,
which cannot reorder.
Update: this is now filed upstream with the maintainer, with a README patch.
- Issue: https://github.com/mpcabd/python-arabic-reshaper/issues/102
- PR: https://github.com/mpcabd/python-arabic-reshaper/pull/103
The PR adds the PIL.features.check("raqm") test to the README so readers can tell which of the two cases they are in before following the example.