@@ -420,14 +420,12 @@ def draw_markers(
420
420
if debugPS :
421
421
self ._pswriter .write ('% draw_markers \n ' )
422
422
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 ])
431
429
432
430
# construct the generic marker command:
433
431
@@ -562,7 +560,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
562
560
if debugPS :
563
561
write ("% text\n " )
564
562
565
- if len (gc .get_rgb ()) == 4 and gc . get_rgb ()[ 3 ] == 0 :
563
+ if _is_transparent (gc .get_rgb ()):
566
564
return # Special handling for fully transparent.
567
565
568
566
if ismath == 'TeX' :
@@ -744,10 +742,12 @@ def _draw_ps(self, ps, gc, rgbFace, fill=True, stroke=True, command=None):
744
742
write = self ._pswriter .write
745
743
if debugPS and command :
746
744
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
751
751
hatch = gc .get_hatch ()
752
752
753
753
if mightstroke :
@@ -793,6 +793,21 @@ def _draw_ps(self, ps, gc, rgbFace, fill=True, stroke=True, command=None):
793
793
write ("grestore\n " )
794
794
795
795
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
+
796
811
class GraphicsContextPS (GraphicsContextBase ):
797
812
def get_capstyle (self ):
798
813
return {'butt' : 0 , 'round' : 1 , 'projecting' : 2 }[
@@ -802,6 +817,7 @@ def get_joinstyle(self):
802
817
return {'miter' : 0 , 'round' : 1 , 'bevel' : 2 }[
803
818
GraphicsContextBase .get_joinstyle (self )]
804
819
820
+ @cbook .deprecated ("3.1" )
805
821
def shouldstroke (self ):
806
822
return (self .get_linewidth () > 0.0 and
807
823
(len (self .get_rgb ()) <= 3 or self .get_rgb ()[3 ] != 0.0 ))
0 commit comments