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

Skip to content

Commit a14a8fe

Browse files
authored
Merge pull request #19993 from meeseeksmachine/auto-backport-of-pr-19983-on-v3.4.x
Backport PR #19983 on branch v3.4.x (Fix handling of "d" glyph in backend_ps.)
2 parents f30d086 + 7267f8d commit a14a8fe

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
@@ -1356,36 +1356,39 @@ def pstoeps(tmpfile, bbox=None, rotated=False):
13561356
# The usage comments use the notation of the operator summary
13571357
# in the PostScript Language reference manual.
13581358
psDefs = [
1359-
# name proc *d* -
1360-
"/d { bind def } bind def",
1359+
# name proc *_d* -
1360+
# Note that this cannot be bound to /d, because when embedding a Type3 font
1361+
# we may want to define a "d" glyph using "/d{...} d" which would locally
1362+
# overwrite the definition.
1363+
"/_d { bind def } bind def",
13611364
# x y *m* -
1362-
"/m { moveto } d",
1365+
"/m { moveto } _d",
13631366
# x y *l* -
1364-
"/l { lineto } d",
1367+
"/l { lineto } _d",
13651368
# x y *r* -
1366-
"/r { rlineto } d",
1369+
"/r { rlineto } _d",
13671370
# x1 y1 x2 y2 x y *c* -
1368-
"/c { curveto } d",
1371+
"/c { curveto } _d",
13691372
# *cl* -
1370-
"/cl { closepath } d",
1373+
"/cl { closepath } _d",
13711374
# *ce* -
1372-
"/ce { closepath eofill } d",
1375+
"/ce { closepath eofill } _d",
13731376
# w h x y *box* -
13741377
"""/box {
13751378
m
13761379
1 index 0 r
13771380
0 exch r
13781381
neg 0 r
13791382
cl
1380-
} d""",
1383+
} _d""",
13811384
# w h x y *clipbox* -
13821385
"""/clipbox {
13831386
box
13841387
clip
13851388
newpath
1386-
} d""",
1389+
} _d""",
13871390
# wx wy llx lly urx ury *setcachedevice* -
1388-
"/sc { setcachedevice } d",
1391+
"/sc { setcachedevice } _d",
13891392
]
13901393

13911394

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)