Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
QuLogic merged 1 commit intomatplotlib:text-overhaulfromQuLogic:text-language
Sep 20, 2025

Conversation

@QuLogic
Copy link
Member

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:

  1. thelanguage parameter attached toText, and any other API that wraps it (i.e.,Axes.text orAxes.annotate)
  2. thelanguage parameter in backend'sRenderer.draw_text

At the moment, for both, I have set these tostr | 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

@anntzer
Copy link
Contributor

anntzer commentedMar 22, 2025
edited
Loading

re: adding language to draw_text: the general discussion about extensibility of renderer API applies, i.e.

  • if you're going to add language as a parameter to draw_text then it should be at least keyword-only.
  • it's likely that the more maintainable API would likely to just embed language as part of fontproperties (it's not really different from e.g. font features, I'd think) and tell the backend to read that info.
  • for draw_text we have actually more or less given up on having a "clean" renderer API because we pass the whole Text instance to draw_text (perPropagate mpl.text.Text instances to the backends and fix documentation #1081) anyways so perhaps backends that care could also just read that info off the Text instance. It feels a bit dirty, but heh... ("dirty" because we as well may just have a renderer API that'srenderer.draw_text(textobj) to start with...)

@anntzeranntzer mentioned this pull requestMar 22, 2025
5 tasks
@anntzer
Copy link
Contributor

Side point regarding allowinglist[tuple[str, int, int]] as language setting: this may be a problem if one usessomelanguage[idx:] to set the language from an index up to the end of the string (whose length could technically be modified later, even though it's not clear this necessarily makes much practical sense). Likely you needlist[tuple[str, int, int | None]] (and then you may possibly support None (=0) for the start as well).

@QuLogic
Copy link
MemberAuthor

In the call a couple weeks ago, we decided to drop the newlanguage parameter todraw_text, because that already had amtext parameter which contained the wholeText object. This would avoid any signature introspection.

However, one followup is thatRenderer.get_text_width_height_descent wouldalso depend on font features/language settings, and really should get these passed through somehow as well.



deflayout(string,font,*,kern_mode=Kerning.DEFAULT):
deflayout(string,font,language,*,kern_mode=Kerning.DEFAULT):
Copy link
Contributor

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)

@QuLogicQuLogicforce-pushed thetext-language branch 2 times, most recently from3c188df to931423bCompareMay 13, 2025 03:28

if (languages.has_value()) {
for (auto & [lang_str, start, end] : languages.value()) {
if (!raqm_set_language(rq, lang_str.c_str(), start, end)) {
Copy link
MemberAuthor

@QuLogicQuLogicAug 27, 2025
edited
Loading

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.)

Copy link
Contributor

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?

Copy link
MemberAuthor

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.

@QuLogic
Copy link
MemberAuthor

QuLogic commentedSep 3, 2025
edited
Loading

Also extended the tests a bit to ensure that the results are as expected and fixed the fallback to thercParam as well.

The test image is extracted to a separate commit as it should not be merged yet.

@QuLogicQuLogicforce-pushed thetext-language branch 2 times, most recently fromd8051c2 to886bf64CompareSeptember 19, 2025 05:55
@QuLogicQuLogicforce-pushed thetext-language branch 2 times, most recently from0485aee to3ffce36CompareSeptember 19, 2025 06:33
Comment on lines 35 to 36
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',
Copy link
Member

@tacaswelltacaswellSep 19, 2025
edited
Loading

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:

Suggested change
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
Copy link
Member

It looks like the appveyor tests hung.

@QuLogic
Copy link
MemberAuthor

OK, I fixed the doc note, and moved the test image to thetext-overhaul-figures branch in preparation for merging.

@QuLogicQuLogic merged commit44c17bc intomatplotlib:text-overhaulSep 20, 2025
46 of 47 checks passed
@QuLogicQuLogic deleted the text-language branchSeptember 20, 2025 04:13
@github-project-automationgithub-project-automationbot moved this fromReady for Review toDone inFont and text overhaulSep 20, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@anntzeranntzeranntzer left review comments

@tacaswelltacaswelltacaswell approved these changes

@story645story645story645 approved these changes

Assignees

No one assigned

Projects

Status: Done

Milestone

v3.11.0

Development

Successfully merging this pull request may close these issues.

4 participants

@QuLogic@anntzer@tacaswell@story645

[8]ページ先頭

©2009-2025 Movatter.jp