Warn that pre-shaping corrupts text under the Raqm layout engine - #9925
Open
Syamjith-NK wants to merge 1 commit into
Open
Warn that pre-shaping corrupts text under the Raqm layout engine#9925Syamjith-NK wants to merge 1 commit into
Syamjith-NK wants to merge 1 commit into
Conversation
Running a string through arabic_reshaper + python-bidi before drawing is the standard advice in most tutorials for Arabic with Pillow, and it is correct for Layout.BASIC. Under Layout.RAQM it double-shapes: Pillow already shapes and reorders, so the text renders but is wrong. Which engine is used depends on how Pillow was built, so the same code can be correct on one machine and wrong on another - which is why the pattern persists in projects that no longer need it. Placed in the Layout section rather than on ImageDraw.text because the behaviour is a property of the engine. Refs python-pillow#9907
radarhere
reviewed
Aug 29, 2026
| the reshaped string, so the corruption is written to the database and | ||
| outlives any later fix. It also cannot be undone by mapping the | ||
| presentation forms back, because lam-alef ligatures collapse two | ||
| characters into one glyph. |
Member
There was a problem hiding this comment.
This paragraph doesn't seem optimal to me.
I start reading it and think
Damage? Pillow is doing damage to things beyond the image? What security problem is this?
but you're actually talking about reshaping that has occurred before Pillow enters the picture.
Are you sure we need to spell the problem out in this much detail for users? We've clearly said that they need to do. If they haven't things through with regards to a database, isn't that outside of Pillow's remit?
While I'm no expert on 'mapping the presentation forms back', that's not Pillow functionality. At some point, doesn't this documentation belong in arabic-reshaper or python-bidi instead?
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.
Closes #9907. Alternative to #9914
Running a string through
arabic_reshaper+python-bidibefore drawing is the standard advice in most tutorials for Arabic with Pillow, and it is correct forLayout.BASIC. UnderLayout.RAQMit double-shapes the string: Pillow already shapes and reorders, so the text still renders but is wrong.Because the engine is chosen by how Pillow was built, the same code is correct on one machine and wrong on another — which is why the pattern persists in projects that no longer need it, and why the docs seemed the right place for it.
Two details that made this feel worth documenting rather than leaving to user code:
السلامintoالسالم.Documentation only, no code change. Placed in the
Layoutsection rather than onImageDraw.textbecause the behaviour is a property of the engine rather than of one drawing call.As @akx noted on the issue, #9913 (linking FreeType against the bundled HarfBuzz in the wheels) would widen who is affected — pipelines that are correct today because their Pillow is not shaping would begin to double-shape — so this warning becomes more useful if that lands, not less.