@@ -265,6 +265,21 @@ def __init__(self, width, height, pswriter, imagedpi=72):
265
265
self ._path_collection_id = 0
266
266
267
267
self ._character_tracker = _backend_pdf_ps .CharacterTracker ()
268
+ self ._logwarn_once = functools .lru_cache (None )(_log .warning )
269
+
270
+ def _is_transparent (self , rgb_or_rgba ):
271
+ if rgb_or_rgba is None :
272
+ return True # Consistent with rgbFace semantics.
273
+ elif len (rgb_or_rgba ) == 4 :
274
+ if rgb_or_rgba [3 ] == 0 :
275
+ return True
276
+ if rgb_or_rgba [3 ] != 1 :
277
+ self ._logwarn_once (
278
+ "The PostScript backend does not support transparency; "
279
+ "partially transparent artists will be rendered opaque." )
280
+ return False
281
+ else : # len() == 3.
282
+ return False
268
283
269
284
def set_color (self , r , g , b , store = True ):
270
285
if (r , g , b ) != self .color :
@@ -457,7 +472,7 @@ def draw_markers(
457
472
458
473
ps_color = (
459
474
None
460
- if _is_transparent (rgbFace )
475
+ if self . _is_transparent (rgbFace )
461
476
else '%1.3f setgray' % rgbFace [0 ]
462
477
if rgbFace [0 ] == rgbFace [1 ] == rgbFace [2 ]
463
478
else '%1.3f %1.3f %1.3f setrgbcolor' % rgbFace [:3 ])
@@ -552,7 +567,7 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
552
567
def draw_tex (self , gc , x , y , s , prop , angle , * , mtext = None ):
553
568
# docstring inherited
554
569
if not hasattr (self , "psfrag" ):
555
- _log . warning (
570
+ self . _logwarn_once (
556
571
"The PS backend determines usetex status solely based on "
557
572
"rcParams['text.usetex'] and does not support having "
558
573
"usetex=True only for some elements; this element will thus "
@@ -589,7 +604,7 @@ def draw_tex(self, gc, x, y, s, prop, angle, *, mtext=None):
589
604
def draw_text (self , gc , x , y , s , prop , angle , ismath = False , mtext = None ):
590
605
# docstring inherited
591
606
592
- if _is_transparent (gc .get_rgb ()):
607
+ if self . _is_transparent (gc .get_rgb ()):
593
608
return # Special handling for fully transparent.
594
609
595
610
if ismath == 'TeX' :
@@ -729,10 +744,10 @@ def _draw_ps(self, ps, gc, rgbFace, *, fill=True, stroke=True):
729
744
"""
730
745
write = self ._pswriter .write
731
746
mightstroke = (gc .get_linewidth () > 0
732
- and not _is_transparent (gc .get_rgb ()))
747
+ and not self . _is_transparent (gc .get_rgb ()))
733
748
if not mightstroke :
734
749
stroke = False
735
- if _is_transparent (rgbFace ):
750
+ if self . _is_transparent (rgbFace ):
736
751
fill = False
737
752
hatch = gc .get_hatch ()
738
753
@@ -769,21 +784,6 @@ def _draw_ps(self, ps, gc, rgbFace, *, fill=True, stroke=True):
769
784
write ("grestore\n " )
770
785
771
786
772
- def _is_transparent (rgb_or_rgba ):
773
- if rgb_or_rgba is None :
774
- return True # Consistent with rgbFace semantics.
775
- elif len (rgb_or_rgba ) == 4 :
776
- if rgb_or_rgba [3 ] == 0 :
777
- return True
778
- if rgb_or_rgba [3 ] != 1 :
779
- _log .warning (
780
- "The PostScript backend does not support transparency; "
781
- "partially transparent artists will be rendered opaque." )
782
- return False
783
- else : # len() == 3.
784
- return False
785
-
786
-
787
787
@_api .deprecated ("3.4" , alternative = "GraphicsContextBase" )
788
788
class GraphicsContextPS (GraphicsContextBase ):
789
789
def get_capstyle (self ):
0 commit comments