Skip to content

Commit 0c84324

Browse files
authored
Merge pull request matplotlib#19983 from anntzer/psd
Fix handling of "d" glyph in backend_ps.
2 parents 316c3bf + 3e94489 commit 0c84324

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

lib/matplotlib/backends/backend_ps.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,12 @@ def _font_to_ps_type3(font_path, glyph_ids):
180180
2 copy known not {pop /.notdef} if
181181
true 3 1 roll get exec
182182
end
183-
} d
183+
} _d
184184
185185
/BuildChar {
186186
1 index /Encoding get exch get
187187
1 index /BuildGlyph get exec
188-
} d
188+
} _d
189189
190190
FontName currentdict end definefont pop
191191
"""
@@ -208,7 +208,7 @@ def _font_to_ps_type3(font_path, glyph_ids):
208208
# decomposer always explicitly moving to the closing point
209209
# first).
210210
[b"m", b"l", b"", b"c", b""], True).decode("ascii")
211-
+ "ce} d"
211+
+ "ce} _d"
212212
)
213213

214214
return preamble + "\n".join(entries) + postamble
@@ -1338,36 +1338,39 @@ def pstoeps(tmpfile, bbox=None, rotated=False):
13381338
# The usage comments use the notation of the operator summary
13391339
# in the PostScript Language reference manual.
13401340
psDefs = [
1341-
# name proc *d* -
1342-
"/d { bind def } bind def",
1341+
# name proc *_d* -
1342+
# Note that this cannot be bound to /d, because when embedding a Type3 font
1343+
# we may want to define a "d" glyph using "/d{...} d" which would locally
1344+
# overwrite the definition.
1345+
"/_d { bind def } bind def",
13431346
# x y *m* -
1344-
"/m { moveto } d",
1347+
"/m { moveto } _d",
13451348
# x y *l* -
1346-
"/l { lineto } d",
1349+
"/l { lineto } _d",
13471350
# x y *r* -
1348-
"/r { rlineto } d",
1351+
"/r { rlineto } _d",
13491352
# x1 y1 x2 y2 x y *c* -
1350-
"/c { curveto } d",
1353+
"/c { curveto } _d",
13511354
# *cl* -
1352-
"/cl { closepath } d",
1355+
"/cl { closepath } _d",
13531356
# *ce* -
1354-
"/ce { closepath eofill } d",
1357+
"/ce { closepath eofill } _d",
13551358
# w h x y *box* -
13561359
"""/box {
13571360
m
13581361
1 index 0 r
13591362
0 exch r
13601363
neg 0 r
13611364
cl
1362-
} d""",
1365+
} _d""",
13631366
# w h x y *clipbox* -
13641367
"""/clipbox {
13651368
box
13661369
clip
13671370
newpath
1368-
} d""",
1371+
} _d""",
13691372
# wx wy llx lly urx ury *setcachedevice* -
1370-
"/sc { setcachedevice } d",
1373+
"/sc { setcachedevice } _d",
13711374
]
13721375

13731376

lib/matplotlib/tests/test_backend_ps.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,14 @@ def test_text_clip(fig_test, fig_ref):
173173
# Fully clipped-out text should not appear.
174174
ax.text(0, 0, "hello", transform=fig_test.transFigure, clip_on=True)
175175
fig_ref.add_subplot()
176+
177+
178+
@needs_ghostscript
179+
def test_d_glyph(tmp_path):
180+
# Ensure that we don't have a procedure defined as /d, which would be
181+
# overwritten by the glyph definition for "d".
182+
fig = plt.figure()
183+
fig.text(.5, .5, "def")
184+
out = tmp_path / "test.eps"
185+
fig.savefig(out)
186+
mpl.testing.compare.convert(out, cache=False) # Should not raise.

0 commit comments

Comments
 (0)