Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
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
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
Specifying text language | ||
------------------------ | ||
OpenType fonts may support language systems which can be used to select different | ||
typographic conventions, e.g., localized variants of letters that share a single Unicode | ||
code point, or different default font features. The text API now supports setting a | ||
language to be used and may be set/get with: | ||
- `matplotlib.text.Text.set_language` / `matplotlib.text.Text.get_language` | ||
- Any API that creates a `.Text` object by passing the *language* argument (e.g., | ||
``plt.xlabel(..., language=...)``) | ||
The language of the text must be in a format accepted by libraqm, namely `a BCP47 | ||
language code <https://www.w3.org/International/articles/language-tags/>`_. If None or | ||
unset, then no particular language will be implied, and default font settings will be | ||
used. | ||
For example, the default font ``DejaVu Sans`` supports language-specific glyphs in the | ||
Serbian and Macedonian languages in the Cyrillic alphabet, or the Sámi family of | ||
languages in the Latin alphabet. | ||
.. plot:: | ||
:include-source: | ||
fig = plt.figure(figsize=(7, 3)) | ||
char = '\U00000431' | ||
fig.text(0.5, 0.8, f'\\U{ord(char):08x}', fontsize=40, horizontalalignment='center') | ||
fig.text(0, 0.6, f'Serbian: {char}', fontsize=40, language='sr') | ||
fig.text(1, 0.6, f'Russian: {char}', fontsize=40, language='ru', | ||
horizontalalignment='right') | ||
char = '\U0000014a' | ||
fig.text(0.5, 0.3, f'\\U{ord(char):08x}', fontsize=40, horizontalalignment='center') | ||
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', | ||
horizontalalignment='right') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -43,7 +43,7 @@ def warn_on_missing_glyph(codepoint, fontnames): | ||
f"Matplotlib currently does not support {block} natively.") | ||
def layout(string, font, *,language=None,kern_mode=Kerning.DEFAULT): | ||
""" | ||
Render *string* with *font*. | ||
@@ -56,6 +56,9 @@ def layout(string, font, *, kern_mode=Kerning.DEFAULT): | ||
The string to be rendered. | ||
font : FT2Font | ||
The font. | ||
language : str or list of tuples of (str, int, int), optional | ||
The language of the text in a format accepted by libraqm, namely `a BCP47 | ||
language code <https://www.w3.org/International/articles/language-tags/>`_. | ||
kern_mode : Kerning | ||
A FreeType kerning mode. | ||
@@ -65,7 +68,7 @@ def layout(string, font, *, kern_mode=Kerning.DEFAULT): | ||
""" | ||
x = 0 | ||
prev_glyph_idx = None | ||
char_to_font = font._get_fontmap(string) # TODO: Pass in language. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Note, this function is getting rewritten with libraqm, so this is just a note for later. | ||
base_font = font | ||
for char in string: | ||
# This has done the fallback logic | ||
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.