Skip to content

Draw Arabic recognition results joined and right to left - #5243

Open
DrEssam97 wants to merge 1 commit into
PaddlePaddle:developfrom
DrEssam97:fix/arabic-result-images-develop
Open

DrEssam97 wants to merge 1 commit into
PaddlePaddle:developfrom
DrEssam97:fix/arabic-result-images-develop

Conversation

@DrEssam97

Copy link
Copy Markdown

Fixes #5242

Without Raqm (Pillow's Windows wheels and most slim Docker images), ImageDraw.text draws Arabic letters unjoined and left to right, so the result images of arabic_PP-OCRv3_mobile_rec and arabic_PP-OCRv5_mobile_rec are hard to read even when rec_text is right.

arabic-before-after

Top: ImageDraw.text without Raqm. Bottom: the same text drawn with khatt.

Changes:

  • paddlex/utils/fonts.py: a small draw_text(image, xy, text, font, fill) helper. When the text has Arabic and khatt is installed, khatt shapes and draws it with the same font file and size. Otherwise it calls ImageDraw.text as before, so other languages draw exactly as they do now.
  • TextRecResult._to_img and the OCR pipeline's draw_box_txt_fine use the helper.
  • setup.py: khatt joins the ocr-core and ocr extras next to python-bidi (khatt >= 0.7.1; python_version >= "3.10"). It needs only Pillow, uharfbuzz, freetype-py and python-bidi, so it adds 3 small wheels and no system libraries. Python 3.8 and 3.9 keep the current drawing.
  • The transformers engine now runs get_display on Arabic rec_text, like the Paddle engine does, so both return the same reading order.

Checks:

  • black, isort and flake8 with the versions in .pre-commit-config.yaml.
  • Drawing مرحبا بالعالم (0.98) through the helper matches khatt.draw_text, and Latin text is pixel-identical to ImageDraw.text.

Disclosure: I maintain khatt.

Without Raqm, Pillow's ImageDraw.text draws Arabic letters unjoined and
left to right. When the text has Arabic and khatt is installed, draw it
with khatt instead, in the same font file and size. khatt is added to the
ocr-core and ocr extras next to python-bidi.

The transformers engine now also puts Arabic rec_text in reading order
with get_display, like the Paddle engine.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CLAassistant

CLAassistant commented Nov 11, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants