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

Skip to content

Commit 0362a4e

Browse files
committed
Correctly position text with nonzero descent with afm fonts / ps output.
See e.g. ``` rcParams["ps.useafm"] = True text(.5, .5, "qk") axhline(.5) savefig("/tmp/test.ps") ``` Previously the bottom of the tip of the "q" would be on the baseline; now the baseline is correctly positioned. (I picked a relatively generic name for the test because we could later update the baseline image "in place" for more afm tests.)
1 parent c1f6515 commit 0362a4e

File tree

3 files changed

+76
-2
lines changed

3 files changed

+76
-2
lines changed

lib/matplotlib/backends/backend_ps.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,6 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
541541
scale = 0.001 * fontsize
542542

543543
thisx = 0
544-
thisy = font.get_str_bbox_and_descent(s)[4] * scale
545544
last_name = None
546545
lines = []
547546
for c in s:
@@ -558,7 +557,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
558557
last_name = name
559558
thisx += kern * scale
560559

561-
lines.append('%f %f m /%s glyphshow' % (thisx, thisy, name))
560+
lines.append('%f 0 m /%s glyphshow' % (thisx, name))
562561

563562
thisx += width * scale
564563

lib/matplotlib/tests/baseline_images/test_backend_ps/useafm.eps

Lines changed: 66 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/matplotlib/tests/test_backend_ps.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,12 @@ def test_partial_usetex(caplog):
148148
plt.savefig(io.BytesIO(), format="ps")
149149
assert caplog.records and all("as if usetex=False" in record.getMessage()
150150
for record in caplog.records)
151+
152+
153+
@image_comparison(["useafm.eps"])
154+
def test_useafm():
155+
mpl.rcParams["ps.useafm"] = True
156+
fig, ax = plt.subplots()
157+
ax.set_axis_off()
158+
ax.axhline(.5)
159+
ax.text(.5, .5, "qk")

0 commit comments

Comments
 (0)