@@ -420,14 +420,12 @@ def draw_markers(
420420 if debugPS :
421421 self ._pswriter .write ('% draw_markers \n ' )
422422
423- if rgbFace :
424- if len (rgbFace ) == 4 and rgbFace [3 ] == 0 :
425- ps_color = None
426- else :
427- if rgbFace [0 ] == rgbFace [1 ] == rgbFace [2 ]:
428- ps_color = '%1.3f setgray' % rgbFace [0 ]
429- else :
430- ps_color = '%1.3f %1.3f %1.3f setrgbcolor' % rgbFace [:3 ]
423+ ps_color = (
424+ None
425+ if _is_transparent (rgbFace )
426+ else '%1.3f setgray' % rgbFace [0 ]
427+ if rgbFace [0 ] == rgbFace [1 ] == rgbFace [2 ]
428+ else '%1.3f %1.3f %1.3f setrgbcolor' % rgbFace [:3 ])
431429
432430 # construct the generic marker command:
433431
@@ -562,7 +560,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
562560 if debugPS :
563561 write ("% text\n " )
564562
565- if len (gc .get_rgb ()) == 4 and gc . get_rgb ()[ 3 ] == 0 :
563+ if _is_transparent (gc .get_rgb ()):
566564 return # Special handling for fully transparent.
567565
568566 if ismath == 'TeX' :
@@ -744,10 +742,12 @@ def _draw_ps(self, ps, gc, rgbFace, fill=True, stroke=True, command=None):
744742 write = self ._pswriter .write
745743 if debugPS and command :
746744 write ("% " + command + "\n " )
747- mightstroke = gc .shouldstroke ()
748- stroke = stroke and mightstroke
749- fill = (fill and rgbFace is not None and
750- (len (rgbFace ) <= 3 or rgbFace [3 ] != 0.0 ))
745+ mightstroke = (gc .get_linewidth () > 0
746+ and not _is_transparent (gc .get_rgb ()))
747+ if not mightstroke :
748+ stroke = False
749+ if _is_transparent (rgbFace ):
750+ fill = False
751751 hatch = gc .get_hatch ()
752752
753753 if mightstroke :
@@ -793,6 +793,21 @@ def _draw_ps(self, ps, gc, rgbFace, fill=True, stroke=True, command=None):
793793 write ("grestore\n " )
794794
795795
796+ def _is_transparent (rgb_or_rgba ):
797+ if rgb_or_rgba is None :
798+ return True # Consistent with rgbFace semantics.
799+ elif len (rgb_or_rgba ) == 4 :
800+ if rgb_or_rgba [3 ] == 0 :
801+ return True
802+ if rgb_or_rgba [3 ] != 1 :
803+ _log .warning (
804+ "The PostScript backend does not support transparency; "
805+ "partially transparent artists will be rendered opaque." )
806+ return False
807+ else : # len() == 3.
808+ return False
809+
810+
796811class GraphicsContextPS (GraphicsContextBase ):
797812 def get_capstyle (self ):
798813 return {'butt' : 0 , 'round' : 1 , 'projecting' : 2 }[
@@ -802,6 +817,7 @@ def get_joinstyle(self):
802817 return {'miter' : 0 , 'round' : 1 , 'bevel' : 2 }[
803818 GraphicsContextBase .get_joinstyle (self )]
804819
820+ @cbook .deprecated ("3.1" )
805821 def shouldstroke (self ):
806822 return (self .get_linewidth () > 0.0 and
807823 (len (self .get_rgb ()) <= 3 or self .get_rgb ()[3 ] != 0.0 ))
0 commit comments