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

Skip to content

Commit ba83035

Browse files
authored
Merge pull request #7003 from mdboom/clipping-text
FIX: text clipping rectangle needs to be inverted Closes #6794
2 parents 0e03ff2 + 3a51240 commit ba83035

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

lib/matplotlib/tests/test_text.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,3 +393,14 @@ def test_text_stale():
393393
assert not ax1.stale
394394
assert not ax2.stale
395395
assert not fig.stale
396+
397+
398+
@image_comparison(baseline_images=['agg_text_clip'],
399+
extensions=['png'])
400+
def test_agg_text_clip():
401+
np.random.seed(1)
402+
fig, (ax1, ax2) = plt.subplots(2)
403+
for x, y in np.random.rand(10, 2):
404+
ax1.text(x, y, "foo", clip_on=True)
405+
ax2.text(x, y, "foo")
406+
plt.show()

src/_backend_agg.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -738,14 +738,14 @@ inline void RendererAgg::draw_text_image(GCAgg &gc, ImageArray &image, int x, in
738738
typedef agg::renderer_scanline_aa<renderer_base, color_span_alloc_type, span_gen_type>
739739
renderer_type;
740740

741+
theRasterizer.reset_clipping();
742+
rendererBase.reset_clipping(true);
741743
if (angle != 0.0) {
742744
agg::rendering_buffer srcbuf(
743745
image.data(), (unsigned)image.dim(1),
744746
(unsigned)image.dim(0), (unsigned)image.dim(1));
745747
agg::pixfmt_gray8 pixf_img(srcbuf);
746748

747-
theRasterizer.reset_clipping();
748-
rendererBase.reset_clipping(true);
749749
set_clipbox(gc.cliprect, theRasterizer);
750750

751751
agg::trans_affine mtx;
@@ -786,9 +786,9 @@ inline void RendererAgg::draw_text_image(GCAgg &gc, ImageArray &image, int x, in
786786
agg::rect_i clip;
787787

788788
clip.init(int(mpl_round(gc.cliprect.x1)),
789-
int(mpl_round(gc.cliprect.y1)),
789+
int(mpl_round(height - gc.cliprect.y2)),
790790
int(mpl_round(gc.cliprect.x2)),
791-
int(mpl_round(gc.cliprect.y2)));
791+
int(mpl_round(height - gc.cliprect.y1)));
792792
text.clip(clip);
793793
}
794794

0 commit comments

Comments
 (0)