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