Repository navigation
Conversation
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>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5242
Without Raqm (Pillow's Windows wheels and most slim Docker images),
ImageDraw.textdraws Arabic letters unjoined and left to right, so the result images ofarabic_PP-OCRv3_mobile_recandarabic_PP-OCRv5_mobile_recare hard to read even whenrec_textis right.Top:
ImageDraw.textwithout Raqm. Bottom: the same text drawn with khatt.Changes:
paddlex/utils/fonts.py: a smalldraw_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 callsImageDraw.textas before, so other languages draw exactly as they do now.TextRecResult._to_imgand the OCR pipeline'sdraw_box_txt_fineuse the helper.setup.py: khatt joins theocr-coreandocrextras 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.get_displayon Arabicrec_text, like the Paddle engine does, so both return the same reading order.Checks:
.pre-commit-config.yaml.مرحبا بالعالم (0.98)through the helper matcheskhatt.draw_text, and Latin text is pixel-identical toImageDraw.text.Disclosure: I maintain khatt.