-
-
Notifications
You must be signed in to change notification settings - Fork 8.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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
re: adding language to draw_text: the general discussion about extensibility of renderer API applies, i.e.
|
|
Side point regarding allowing |
|
In the call a couple weeks ago, we decided to drop the new However, one followup is that |
lib/matplotlib/_text_helpers.py
Outdated
|
|
||
|
|
||
| def layout(string, font, *, kern_mode=Kerning.DEFAULT): | ||
| def layout(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)
3c188df to
931423b
Compare
src/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.
1858a56 to
6d35c9a
Compare
6fc2dee to
6ef55ed
Compare
|
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 to
886bf64
Compare
0485aee to
3ffce36
Compare
| 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', |
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', |
|
It looks like the appveyor tests hung. |
3ffce36 to
7ce8eae
Compare
|
OK, I fixed the doc note, and moved the test image to the |
PR summary
Along with #29695, this language 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 about the 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