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

Skip to content

Commit df9223f

Browse files
authored
Merge pull request #18687 from anntzer/psgc
Deprecate GraphicsContextPS.
2 parents 06567e0 + 86b1285 commit df9223f

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
@@ -285,15 +285,29 @@ def set_linewidth(self, linewidth, store=True):
285285
if store:
286286
self.linewidth = linewidth
287287

288+
@staticmethod
289+
def _linejoin_cmd(linejoin):
290+
# Support for directly passing integer values is for backcompat.
291+
linejoin = {'miter': 0, 'round': 1, 'bevel': 2, 0: 0, 1: 1, 2: 2}[
292+
linejoin]
293+
return f"{linejoin:d} setlinejoin\n"
294+
288295
def set_linejoin(self, linejoin, store=True):
289296
if linejoin != self.linejoin:
290-
self._pswriter.write("%d setlinejoin\n" % linejoin)
297+
self._pswriter.write(self._linejoin_cmd(linejoin))
291298
if store:
292299
self.linejoin = linejoin
293300

301+
@staticmethod
302+
def _linecap_cmd(linecap):
303+
# Support for directly passing integer values is for backcompat.
304+
linecap = {'butt': 0, 'round': 1, 'projecting': 2, 0: 0, 1: 1, 2: 2}[
305+
linecap]
306+
return f"{linecap:d} setlinecap\n"
307+
294308
def set_linecap(self, linecap, store=True):
295309
if linecap != self.linecap:
296-
self._pswriter.write("%d setlinecap\n" % linecap)
310+
self._pswriter.write(self._linecap_cmd(linecap))
297311
if store:
298312
self.linecap = linecap
299313

@@ -477,10 +491,8 @@ def draw_markers(
477491
stroke = lw > 0 and alpha > 0
478492
if stroke:
479493
ps_cmd.append('%.1f setlinewidth' % lw)
480-
jint = gc.get_joinstyle()
481-
ps_cmd.append('%d setlinejoin' % jint)
482-
cint = gc.get_capstyle()
483-
ps_cmd.append('%d setlinecap' % cint)
494+
ps_cmd.append(self._linejoin_cmd(gc.get_joinstyle()))
495+
ps_cmd.append(self._linecap_cmd(gc.get_capstyle()))
484496

485497
ps_cmd.append(self._convert_path(marker_path, marker_trans,
486498
simplify=False))
@@ -675,10 +687,6 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
675687
grestore
676688
""")
677689

678-
def new_gc(self):
679-
# docstring inherited
680-
return GraphicsContextPS()
681-
682690
def draw_mathtext(self, gc, x, y, s, prop, angle):
683691
"""Draw the math text using matplotlib.mathtext."""
684692
if debugPS:
@@ -783,10 +791,8 @@ def _draw_ps(self, ps, gc, rgbFace, fill=True, stroke=True, command=None):
783791

784792
if mightstroke:
785793
self.set_linewidth(gc.get_linewidth())
786-
jint = gc.get_joinstyle()
787-
self.set_linejoin(jint)
788-
cint = gc.get_capstyle()
789-
self.set_linecap(cint)
794+
self.set_linejoin(gc.get_joinstyle())
795+
self.set_linecap(gc.get_capstyle())
790796
self.set_linedash(*gc.get_dashes())
791797
self.set_color(*gc.get_rgb()[:3])
792798
write('gsave\n')
@@ -839,6 +845,7 @@ def _is_transparent(rgb_or_rgba):
839845
return False
840846

841847

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

0 commit comments

Comments
 (0)