8000 Clip text when using clip_path in AGG by ronnh · Pull Request #10811 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Clip text when using clip_path in AGG #10811

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

Closed
wants to merge 2 commits into from

Conversation

ronnh
Copy link
@ronnh ronnh commented Mar 16, 2018

PR Summary

In response to issue #8270
Added a partial fix for when the text is not clipped.
When the text is being rendered, inside _backend_agg.h the draw_text_image function is not handling whether the text need to be clipped or not. Thus we added a condition to check. Currently if it needs to be clipped it will be rendered as an image.
Currently a clippath cannot be initialized together with the text because there is a separate where the clippath is not being passed properly.
With this fix a clippath can be added like this.

import numpy as np
import matplotlib as mpl
from matplotlib import pyplot as plt

plt.figure(figsize=(8,8))
ax = plt.gca()

poly = mpl.patches.Polygon([[1,0], [0,1], [-1,0], [0,-1]], 
                           facecolor="#ddffdd", edgecolor="#00ff00", linewidth=2, alpha=0.5)

ax.add_patch(poly)

# add a text into the axes with clip path which should not be displayed
txt_outside = mpl.text.Text(0.65,0.85,"outside 1", clip_on=True, clip_path=poly)
ax.add_artist(txt_outside)
txt_outside.set_clip_path(poly)

ax.set_xlim(-1,1)
ax.set_ylim(-1,1)
plt.show()

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@jklymak
Copy link
Member
jklymak commented Mar 16, 2018

Thanks for the PR!

Can this get a descriptive title that does not refer to the issue number? But please refer to issue number in the text of the PR. You will get more reviewers if they know what this is about

@tacaswell
Copy link
Member

Does this mean that this clipping was working correctly with pdf / svg / eps / cairo backends?

Any idea what is going wrong with the tests? The "gw3] node down: Not properly terminated" warnings make me concerned that there is a segfault or similar introduced by this change.

Good job chasing this down to the Agg level!

@tacaswell tacaswell added this to the v3.0 milestone Mar 16, 2018
@phobson phobson changed the title Iss 8270 bugfix Clip text when using clip_path in AGG Mar 17, 2018
@tacaswell tacaswell modified the milestones: v3.0, v3.1 Jul 7, 2018
@jklymak jklymak modified the milestones: v3.1.0, v3.2.0 Feb 8, 2019
@jklymak
Copy link
Member
jklymak commented Feb 8, 2019

@ronnh, are you planning to come back to this? It'll need a rebase, and will need to pass the tests.

@tacaswell tacaswell modified the milestones: v3.2.0, v3.3.0 Aug 28, 2019
@QuLogic
Copy link
Member
QuLogic commented May 12, 2020

I rebased this, and tried for quite a while to figure out why it was crashing, but right now I don't think this is quite the correct way to do it. It changes the type of the source image in the C code, but not the Python side. But doing that change on the Python side would be quite a far-reaching thing. This needs to be a bit more focused on the scanline rendering part, only.

Since this has not been touched for about 2 years and isn't working, I'm going to close this. Please re-open if you decide to come back to this.

@QuLogic QuLogic closed this May 12, 2020
@QuLogic QuLogic modified the milestones: v3.3.0, unassigned May 12, 2020
@greglucas greglucas mentioned this pull request Mar 4, 2023
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0