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

Skip to content

Commit 40d697a

Browse files
committed
Correctly size non-ASCII characters in agg backend.
load_char does not resize the buffer, set_text does.
1 parent 602db5a commit 40d697a

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
@@ -175,12 +175,9 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
175175

176176
if font is None:
177177
return None
178-
if len(s) == 1 and ord(s) > 127:
179-
font.load_char(ord(s), flags=flags)
180-
else:
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)
178+
# We pass '0' for angle here, since it will be rotated (in raster
179+
# space) in the following call to draw_text_image).
180+
font.set_text(s, 0, flags=flags)
184181
font.draw_glyphs_to_bitmap(antialiased=rcParams['text.antialiased'])
185182
d = font.get_descent() / 64.0
186183
# 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)