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

Skip to content

Fix issue with empty line in ps backend #23964

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

Merged
merged 1 commit into from
Sep 24, 2022
Merged
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
5 changes: 3 additions & 2 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,9 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
curr_stream[1].append(
(item.x, item.ft_object.get_glyph_name(item.glyph_idx))
)
# append the last entry
stream.append(curr_stream)
# append the last entry if exists
if curr_stream:
Copy link
Member

Choose a reason for hiding this comment

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

On consideration, I think the looser check here is better than what I had because I suspect other falsy things (like empty lists) would also break the consumer code.

stream.append(curr_stream)

self.set_color(*gc.get_rgb())

Expand Down
9 changes: 9 additions & 0 deletions lib/matplotlib/tests/test_backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,15 @@ def test_linedash():
assert buf.tell() > 0


def test_empty_line():
# Smoke-test for gh#23954
figure = Figure()
figure.text(0.5, 0.5, "\nfoo\n\n")
buf = io.BytesIO()
figure.savefig(buf, format='eps')
figure.savefig(buf, format='ps')


def test_no_duplicate_definition():

fig = Figure()
Expand Down