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

Skip to content

Commit f1c50ac

Browse files
timhoffmMeeseeksDev[bot]
authored and
MeeseeksDev[bot]
committed
Backport PR #14705: Correctly size non-ASCII characters in agg backend.
1 parent 3c578f6 commit f1c50ac

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

lib/matplotlib/backends/backend_agg.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,9 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
178178

179179
if font is None:
180180
return None
181-
if len(s) == 1 and ord(s) > 127:
182-
font.load_char(ord(s), flags=flags)
183-
else:
184-
# We pass '0' for angle here, since it will be rotated (in raster
185-
# space) in the following call to draw_text_image).
186-
font.set_text(s, 0, flags=flags)
181+
# We pass '0' for angle here, since it will be rotated (in raster
182+
# space) in the following call to draw_text_image).
183+
font.set_text(s, 0, flags=flags)
187184
font.draw_glyphs_to_bitmap(antialiased=rcParams['text.antialiased'])
188185
d = font.get_descent() / 64.0
189186
# The descent needs to be adjusted for the angle.

lib/matplotlib/tests/test_text.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from matplotlib.backend_bases import MouseEvent
1010
import matplotlib.patches as mpatches
1111
import matplotlib.pyplot as plt
12-
from matplotlib.testing.decorators import image_comparison
12+
from matplotlib.testing.decorators import check_figures_equal, image_comparison
1313

1414

1515
needs_usetex = pytest.mark.skipif(
@@ -621,3 +621,17 @@ def test_wrap_no_wrap():
621621
text = fig.text(0, 0, 'non wrapped text', wrap=True)
622622
fig.canvas.draw()
623623
assert text._get_wrapped_text() == 'non wrapped text'
624+
625+
626+
@check_figures_equal(extensions=["png"])
627+
def test_buffer_size(fig_test, fig_ref):
628+
# On old versions of the Agg renderer, large non-ascii single-character
629+
# strings (here, "€") would be rendered clipped because the rendering
630+
# buffer would be set by the physical size of the smaller "a" character.
631+
ax = fig_test.add_subplot()
632+
ax.set_yticks([0, 1])
633+
ax.set_yticklabels(["€", "a"])
634+
ax.yaxis.majorTicks[1].label1.set_color("w")
635+
ax = fig_ref.add_subplot()
636+
ax.set_yticks([0, 1])
637+
ax.set_yticklabels(["€", ""])

0 commit comments

Comments
 (0)