Skip to content

Commit 9ffe5d5

Browse files
authored
Merge pull request matplotlib#11891 from anntzer/group-ps-prints
Group some print()s in backend_ps.
2 parents d99714f + d3aef44 commit 9ffe5d5

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

lib/matplotlib/backends/backend_ps.py

+30-25
Original file line numberDiff line numberDiff line change
@@ -1082,10 +1082,12 @@ def print_figure_impl(fh):
10821082
if isEPSF:
10831083
print("%!PS-Adobe-3.0 EPSF-3.0", file=fh)
10841084
else:
1085-
print("%!PS-Adobe-3.0", file=fh)
1085+
print("%!PS-Adobe-3.0\n"
1086+
"%%DocumentPaperSizes: {papertype}\n"
1087+
"%%Pages: 1\n".format(papertype=papertype),
1088+
end="", file=fh)
10861089
if title:
10871090
print("%%Title: " + title, file=fh)
1088-
print("%%Creator: " + creator_str, file=fh)
10891091
# get source date from SOURCE_DATE_EPOCH, if set
10901092
# See https://reproducible-builds.org/specs/source-date-epoch/
10911093
source_date_epoch = os.getenv("SOURCE_DATE_EPOCH")
@@ -1094,14 +1096,14 @@ def print_figure_impl(fh):
10941096
int(source_date_epoch)).strftime("%a %b %d %H:%M:%S %Y")
10951097
else:
10961098
source_date = time.ctime()
1097-
print("%%CreationDate: " + source_date, file=fh)
1098-
print("%%Orientation: " + orientation, file=fh)
1099-
if not isEPSF:
1100-
print("%%DocumentPaperSizes: "+papertype, file=fh)
1101-
print("%%%%BoundingBox: %d %d %d %d" % bbox, file=fh)
1102-
if not isEPSF:
1103-
print("%%Pages: 1", file=fh)
1104-
print("%%EndComments", file=fh)
1099+
print("%%Creator: {creator_str}\n"
1100+
"%%CreationDate: {source_date}\n"
1101+
"%%Orientation: {orientation}\n"
1102+
"%%BoundingBox: {bbox[0]} {bbox[1]} {bbox[2]} {bbox[3]}\n"
1103+
"%%EndComments\n"
1104+
.format(creator_str=creator_str, source_date=source_date,
1105+
orientation=orientation, bbox=bbox),
1106+
end="", file=fh)
11051107

11061108
Ndict = len(psDefs)
11071109
print("%%BeginProlog", file=fh)
@@ -1278,7 +1280,6 @@ def write(self, *kl, **kwargs):
12781280
print("%!PS-Adobe-3.0 EPSF-3.0", file=fh)
12791281
if title:
12801282
print("%%Title: "+title, file=fh)
1281-
print("%%Creator: " + creator_str, file=fh)
12821283
# get source date from SOURCE_DATE_EPOCH, if set
12831284
# See https://reproducible-builds.org/specs/source-date-epoch/
12841285
source_date_epoch = os.getenv("SOURCE_DATE_EPOCH")
@@ -1288,20 +1289,24 @@ def write(self, *kl, **kwargs):
12881289
"%a %b %d %H:%M:%S %Y")
12891290
else:
12901291
source_date = time.ctime()
1291-
print("%%CreationDate: "+source_date, file=fh)
1292-
print("%%%%BoundingBox: %d %d %d %d" % bbox, file=fh)
1293-
print("%%EndComments", file=fh)
1294-
1295-
Ndict = len(psDefs)
1296-
print("%%BeginProlog", file=fh)
1297-
print("/mpldict %d dict def" % Ndict, file=fh)
1298-
print("mpldict begin", file=fh)
1299-
for d in psDefs:
1300-
d = d.strip()
1301-
for l in d.split('\n'):
1302-
print(l.strip(), file=fh)
1303-
print("end", file=fh)
1304-
print("%%EndProlog", file=fh)
1292+
print(
1293+
"%%Creator: {creator_str}\n"
1294+
"%%CreationDate: {source_date}\n"
1295+
"%%BoundingBox: {bbox[0]} {bbox[1]} {bbox[2]} {bbox[3]}\n"
1296+
"%%EndComments\n"
1297+
.format(creator_str=creator_str, source_date=source_date,
1298+
bbox=bbox),
1299+
end="", file=fh)
1300+
1301+
print("%%BeginProlog\n"
1302+
"/mpldict {len_psDefs} dict def\n"
1303+
"mpldict begin\n"
1304+
"{psDefs}\n"
1305+
"end\n"
1306+
"%%EndProlog\n"
1307+
.format(len_psDefs=len(psDefs),
1308+
psDefs="\n".join(psDefs)),
1309+
end="", file=fh)
13051310

13061311
print("mpldict begin", file=fh)
13071312
print("%s translate" % _nums_to_str(xo, yo), file=fh)

0 commit comments

Comments
 (0)