Skip to content

Do not distill and embed fonts if no text #23775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,13 @@ def _print_figure_tex(
""",
encoding="latin-1")

if len(ps_renderer.psfrag) == 0:
# No text, so no need to distill
if is_eps:
pstoeps(str(tmppath))
_move_path_to_path_or_stream(tmppath, outfile)
return

if orientation is _Orientation.landscape: # now, ready to rotate
width, height = height, width
bbox = (lly, llx, ury, urx)
Expand Down
16 changes: 16 additions & 0 deletions lib/matplotlib/tests/test_backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,22 @@ def test_linedash():
assert buf.tell() > 0


def test_noembed_fonts():
"""Test that fonts are not embedded when no text is used"""
mpl.rcParams["text.usetex"] = True
fig, ax = plt.subplots()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you can skip axes creation (fig = plt.figure()).

ax.set_axis_off()

# About 160k with embedded fonts
buf = io.BytesIO()
fig.savefig(buf, format="ps")
assert buf.getbuffer().nbytes < 1000

buf = io.BytesIO()
fig.savefig(buf, format="eps")
assert buf.getbuffer().nbytes < 1000


def test_no_duplicate_definition():

fig = Figure()
Expand Down