@@ -1045,8 +1045,8 @@ def _print_figure_tex(
1045
1045
1046
1046
# write to a temp file, we'll move it to outfile when done
1047
1047
with TemporaryDirectory () as tmpdir :
1048
- tmpfile = os . path . join (tmpdir , "tmp.ps" )
1049
- pathlib . Path ( tmpfile ) .write_text (
1048
+ tmppath = pathlib . Path (tmpdir , "tmp.ps" )
1049
+ tmppath .write_text (
1050
1050
f"""\
1051
1051
%!PS-Adobe-3.0 EPSF-3.0
1052
1052
{ dsc_comments }
@@ -1082,27 +1082,21 @@ def _print_figure_tex(
1082
1082
papertype = _get_papertype (width , height )
1083
1083
paper_width , paper_height = papersize [papertype ]
1084
1084
1085
- texmanager = ps_renderer .get_texmanager ()
1086
- font_preamble = texmanager .get_font_preamble ()
1087
- custom_preamble = texmanager .get_custom_preamble ()
1088
-
1089
- psfrag_rotated = convert_psfrags (tmpfile , ps_renderer .psfrag ,
1090
- font_preamble ,
1091
- custom_preamble , paper_width ,
1092
- paper_height ,
1093
- orientation .name )
1085
+ psfrag_rotated = _convert_psfrags (
1086
+ tmppath , ps_renderer .psfrag , paper_width , paper_height ,
1087
+ orientation .name )
1094
1088
1095
1089
if (mpl .rcParams ['ps.usedistiller' ] == 'ghostscript'
1096
1090
or mpl .rcParams ['text.usetex' ]):
1097
1091
_try_distill (gs_distill ,
1098
- tmpfile , is_eps , ptype = papertype , bbox = bbox ,
1092
+ tmppath , is_eps , ptype = papertype , bbox = bbox ,
1099
1093
rotated = psfrag_rotated )
1100
1094
elif mpl .rcParams ['ps.usedistiller' ] == 'xpdf' :
1101
1095
_try_distill (xpdf_distill ,
1102
- tmpfile , is_eps , ptype = papertype , bbox = bbox ,
1096
+ tmppath , is_eps , ptype = papertype , bbox = bbox ,
1103
1097
rotated = psfrag_rotated )
1104
1098
1105
- _move_path_to_path_or_stream (tmpfile , outfile )
1099
+ _move_path_to_path_or_stream (tmppath , outfile )
1106
1100
1107
1101
print_ps = functools .partialmethod (_print_ps , "ps" )
1108
1102
print_eps = functools .partialmethod (_print_ps , "eps" )
@@ -1112,8 +1106,14 @@ def draw(self):
1112
1106
return super ().draw ()
1113
1107
1114
1108
1109
+ @_api .deprecated ("3.6" )
1115
1110
def convert_psfrags (tmpfile , psfrags , font_preamble , custom_preamble ,
1116
1111
paper_width , paper_height , orientation ):
1112
+ return _convert_psfrags (
1113
+ pathlib .Path (tmpfile ), psfrags , paper_width , paper_height , orientation )
1114
+
1115
+
1116
+ def _convert_psfrags (tmppath , psfrags , paper_width , paper_height , orientation ):
1117
1117
"""
1118
1118
When we want to use the LaTeX backend with postscript, we write PSFrag tags
1119
1119
to a temporary postscript file, each one marking a position for LaTeX to
@@ -1140,15 +1140,15 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble,
1140
1140
% {
1141
1141
"psfrags" : "\n " .join (psfrags ),
1142
1142
"angle" : 90 if orientation == 'landscape' else 0 ,
1143
- "epsfile" : pathlib . Path ( tmpfile ) .resolve ().as_posix (),
1143
+ "epsfile" : tmppath .resolve ().as_posix (),
1144
1144
},
1145
1145
fontsize = 10 ) # tex's default fontsize.
1146
1146
1147
1147
with TemporaryDirectory () as tmpdir :
1148
1148
psfile = os .path .join (tmpdir , "tmp.ps" )
1149
1149
cbook ._check_and_log_subprocess (
1150
1150
['dvips' , '-q' , '-R0' , '-o' , psfile , dvifile ], _log )
1151
- shutil .move (psfile , tmpfile )
1151
+ shutil .move (psfile , tmppath )
1152
1152
1153
1153
# check if the dvips created a ps in landscape paper. Somehow,
1154
1154
# above latex+dvips results in a ps file in a landscape mode for a
@@ -1157,14 +1157,14 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble,
1157
1157
# the generated ps file is in landscape and return this
1158
1158
# information. The return value is used in pstoeps step to recover
1159
1159
# the correct bounding box. 2010-06-05 JJL
1160
- with open (tmpfile ) as fh :
1160
+ with open (tmppath ) as fh :
1161
1161
psfrag_rotated = "Landscape" in fh .read (1000 )
1162
1162
return psfrag_rotated
1163
1163
1164
1164
1165
- def _try_distill (func , * args , ** kwargs ):
1165
+ def _try_distill (func , tmppath , * args , ** kwargs ):
1166
1166
try :
1167
- func (* args , ** kwargs )
1167
+ func (str ( tmppath ), * args , ** kwargs )
1168
1168
except mpl .ExecutableNotFoundError as exc :
1169
1169
_log .warning ("%s. Distillation step skipped." , exc )
1170
1170
0 commit comments