GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ENH: Add paragraph direction to FT2Font layout by msarmadsohail · Pull Request #32563 · matplotlib/matplotlib

Conversation

@msarmadsohail

@msarmadsohail msarmadsohail commented Oct 31, 2026

Copy link
Copy Markdown

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:

  • a new ft2font.Direction enum (DEFAULT, LTR, RTL, TTB) that maps to raqm_direction_t
  • a direction argument on FT2Font.set_text and FT2Font._layout, passed to
    raqm_set_par_direction
  • the direction is part of the layout cache key, so a cached left-to-right layout is not reused
    for right-to-left

The new test test_layout_direction lays out "Python اردو" and "اردو Python" with each direction
and 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:

  • test_ft2font, test_text, mathtext and the agg
  • pdf, ps and svg backend tests

PR quality check

  • Use an expressive title
  • New and changed code is tested
  • Plotting related features are demonstrated in an example -> N/A for now, will add with the Text API
  • New features and API changes have release notes -> N/A for now, will add with the Text API
  • Documentation complies with general and docstring guidelines

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@msarmadsohail
ENH: Add paragraph direction to FT2Font layout
7cbb7d9
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.
@github-actions github-actions Bot added the topic: text/fonts label Oct 31, 2026
@github-actions

github-actions Bot commented Oct 31, 2026

Copy link
Copy Markdown

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.
Please let us know if (and how) you use AI, it will help us give you better feedback on your PR.

We strive to be a welcoming and open project. Please follow our Code of Conduct.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the first-contribution label Oct 31, 2026

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

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

first-contribution topic: text/fonts

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@msarmadsohail
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.