-
-
Notifications
You must be signed in to change notification settings - Fork 8k
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
base: text-overhaul
Are you sure you want to change the base?
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
@@ -43,7 +43,7 @@ def warn_on_missing_glyph(codepoint, fontnames): | |||
f"Matplotlib currently does not support {block} natively.") | |||
|
|||
|
|||
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
Rebased on the text-overhaul branch and the failures should be fixed with the preloading from #30231. |
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.
Thanks for parameterizing all the things!
|
||
Parameters | ||
---------- | ||
language : str or None |
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.
language : str or None | |
language : str or list or tuple or None |
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 believe we decided not to document the split version yet until we figure out the multiline work.
Since #30000 is almost merged, I've rebased on top of that, and added the libraqm implementation, so the docs now correctly show the change and there are working tests. |
src/ft2font.cpp
Outdated
@@ -361,6 +363,17 @@ void FT2Font::set_text( | |||
throw std::runtime_error("failed to set text flags for layout"); | |||
} | |||
|
|||
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
a138fb2
to
6fc2dee
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. |
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:
language
parameter attached toText
, and any other API that wraps it (i.e.,Axes.text
orAxes.annotate
)language
parameter in backend'sRenderer.draw_text
At 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