diff --git a/lib/matplotlib/tests/baseline_images/test_text/agg_text_clip.png b/lib/matplotlib/tests/baseline_images/test_text/agg_text_clip.png new file mode 100644 index 000000000000..25f47cec6128 Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_text/agg_text_clip.png differ diff --git a/lib/matplotlib/tests/test_text.py b/lib/matplotlib/tests/test_text.py index beddb9edb75a..54492607b304 100644 --- a/lib/matplotlib/tests/test_text.py +++ b/lib/matplotlib/tests/test_text.py @@ -393,3 +393,14 @@ def test_text_stale(): assert not ax1.stale assert not ax2.stale assert not fig.stale + + +@image_comparison(baseline_images=['agg_text_clip'], + extensions=['png']) +def test_agg_text_clip(): + np.random.seed(1) + fig, (ax1, ax2) = plt.subplots(2) + for x, y in np.random.rand(10, 2): + ax1.text(x, y, "foo", clip_on=True) + ax2.text(x, y, "foo") + plt.show() diff --git a/src/_backend_agg.h b/src/_backend_agg.h index a792852a282e..6f6214f482b4 100644 --- a/src/_backend_agg.h +++ b/src/_backend_agg.h @@ -738,14 +738,14 @@ inline void RendererAgg::draw_text_image(GCAgg &gc, ImageArray &image, int x, in typedef agg::renderer_scanline_aa renderer_type; + theRasterizer.reset_clipping(); + rendererBase.reset_clipping(true); if (angle != 0.0) { agg::rendering_buffer srcbuf( image.data(), (unsigned)image.dim(1), (unsigned)image.dim(0), (unsigned)image.dim(1)); agg::pixfmt_gray8 pixf_img(srcbuf); - theRasterizer.reset_clipping(); - rendererBase.reset_clipping(true); set_clipbox(gc.cliprect, theRasterizer); agg::trans_affine mtx; @@ -786,9 +786,9 @@ inline void RendererAgg::draw_text_image(GCAgg &gc, ImageArray &image, int x, in agg::rect_i clip; clip.init(int(mpl_round(gc.cliprect.x1)), - int(mpl_round(gc.cliprect.y1)), + int(mpl_round(height - gc.cliprect.y2)), int(mpl_round(gc.cliprect.x2)), - int(mpl_round(gc.cliprect.y2))); + int(mpl_round(height - gc.cliprect.y1))); text.clip(clip); }