From ee043fce0ee30ec4108cd9f14f0566448306aa3e Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Thu, 4 Jan 2018 13:11:41 -0800 Subject: [PATCH] Hide fully transparent text in PS output. PS doesn't really support transparency (because the format itself doesn't, unless using some nonstandard extensions), but has some special casing for "fully transparent" (see e.g. "rgbFace is None" check in _draw_ps). Also implement the special-casing for text. --- lib/matplotlib/backends/backend_ps.py | 5 ++++- .../baseline_images/test_backend_ps/empty.pdf | Bin 0 -> 1253 bytes lib/matplotlib/tests/test_backend_ps.py | 9 +++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 lib/matplotlib/tests/baseline_images/test_backend_ps/empty.pdf diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py index 8c247677704a..c2dc1d02463a 100644 --- a/lib/matplotlib/backends/backend_ps.py +++ b/lib/matplotlib/backends/backend_ps.py @@ -631,13 +631,16 @@ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None): def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None): """ - draw a Text instance + Draw a Text instance. """ # local to avoid repeated attribute lookups write = self._pswriter.write if debugPS: write("% text\n") + if len(gc.get_rgb()) == 4 and gc.get_rgb()[3] == 0: + return # Special handling for fully transparent. + if ismath=='TeX': return self.draw_tex(gc, x, y, s, prop, angle) diff --git a/lib/matplotlib/tests/baseline_images/test_backend_ps/empty.pdf b/lib/matplotlib/tests/baseline_images/test_backend_ps/empty.pdf new file mode 100644 index 0000000000000000000000000000000000000000..80a7f0b2fe39532f274fa6f54cf117fe690464fa GIT binary patch literal 1253 zcmaJ>yKWOf6y+gOYyo8i)orXKg6z&dy^f*?V#gr@6w9_qBpzZPV|#hhmIlz z4WdC1@hGT};0vfJ@(~m$9ef3McKu?FSQqO#ntRWkbIxp`R;jM)s-+aZ{(vvv6dedK z|3Fz^2d(C{X&($k>Yz1`5(-+`6JD3KVPiv~aVR&sGX+~ivE2}!pkQT1RTc{{v;Q?u z2+CuygOio-@A?Nc5Kv5; zPsh;-0^?_GEho~-?maRIHrzXq9ShYIsvjGoKMyb<8Myc$KhH|9w%+;ui zGJ#g@qK*|Bun=XxOXIfafG*vs%fi0k)axn3_h$3-%xK=;Bel~DXZ*Nxybm8fJ^B3e z^7mg47j8aQ-@G_^{_)bQ*B9y4cW-~6oIhGf?k_CvU0Yl{*L!)zk}i&Vjr>eGps zwpbcC8gDAJba)Pw-p+y2u{lusHV4Y6jX?BkfHLZ!-HAeJVQOq$Dx4)T3+Hqm{jXwF zM?@^H$Sf{b)(oP%L?@PR8je9$NpXpgr4>ah%YBT)a?cYv~1DD52nB^Si$SmYB6LrpE#6jP4nCZ@Q z7~~(b81wsz`ph{5_o6Q4=?7^iZZSxW#+y`UOy(oKRgLHwMZvP0;c<~lSki5!P}th7 GDt`bTk5eW9 literal 0 HcmV?d00001 diff --git a/lib/matplotlib/tests/test_backend_ps.py b/lib/matplotlib/tests/test_backend_ps.py index fcac2539424c..0d86b32bd9b7 100644 --- a/lib/matplotlib/tests/test_backend_ps.py +++ b/lib/matplotlib/tests/test_backend_ps.py @@ -12,6 +12,7 @@ import matplotlib import matplotlib.pyplot as plt from matplotlib import patheffects +from matplotlib.testing.decorators import image_comparison from matplotlib.testing.determinism import (_determinism_source_date_epoch, _determinism_check) @@ -148,3 +149,11 @@ def test_determinism_all(): def test_determinism_all_tex(): """Test for reproducible PS/tex output""" _determinism_check(format="ps", usetex=True) + + +@image_comparison(baseline_images=["empty"], extensions=["eps"]) +def test_transparency(): + fig, ax = plt.subplots() + ax.set_axis_off() + ax.plot([0, 1], color="r", alpha=0) + ax.text(.5, .5, "foo", color="r", alpha=0)