Skip to content

Commit 86b1285

Browse files
committed
Deprecate GraphicsContextPS.
The conversion functions (which is the only thing GraphicsContextPS adds) are really internal to the PS format and can be done at the renderer level instead, saving the need for an separate GraphicsContext subclass.
1 parent 48b6327 commit 86b1285

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
GraphicsContextPS
2+
~~~~~~~~~~~~~~~~~
3+
... is deprecated. The PostScript backend now uses `.GraphicsContextBase`.

lib/matplotlib/backends/backend_ps.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,29 @@ def set_linewidth(self, linewidth, store=True):
205205
if store:
206206
self.linewidth = linewidth
207207

208+
@staticmethod
209+
def _linejoin_cmd(linejoin):
210+
# Support for directly passing integer values is for backcompat.
211+
linejoin = {'miter': 0, 'round': 1, 'bevel': 2, 0: 0, 1: 1, 2: 2}[
212+
linejoin]
213+
return f"{linejoin:d} setlinejoin\n"
214+
208215
def set_linejoin(self, linejoin, store=True):
209216
if linejoin != self.linejoin:
210-
self._pswriter.write("%d setlinejoin\n" % linejoin)
217+
self._pswriter.write(self._linejoin_cmd(linejoin))
211218
if store:
212219
self.linejoin = linejoin
213220

221+
@staticmethod
222+
def _linecap_cmd(linecap):
223+
# Support for directly passing integer values is for backcompat.
224+
linecap = {'butt': 0, 'round': 1, 'projecting': 2, 0: 0, 1: 1, 2: 2}[
225+
linecap]
226+
return f"{linecap:d} setlinecap\n"
227+
214228
def set_linecap(self, linecap, store=True):
215229
if linecap != self.linecap:
216-
self._pswriter.write("%d setlinecap\n" % linecap)
230+
self._pswriter.write(self._linecap_cmd(linecap))
217231
if store:
218232
self.linecap = linecap
219233

@@ -397,10 +411,8 @@ def draw_markers(
397411
stroke = lw > 0 and alpha > 0
398412
if stroke:
399413
ps_cmd.append('%.1f setlinewidth' % lw)
400-
jint = gc.get_joinstyle()
401-
ps_cmd.append('%d setlinejoin' % jint)
402-
cint = gc.get_capstyle()
403-
ps_cmd.append('%d setlinecap' % cint)
414+
ps_cmd.append(self._linejoin_cmd(gc.get_joinstyle()))
415+
ps_cmd.append(self._linecap_cmd(gc.get_capstyle()))
404416

405417
ps_cmd.append(self._convert_path(marker_path, marker_trans,
406418
simplify=False))
@@ -595,10 +607,6 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
595607
grestore
596608
""")
597609

598-
def new_gc(self):
599-
# docstring inherited
600-
return GraphicsContextPS()
601-
602610
def draw_mathtext(self, gc, x, y, s, prop, angle):
603611
"""Draw the math text using matplotlib.mathtext."""
604612
if debugPS:
@@ -703,10 +711,8 @@ def _draw_ps(self, ps, gc, rgbFace, fill=True, stroke=True, command=None):
703711

704712
if mightstroke:
705713
self.set_linewidth(gc.get_linewidth())
706-
jint = gc.get_joinstyle()
707-
self.set_linejoin(jint)
708-
cint = gc.get_capstyle()
709-
self.set_linecap(cint)
714+
self.set_linejoin(gc.get_joinstyle())
715+
self.set_linecap(gc.get_capstyle())
710716
self.set_linedash(*gc.get_dashes())
711717
self.set_color(*gc.get_rgb()[:3])
712718
write('gsave\n')
@@ -759,6 +765,7 @@ def _is_transparent(rgb_or_rgba):
759765
return False
760766

761767

768+
@cbook.deprecated("3.4", alternative="GraphicsContextBase")
762769
class GraphicsContextPS(GraphicsContextBase):
763770
def get_capstyle(self):
764771
return {'butt': 0, 'round': 1, 'projecting': 2}[super().get_capstyle()]

0 commit comments

Comments
 (0)