Skip to content

Commit 61a4058

Browse files
committed
Do not distill and embed fonts if no text
1 parent efaedd8 commit 61a4058

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/matplotlib/backends/backend_ps.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,13 @@ def _print_figure_tex(
10631063
""",
10641064
encoding="latin-1")
10651065

1066+
if len(ps_renderer.psfrag) == 0:
1067+
# No text, so no need to distill
1068+
if is_eps:
1069+
pstoeps(str(tmppath))
1070+
_move_path_to_path_or_stream(tmppath, outfile)
1071+
return
1072+
10661073
if orientation is _Orientation.landscape: # now, ready to rotate
10671074
width, height = height, width
10681075
bbox = (lly, llx, ury, urx)

lib/matplotlib/tests/test_backend_ps.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,22 @@ def test_linedash():
254254
assert buf.tell() > 0
255255

256256

257+
def test_noembed_fonts():
258+
"""Test that fonts are not embedded when no text is used"""
259+
mpl.rcParams["text.usetex"] = True
260+
fig, ax = plt.subplots()
261+
ax.set_axis_off()
262+
263+
# About 160k with embedded fonts
264+
buf = io.BytesIO()
265+
fig.savefig(buf, format="ps")
266+
assert buf.getbuffer().nbytes < 1000
267+
268+
buf = io.BytesIO()
269+
fig.savefig(buf, format="eps")
270+
assert buf.getbuffer().nbytes < 1000
271+
272+
257273
def test_no_duplicate_definition():
258274

259275
fig = Figure()

0 commit comments

Comments
 (0)