Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b061cc0

Browse files
anntzerissamarabi
authored andcommitted
Deprecate backend_ps.get_bbox_header, and split it for internal use.
It's clearly an internal helper, and the two parts (the actual bbox header and the rotation command) don't really benefit from being smushed together, so make the function private and split the two parts.
1 parent b1bd86c commit b061cc0

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``backend_ps.get_bbox_header``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
... is deprecated, as it is considered an internal helper.

lib/matplotlib/backends/backend_ps.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from io import StringIO
1010
import itertools
1111
import logging
12+
import math
1213
import os
1314
import pathlib
1415
import shutil
@@ -904,7 +905,7 @@ def print_figure_impl(fh):
904905
print(f"%%LanguageLevel: 3\n"
905906
f"{dsc_comments}\n"
906907
f"%%Orientation: {orientation.name}\n"
907-
f"{get_bbox_header(bbox)[0]}\n"
908+
f"{_get_bbox_header(bbox)}\n"
908909
f"%%EndComments\n",
909910
end="", file=fh)
910911

@@ -1013,7 +1014,7 @@ def _print_figure_tex(
10131014
%!PS-Adobe-3.0 EPSF-3.0
10141015
%%LanguageLevel: 3
10151016
{dsc_comments}
1016-
{get_bbox_header(bbox)[0]}
1017+
{_get_bbox_header(bbox)}
10171018
%%EndComments
10181019
%%BeginProlog
10191020
/mpldict {len(_psDefs)} dict def
@@ -1205,21 +1206,26 @@ def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
12051206
pstoeps(tmpfile)
12061207

12071208

1209+
@_api.deprecated("3.9")
12081210
def get_bbox_header(lbrt, rotated=False):
12091211
"""
12101212
Return a postscript header string for the given bbox lbrt=(l, b, r, t).
12111213
Optionally, return rotate command.
12121214
"""
1215+
return _get_bbox_header(lbrt), (_get_rotate_command(lbrt) if rotated else "")
12131216

1217+
1218+
def _get_bbox_header(lbrt):
1219+
"""Return a PostScript header string for bounding box *lbrt*=(l, b, r, t)."""
12141220
l, b, r, t = lbrt
1215-
if rotated:
1216-
rotate = f"{l+r:.2f} {0:.2f} translate\n90 rotate"
1217-
else:
1218-
rotate = ""
1219-
bbox_info = '%%%%BoundingBox: %d %d %d %d' % (l, b, np.ceil(r), np.ceil(t))
1220-
hires_bbox_info = f'%%HiResBoundingBox: {l:.6f} {b:.6f} {r:.6f} {t:.6f}'
1221+
return (f"%%BoundingBox: {int(l)} {int(b)} {math.ceil(r)} {math.ceil(t)}\n"
1222+
f"%%HiResBoundingBox: {l:.6f} {b:.6f} {r:.6f} {t:.6f}")
1223+
12211224

1222-
return '\n'.join([bbox_info, hires_bbox_info]), rotate
1225+
def _get_rotate_command(lbrt):
1226+
"""Return a PostScript 90° rotation command for bounding box *lbrt*=(l, b, r, t)."""
1227+
l, b, r, t = lbrt
1228+
return f"{l+r:.2f} {0:.2f} translate\n90 rotate"
12231229

12241230

12251231
def pstoeps(tmpfile, bbox=None, rotated=False):
@@ -1229,12 +1235,6 @@ def pstoeps(tmpfile, bbox=None, rotated=False):
12291235
None, original bbox will be used.
12301236
"""
12311237

1232-
# if rotated==True, the output eps file need to be rotated
1233-
if bbox:
1234-
bbox_info, rotate = get_bbox_header(bbox, rotated=rotated)
1235-
else:
1236-
bbox_info, rotate = None, None
1237-
12381238
epsfile = tmpfile + '.eps'
12391239
with open(epsfile, 'wb') as epsh, open(tmpfile, 'rb') as tmph:
12401240
write = epsh.write
@@ -1243,7 +1243,7 @@ def pstoeps(tmpfile, bbox=None, rotated=False):
12431243
if line.startswith(b'%!PS'):
12441244
write(b"%!PS-Adobe-3.0 EPSF-3.0\n")
12451245
if bbox:
1246-
write(bbox_info.encode('ascii') + b'\n')
1246+
write(_get_bbox_header(bbox).encode('ascii') + b'\n')
12471247
elif line.startswith(b'%%EndComments'):
12481248
write(line)
12491249
write(b'%%BeginProlog\n'
@@ -1255,8 +1255,8 @@ def pstoeps(tmpfile, bbox=None, rotated=False):
12551255
b'/setpagedevice {pop} def\n'
12561256
b'%%EndProlog\n'
12571257
b'%%Page 1 1\n')
1258-
if rotate:
1259-
write(rotate.encode('ascii') + b'\n')
1258+
if rotated: # The output eps file need to be rotated.
1259+
write(_get_rotate_command(bbox).encode('ascii') + b'\n')
12601260
break
12611261
elif bbox and line.startswith((b'%%Bound', b'%%HiResBound',
12621262
b'%%DocumentMedia', b'%%Pages')):

0 commit comments

Comments
 (0)