@@ -841,7 +841,7 @@ def _print_ps(
841
841
if papertype is None :
842
842
papertype = mpl .rcParams ['ps.papersize' ]
843
843
papertype = papertype .lower ()
844
- _api .check_in_list (['auto' , * papersize ], papertype = papertype )
844
+ _api .check_in_list (['figure' , ' auto' , * papersize ], papertype = papertype )
845
845
846
846
orientation = _api .check_getitem (
847
847
_Orientation , orientation = orientation .lower ())
@@ -873,24 +873,16 @@ def _print_figure(
873
873
width , height = self .figure .get_size_inches ()
874
874
if papertype == 'auto' :
875
875
_api .warn_deprecated ("3.8" , name = "papertype='auto'" ,
876
- addendum = "Pass an explicit paper type, or omit the "
877
- "*papertype* argument entirely." )
876
+ addendum = "Pass an explicit paper type, 'figure', or "
877
+ "omit the *papertype* argument entirely." )
878
878
papertype = _get_papertype (* orientation .swap_if_landscape ((width , height )))
879
879
880
- if is_eps :
880
+ if is_eps or papertype == 'figure' :
881
881
paper_width , paper_height = width , height
882
882
else :
883
883
paper_width , paper_height = orientation .swap_if_landscape (
884
884
papersize [papertype ])
885
885
886
- if mpl .rcParams ['ps.usedistiller' ]:
887
- # distillers improperly clip eps files if pagesize is too small
888
- if width > paper_width or height > paper_height :
889
- papertype = _get_papertype (
890
- * orientation .swap_if_landscape ((width , height )))
891
- paper_width , paper_height = orientation .swap_if_landscape (
892
- papersize [papertype ])
893
-
894
886
# center the figure on the paper
895
887
xo = 72 * 0.5 * (paper_width - width )
896
888
yo = 72 * 0.5 * (paper_height - height )
@@ -921,10 +913,10 @@ def print_figure_impl(fh):
921
913
if is_eps :
922
914
print ("%!PS-Adobe-3.0 EPSF-3.0" , file = fh )
923
915
else :
924
- print (f "%!PS-Adobe-3.0\n "
925
- f"%%DocumentPaperSizes: { papertype } \n "
926
- f"%%Pages: 1 \n " ,
927
- end = " " , file = fh )
916
+ print ("%!PS-Adobe-3.0" , file = fh )
917
+ if papertype != 'figure' :
918
+ print ( f"%%DocumentPaperSizes: { papertype } " , file = fh )
919
+ print ( "%%Pages: 1 " , file = fh )
928
920
print (f"%%LanguageLevel: 3\n "
929
921
f"{ dsc_comments } \n "
930
922
f"%%Orientation: { orientation .name } \n "
@@ -1061,7 +1053,7 @@ def _print_figure_tex(
1061
1053
# set the paper size to the figure size if is_eps. The
1062
1054
# resulting ps file has the given size with correct bounding
1063
1055
# box so that there is no need to call 'pstoeps'
1064
- if is_eps :
1056
+ if is_eps or papertype == 'figure' :
1065
1057
paper_width , paper_height = orientation .swap_if_landscape (
1066
1058
self .figure .get_size_inches ())
1067
1059
else :
@@ -1160,17 +1152,22 @@ def gs_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
1160
1152
"""
1161
1153
1162
1154
if eps :
1163
- paper_option = "-dEPSCrop"
1155
+ paper_option = ["-dEPSCrop" ]
1156
+ elif ptype == "figure" :
1157
+ # The bbox will have its lower-left corner at (0, 0), so upper-right
1158
+ # corner corresponds with paper size.
1159
+ paper_option = [f"-dDEVICEWIDTHPOINTS={ bbox [2 ]} " ,
1160
+ f"-dDEVICEHEIGHTPOINTS={ bbox [3 ]} " ]
1164
1161
else :
1165
- paper_option = "-sPAPERSIZE=%s" % ptype
1162
+ paper_option = [ f "-sPAPERSIZE={ ptype } " ]
1166
1163
1167
1164
psfile = tmpfile + '.ps'
1168
1165
dpi = mpl .rcParams ['ps.distiller.res' ]
1169
1166
1170
1167
cbook ._check_and_log_subprocess (
1171
1168
[mpl ._get_executable_info ("gs" ).executable ,
1172
1169
"-dBATCH" , "-dNOPAUSE" , "-r%d" % dpi , "-sDEVICE=ps2write" ,
1173
- paper_option , "-sOutputFile=%s" % psfile , tmpfile ],
1170
+ * paper_option , f "-sOutputFile={ psfile } " , tmpfile ],
1174
1171
_log )
1175
1172
1176
1173
os .remove (tmpfile )
@@ -1196,6 +1193,16 @@ def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
1196
1193
mpl ._get_executable_info ("gs" ) # Effectively checks for ps2pdf.
1197
1194
mpl ._get_executable_info ("pdftops" )
1198
1195
1196
+ if eps :
1197
+ paper_option = ["-dEPSCrop" ]
1198
+ elif ptype == "figure" :
1199
+ # The bbox will have its lower-left corner at (0, 0), so upper-right
1200
+ # corner corresponds with paper size.
1201
+ paper_option = [f"-dDEVICEWIDTHPOINTS#{ bbox [2 ]} " ,
1202
+ f"-dDEVICEHEIGHTPOINTS#{ bbox [3 ]} " ]
1203
+ else :
1204
+ paper_option = [f"-sPAPERSIZE#{ ptype } " ]
1205
+
1199
1206
with TemporaryDirectory () as tmpdir :
1200
1207
tmppdf = pathlib .Path (tmpdir , "tmp.pdf" )
1201
1208
tmpps = pathlib .Path (tmpdir , "tmp.ps" )
@@ -1208,7 +1215,7 @@ def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
1208
1215
"-sAutoRotatePages#None" ,
1209
1216
"-sGrayImageFilter#FlateEncode" ,
1210
1217
"-sColorImageFilter#FlateEncode" ,
1211
- "-dEPSCrop" if eps else "-sPAPERSIZE#%s" % ptype ,
1218
+ * paper_option ,
1212
1219
tmpfile , tmppdf ], _log )
1213
1220
cbook ._check_and_log_subprocess (
1214
1221
["pdftops" , "-paper" , "match" , "-level3" , tmppdf , tmpps ], _log )
0 commit comments