Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
Add language parameter to Text objects#29794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
anntzer commentedMar 22, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
re: adding language to draw_text: the general discussion about extensibility of renderer API applies, i.e.
|
anntzer commentedMar 28, 2025
Side point regarding allowing |
QuLogic commentedApr 16, 2025
In the call a couple weeks ago, we decided to drop the new However, one followup is that |
Uh oh!
There was an error while loading.Please reload this page.
lib/matplotlib/_text_helpers.py Outdated
| deflayout(string,font,*,kern_mode=Kerning.DEFAULT): | ||
| deflayout(string,font,language,*,kern_mode=Kerning.DEFAULT): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
These params should be kwonly? (throughout most of the PR, I think)
Uh oh!
There was an error while loading.Please reload this page.
3c188df to931423bComparesrc/ft2font.cpp Outdated
| if (languages.has_value()) { | ||
| for (auto & [lang_str, start, end] : languages.value()) { | ||
| if (!raqm_set_language(rq, lang_str.c_str(), start, end)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This function actually takes a length, not an end location; I'm not sure which one we should accept (Harfbuzz feature tags use start/end, so maybe that?), but I'll have to update this to the correct naming (the test is setup to match what libraqm says, but the docs say the opposite.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
start-stop looks normal as API to me?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I agree and have made that change.
6fc2dee to6ef55edCompareQuLogic commentedSep 3, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Also extended the tests a bit to ensure that the results are as expected and fixed the fallback to the The test image is extracted to a separate commit as it should not be merged yet. |
d8051c2 to886bf64Compare0485aee to3ffce36Compare| fig.text(0, 0.1, f'English: {char}', fontsize=40, language='en') | ||
| fig.text(1, 0.1, f'Inari Sámi: {char}', fontsize=40, language='smn', |
tacaswellSep 19, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Super picky change to match the example ordering to the text ordering:
| fig.text(0, 0.1, f'English: {char}', fontsize=40, language='en') | |
| fig.text(1, 0.1, f'Inari Sámi: {char}', fontsize=40, language='smn', | |
| fig.text(0, 0.1, f'Inari Sámi: {char}', fontsize=40, language='smn') | |
| fig.text(1, 0.1, f'English: {char}', fontsize=40, language='en', |
tacaswell commentedSep 19, 2025
It looks like the appveyor tests hung. |
QuLogic commentedSep 20, 2025
OK, I fixed the doc note, and moved the test image to the |
44c17bc intomatplotlib:text-overhaulUh oh!
There was an error while loading.Please reload this page.
PR summary
Along with#29695, thislanguage parameter is an additional setting that may affect text layout. As with the other PR, this is not complete, but rather something to get the API decided upon (and likely will be rebased on raqm PR after it's done.)
There are two parts to the API:
languageparameter attached toText, and any other API that wraps it (i.e.,Axes.textorAxes.annotate)languageparameter in backend'sRenderer.draw_textAt the moment, for both, I have set these to
str | list[tuple[str, int, int]]where the latter denotes a list of (language, start, end)-tuples. However, this was before I found out aboutthe font feature machinery, and it is possible that we may wish to use that syntax instead, at least for API part 1. For part 2, it's a little nicer to have the explicit types, just for passing to the FT2Font extension, but this may not be relevant to other implementations.PR checklist