@@ -985,9 +985,9 @@ def print_figure_impl(fh):
985
985
if is_eps :
986
986
print ("%!PS-Adobe-3.0 EPSF-3.0" , file = fh )
987
987
else :
988
- print ("%!PS-Adobe-3.0\n "
989
- "%%DocumentPaperSizes: {papertype}\n "
990
- "%%Pages: 1\n " . format ( papertype = papertype ) ,
988
+ print (f "%!PS-Adobe-3.0\n "
989
+ f "%%DocumentPaperSizes: { papertype } \n "
990
+ f "%%Pages: 1\n " ,
991
991
end = "" , file = fh )
992
992
if title :
993
993
print ("%%Title: " + title , file = fh )
@@ -999,13 +999,11 @@ def print_figure_impl(fh):
999
999
int (source_date_epoch )).strftime ("%a %b %d %H:%M:%S %Y" )
1000
1000
else :
1001
1001
source_date = time .ctime ()
1002
- print ("%%Creator: {creator_str}\n "
1003
- "%%CreationDate: {source_date}\n "
1004
- "%%Orientation: {orientation}\n "
1005
- "%%BoundingBox: {bbox[0]} {bbox[1]} {bbox[2]} {bbox[3]}\n "
1006
- "%%EndComments\n "
1007
- .format (creator_str = creator_str , source_date = source_date ,
1008
- orientation = orientation , bbox = bbox ),
1002
+ print (f"%%Creator: { creator_str } \n "
1003
+ f"%%CreationDate: { source_date } \n "
1004
+ f"%%Orientation: { orientation } \n "
1005
+ f"%%BoundingBox: { bbox [0 ]} { bbox [1 ]} { bbox [2 ]} { bbox [3 ]} \n "
1006
+ f"%%EndComments\n " ,
1009
1007
end = "" , file = fh )
1010
1008
1011
1009
Ndict = len (psDefs )
@@ -1182,51 +1180,37 @@ def write(self, *args, **kwargs):
1182
1180
1183
1181
with TemporaryDirectory () as tmpdir :
1184
1182
tmpfile = os .path .join (tmpdir , "tmp.ps" )
1185
- with open (tmpfile , 'w' , encoding = 'latin-1' ) as fh :
1186
- # write the Encapsulated PostScript headers
1187
- print ("%!PS-Adobe-3.0 EPSF-3.0" , file = fh )
1188
- if title :
1189
- print ("%%Title: " + title , file = fh )
1190
- # get source date from SOURCE_DATE_EPOCH, if set
1191
- # See https://reproducible-builds.org/specs/source-date-epoch/
1192
- source_date_epoch = os .getenv ("SOURCE_DATE_EPOCH" )
1193
- if source_date_epoch :
1194
- source_date = datetime .datetime .utcfromtimestamp (
1195
- int (source_date_epoch )).strftime (
1196
- "%a %b %d %H:%M:%S %Y" )
1197
- else :
1198
- source_date = time .ctime ()
1199
- print (
1200
- "%%Creator: {creator_str}\n "
1201
- "%%CreationDate: {source_date}\n "
1202
- "%%BoundingBox: {bbox[0]} {bbox[1]} {bbox[2]} {bbox[3]}\n "
1203
- "%%EndComments\n "
1204
- .format (creator_str = creator_str , source_date = source_date ,
1205
- bbox = bbox ),
1206
- end = "" , file = fh )
1207
-
1208
- print ("%%BeginProlog\n "
1209
- "/mpldict {len_psDefs} dict def\n "
1210
- "mpldict begin\n "
1211
- "{psDefs}\n "
1212
- "end\n "
1213
- "%%EndProlog\n "
1214
- .format (len_psDefs = len (psDefs ),
1215
- psDefs = "\n " .join (psDefs )),
1216
- end = "" , file = fh )
1217
-
1218
- print ("mpldict begin" , file = fh )
1219
- print ("%s translate" % _nums_to_str (xo , yo ), file = fh )
1220
- print ("%s clipbox" % _nums_to_str (width * 72 , height * 72 , 0 , 0 ),
1221
- file = fh )
1222
-
1223
- # write the figure
1224
- print (self ._pswriter .getvalue (), file = fh )
1225
-
1226
- # write the trailer
1227
- print ("end" , file = fh )
1228
- print ("showpage" , file = fh )
1229
- fh .flush ()
1183
+ # get source date from SOURCE_DATE_EPOCH, if set
1184
+ # See https://reproducible-builds.org/specs/source-date-epoch/
1185
+ source_date_epoch = os .getenv ("SOURCE_DATE_EPOCH" )
1186
+ if source_date_epoch :
1187
+ source_date = datetime .datetime .utcfromtimestamp (
1188
+ int (source_date_epoch )).strftime ("%a %b %d %H:%M:%S %Y" )
1189
+ else :
1190
+ source_date = time .ctime ()
1191
+ pathlib .Path (tmpfile ).write_text (
1192
+ f"""\
1193
+ %!PS-Adobe-3.0 EPSF-3.0
1194
+ { f'''%%Title: { title }
1195
+ ''' if title else "" } \
1196
+ %%Creator: { creator_str }
1197
+ %%CreationDate: { source_date }
1198
+ %%BoundingBox: { bbox [0 ]} { bbox [1 ]} { bbox [2 ]} { bbox [3 ]}
1199
+ %%EndComments
1200
+ %%BeginProlog
1201
+ /mpldict { len (psDefs )} dict def
1202
+ mpldict begin
1203
+ { "" .join (psDefs )}
1204
+ end
1205
+ %%EndProlog
1206
+ mpldict begin
1207
+ { _nums_to_str (xo , yo )} translate
1208
+ { _nums_to_str (width * 72 , height * 72 )} 0 0 clipbox
1209
+ { self ._pswriter .getvalue ()}
1210
+ end
1211
+ showpage
1212
+ """ ,
1213
+ encoding = "latin-1" )
1230
1214
1231
1215
if is_landscape : # now we are ready to rotate
1232
1216
is_landscape = True
0 commit comments