Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Backport PR #14705 on branch v3.2.x (Correctly size non-ASCII characters in agg backend.) #15577

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions lib/matplotlib/backends/backend_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,9 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):

if font is None:
return None
if len(s) == 1 and ord(s) > 127:
font.load_char(ord(s), flags=flags)
else:
# We pass '0' for angle here, since it will be rotated (in raster
# space) in the following call to draw_text_image).
font.set_text(s, 0, flags=flags)
# We pass '0' for angle here, since it will be rotated (in raster
# space) in the following call to draw_text_image).
font.set_text(s, 0, flags=flags)
font.draw_glyphs_to_bitmap(antialiased=rcParams['text.antialiased'])
d = font.get_descent() / 64.0
# The descent needs to be adjusted for the angle.
Expand Down
16 changes: 15 additions & 1 deletion lib/matplotlib/tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from matplotlib.backend_bases import MouseEvent
import matplotlib.patches as mpatches
import matplotlib.pyplot as plt
from matplotlib.testing.decorators import image_comparison
from matplotlib.testing.decorators import check_figures_equal, image_comparison


needs_usetex = pytest.mark.skipif(
Expand Down Expand Up @@ -621,3 +621,17 @@ def test_wrap_no_wrap():
text = fig.text(0, 0, 'non wrapped text', wrap=True)
fig.canvas.draw()
assert text._get_wrapped_text() == 'non wrapped text'


@check_figures_equal(extensions=["png"])
def test_buffer_size(fig_test, fig_ref):
# On old versions of the Agg renderer, large non-ascii single-character
# strings (here, "€") would be rendered clipped because the rendering
# buffer would be set by the physical size of the smaller "a" character.
ax = fig_test.add_subplot()
ax.set_yticks([0, 1])
ax.set_yticklabels(["€", "a"])
ax.yaxis.majorTicks[1].label1.set_color("w")
ax = fig_ref.add_subplot()
ax.set_yticks([0, 1])
ax.set_yticklabels(["€", ""])