MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / gs_distill

Function gs_distill

lib/matplotlib/backends/backend_ps.py:1293–1329  ·  view source on GitHub ↗

Use ghostscript's pswrite or epswrite device to distill a file. This yields smaller files without illegal encapsulated postscript operators. The output is low-level, converting text to outlines.

(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False)

Source from the content-addressed store, hash-verified

1291
1292
1293def gs_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
1294 """
1295 Use ghostscript's pswrite or epswrite device to distill a file.
1296 This yields smaller files without illegal encapsulated postscript
1297 operators. The output is low-level, converting text to outlines.
1298 """
1299
1300 if eps:
1301 paper_option = ["-dEPSCrop"]
1302 elif ptype == "figure":
1303 # The bbox will have its lower-left corner at (0, 0), so upper-right
1304 # corner corresponds with paper size.
1305 paper_option = [f"-dDEVICEWIDTHPOINTS={bbox[2]}",
1306 f"-dDEVICEHEIGHTPOINTS={bbox[3]}"]
1307 else:
1308 paper_option = [f"-sPAPERSIZE={ptype}"]
1309
1310 psfile = tmpfile + '.ps'
1311 dpi = mpl.rcParams['ps.distiller.res']
1312
1313 cbook._check_and_log_subprocess(
1314 [mpl._get_executable_info("gs").executable,
1315 "-dBATCH", "-dNOPAUSE", "-dSAFER", "-r%d" % dpi, "-sDEVICE=ps2write",
1316 *paper_option, f"-sOutputFile={psfile}", tmpfile],
1317 _log)
1318
1319 os.remove(tmpfile)
1320 shutil.move(psfile, tmpfile)
1321
1322 # While it is best if above steps preserve the original bounding
1323 # box, there seem to be cases when it is not. For those cases,
1324 # the original bbox can be restored during the pstoeps step.
1325
1326 if eps:
1327 # For some versions of gs, above steps result in a ps file where the
1328 # original bbox is no more correct. Do not adjust bbox for now.
1329 pstoeps(tmpfile, bbox, rotated=rotated)
1330
1331
1332def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):

Callers

nothing calls this directly

Calls 2

pstoepsFunction · 0.85
removeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…