Repository navigation
ENH: Add paragraph direction to FT2Font layout - #32563
msarmadsohail wants to merge 1 commit into
Conversation
Add an ft2font.Direction enum and a direction argument to FT2Font.set_text and _layout, passed on to raqm_set_par_direction. Without it, right-to-left text that starts with a Latin word is laid out left-to-right, e.g. an Urdu or Arabic sentence that opens with an English name ends up with its words and punctuation in the wrong order. Direction is also part of the layout cache key, so cached results are not reused across directions. See matplotlib#32511.
|
Thank you for opening your first PR into Matplotlib! If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. We also ask that you please finish addressing any review comments on this PR and wait for it to be merged (or closed) before opening a new one, as it can be a valuable learning experience to go through the review process. You can also join us on discourse chat for real-time discussion. For details on testing, writing docs, and our review process, please see the developer guide. We strive to be a welcoming and open project. Please follow our Code of Conduct. |
PR summary
Part of #32511.
Matplotlib never tells libraqm the paragraph direction, so libraqm guesses it from the first
letter with a strong direction. An Urdu or Arabic sentence that starts with an English word,
is then laid out left-to-right and its words and punctuation come out in the wrong order.
This PR does the low-level part we agreed on in the issue:
ft2font.Directionenum (DEFAULT,LTR,RTL,TTB) that maps toraqm_direction_tdirectionargument onFT2Font.set_textandFT2Font._layout, passed toraqm_set_par_directionfor right-to-left
The new test
test_layout_directionlays out "Python اردو" and "اردو Python" with each directionand checks which side the English word ends up on.
AI Disclosure
I used Claude to explain the relevant code to me.
Wrote the the C++ changes and the test cases, following the approach from the issue discussion.
Ran the following tests locally:
PR quality check