@@ -49,6 +49,7 @@ class __getattr__:
49
49
# module-level deprecations
50
50
ps_backend_helper = _api .deprecated ("3.7" , obj_type = "" )(
51
51
property (lambda self : PsBackendHelper ()))
52
+ psDefs = _api .deprecated ("3.8" , obj_type = "" )(property (lambda self : _psDefs ))
52
53
53
54
54
55
papersize = {'letter' : (8.5 , 11 ),
@@ -87,8 +88,8 @@ def _get_papertype(w, h):
87
88
return 'a0'
88
89
89
90
90
- def _nums_to_str (* args ):
91
- return " " .join (f"{ arg :1.3f} " .rstrip ("0" ).rstrip ("." ) for arg in args )
91
+ def _nums_to_str (* args , sep = " " ):
92
+ return sep .join (f"{ arg :1.3f} " .rstrip ("0" ).rstrip ("." ) for arg in args )
92
93
93
94
94
95
def _move_path_to_path_or_stream (src , dst ):
@@ -292,16 +293,16 @@ def _is_transparent(self, rgb_or_rgba):
292
293
293
294
def set_color (self , r , g , b , store = True ):
294
295
if (r , g , b ) != self .color :
295
- self ._pswriter .write (f"{ r :1.3f } setgray\n "
296
+ self ._pswriter .write (f"{ _nums_to_str ( r ) } setgray\n "
296
297
if r == g == b else
297
- f"{ r :1.3f } { g :1.3f } { b :1.3f } setrgbcolor\n " )
298
+ f"{ _nums_to_str ( r , g , b ) } setrgbcolor\n " )
298
299
if store :
299
300
self .color = (r , g , b )
300
301
301
302
def set_linewidth (self , linewidth , store = True ):
302
303
linewidth = float (linewidth )
303
304
if linewidth != self .linewidth :
304
- self ._pswriter .write ("%1.3f setlinewidth\n " % linewidth )
305
+ self ._pswriter .write (f" { _nums_to_str ( linewidth ) } setlinewidth\n " )
305
306
if store :
306
307
self .linewidth = linewidth
307
308
@@ -337,8 +338,7 @@ def set_linedash(self, offset, seq, store=True):
337
338
if np .array_equal (seq , oldseq ) and oldo == offset :
338
339
return
339
340
340
- self ._pswriter .write (f"[{ _nums_to_str (* seq )} ]"
341
- f" { _nums_to_str (offset )} setdash\n "
341
+ self ._pswriter .write (f"[{ _nums_to_str (* seq )} ] { _nums_to_str (offset )} setdash\n "
342
342
if seq is not None and len (seq ) else
343
343
"[] 0 setdash\n " )
344
344
if store :
@@ -406,7 +406,7 @@ def _get_clip_cmd(self, gc):
406
406
clip = []
407
407
rect = gc .get_clip_rectangle ()
408
408
if rect is not None :
409
- clip .append ("%s clipbox \n " % _nums_to_str (* rect .size , * rect .p0 ) )
409
+ clip .append (f" { _nums_to_str (* rect .p0 , * rect .size ) } rectclip \n " )
410
410
path , trf = gc .get_clip_path ()
411
411
if path is not None :
412
412
key = (path , id (trf ))
@@ -473,9 +473,9 @@ def draw_markers(
473
473
ps_color = (
474
474
None
475
475
if self ._is_transparent (rgbFace )
476
- else '%1.3f setgray' % rgbFace [0 ]
476
+ else f' { _nums_to_str ( rgbFace [0 ]) } setgray'
477
477
if rgbFace [0 ] == rgbFace [1 ] == rgbFace [2 ]
478
- else '%1.3f %1.3f %1.3f setrgbcolor' % rgbFace [:3 ])
478
+ else f' { _nums_to_str ( * rgbFace [:3 ]) } setrgbcolor' )
479
479
480
480
# construct the generic marker command:
481
481
@@ -581,7 +581,7 @@ def draw_tex(self, gc, x, y, s, prop, angle, *, mtext=None):
581
581
w , h , bl = self .get_text_width_height_descent (s , prop , ismath = "TeX" )
582
582
fontsize = prop .get_size_in_points ()
583
583
thetext = 'psmarker%d' % self .textcnt
584
- color = '%1.3f,%1.3f,%1.3f' % gc .get_rgb ()[:3 ]
584
+ color = _nums_to_str ( * gc .get_rgb ()[:3 ], sep = ',' )
585
585
fontcmd = {'sans-serif' : r'{\sffamily %s}' ,
586
586
'monospace' : r'{\ttfamily %s}' }.get (
587
587
mpl .rcParams ['font.family' ][0 ], r'{\rmfamily %s}' )
@@ -783,8 +783,8 @@ def _draw_ps(self, ps, gc, rgbFace, *, fill=True, stroke=True):
783
783
if hatch :
784
784
hatch_name = self .create_hatch (hatch )
785
785
write ("gsave\n " )
786
- write ("%f %f %f " % gc .get_hatch_color ()[:3 ])
787
- write ("%s setpattern fill grestore\n " % hatch_name )
786
+ write (_nums_to_str ( * gc .get_hatch_color ()[:3 ]) )
787
+ write (f" { hatch_name } setpattern fill grestore\n " )
788
788
789
789
if stroke :
790
790
write ("stroke\n " )
@@ -914,19 +914,20 @@ def print_figure_impl(fh):
914
914
f"%%DocumentPaperSizes: { papertype } \n "
915
915
f"%%Pages: 1\n " ,
916
916
end = "" , file = fh )
917
- print (f"{ dsc_comments } \n "
917
+ print (f"%%LanguageLevel: 3\n "
918
+ f"{ dsc_comments } \n "
918
919
f"%%Orientation: { orientation .name } \n "
919
920
f"{ get_bbox_header (bbox )[0 ]} \n "
920
921
f"%%EndComments\n " ,
921
922
end = "" , file = fh )
922
923
923
- Ndict = len (psDefs )
924
+ Ndict = len (_psDefs )
924
925
print ("%%BeginProlog" , file = fh )
925
926
if not mpl .rcParams ['ps.useafm' ]:
926
927
Ndict += len (ps_renderer ._character_tracker .used )
927
928
print ("/mpldict %d dict def" % Ndict , file = fh )
928
929
print ("mpldict begin" , file = fh )
929
- print ("\n " .join (psDefs ), file = fh )
930
+ print ("\n " .join (_psDefs ), file = fh )
930
931
if not mpl .rcParams ['ps.useafm' ]:
931
932
for font_path , chars \
932
933
in ps_renderer ._character_tracker .used .items ():
@@ -951,8 +952,7 @@ def print_figure_impl(fh):
951
952
print ("%s translate" % _nums_to_str (xo , yo ), file = fh )
952
953
if rotation :
953
954
print ("%d rotate" % rotation , file = fh )
954
- print ("%s clipbox" % _nums_to_str (width * 72 , height * 72 , 0 , 0 ),
955
- file = fh )
955
+ print (f"0 0 { _nums_to_str (width * 72 , height * 72 )} rectclip" , file = fh )
956
956
957
957
# write the figure
958
958
print (self ._pswriter .getvalue (), file = fh )
@@ -1024,18 +1024,19 @@ def _print_figure_tex(
1024
1024
tmppath .write_text (
1025
1025
f"""\
1026
1026
%!PS-Adobe-3.0 EPSF-3.0
1027
+ %%LanguageLevel: 3
1027
1028
{ dsc_comments }
1028
1029
{ get_bbox_header (bbox )[0 ]}
1029
1030
%%EndComments
1030
1031
%%BeginProlog
1031
- /mpldict { len (psDefs )} dict def
1032
+ /mpldict { len (_psDefs )} dict def
1032
1033
mpldict begin
1033
- { "" .join (psDefs )}
1034
+ { "" .join (_psDefs )}
1034
1035
end
1035
1036
%%EndProlog
1036
1037
mpldict begin
1037
1038
{ _nums_to_str (xo , yo )} translate
1038
- { _nums_to_str (width * 72 , height * 72 )} 0 0 clipbox
1039
+ 0 0 { _nums_to_str (width * 72 , height * 72 )} rectclip
1039
1040
{ self ._pswriter .getvalue ()}
1040
1041
end
1041
1042
showpage
@@ -1196,7 +1197,7 @@ def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
1196
1197
"-dEPSCrop" if eps else "-sPAPERSIZE#%s" % ptype ,
1197
1198
tmpfile , tmppdf ], _log )
1198
1199
cbook ._check_and_log_subprocess (
1199
- ["pdftops" , "-paper" , "match" , "-level2 " , tmppdf , tmpps ], _log )
1200
+ ["pdftops" , "-paper" , "match" , "-level3 " , tmppdf , tmpps ], _log )
1200
1201
shutil .move (tmpps , tmpfile )
1201
1202
if eps :
1202
1203
pstoeps (tmpfile )
@@ -1295,7 +1296,7 @@ def pstoeps(tmpfile, bbox=None, rotated=False):
1295
1296
1296
1297
# The usage comments use the notation of the operator summary
1297
1298
# in the PostScript Language reference manual.
1298
- psDefs = [
1299
+ _psDefs = [
1299
1300
# name proc *_d* -
1300
1301
# Note that this cannot be bound to /d, because when embedding a Type3 font
1301
1302
# we may want to define a "d" glyph using "/d{...} d" which would locally
@@ -1313,20 +1314,6 @@ def pstoeps(tmpfile, bbox=None, rotated=False):
1313
1314
"/cl { closepath } _d" ,
1314
1315
# *ce* -
1315
1316
"/ce { closepath eofill } _d" ,
1316
- # w h x y *box* -
1317
- """/box {
1318
- m
1319
- 1 index 0 r
1320
- 0 exch r
1321
- neg 0 r
1322
- cl
1323
- } _d""" ,
1324
- # w h x y *clipbox* -
1325
- """/clipbox {
1326
- box
1327
- clip
1328
- newpath
1329
- } _d""" ,
1330
1317
# wx wy llx lly urx ury *setcachedevice* -
1331
1318
"/sc { setcachedevice } _d" ,
1332
1319
]
0 commit comments