diff --git a/lib/matplotlib/_type1font.py b/lib/matplotlib/_type1font.py index b4ee5edb233c..c7b73f9c0c7e 100644 --- a/lib/matplotlib/_type1font.py +++ b/lib/matplotlib/_type1font.py @@ -866,17 +866,16 @@ def subset(self, characters, name_prefix): encoding = {code: glyph for code, glyph in self.prop['Encoding'].items() if code in characters} - encoding[0] = '.notdef' # todo and done include strings (glyph names) - todo = set(encoding.values()) + todo = {'.notdef', *encoding.values()} done = set() seen_subrs = {0, 1, 2, 3} while todo: glyph = todo.pop() called_glyphs, called_subrs = _CharstringSimulator(self).run(glyph) + done.add(glyph) todo.update(called_glyphs - done) seen_subrs.update(called_subrs) - done.add(glyph) charstrings = self._subset_charstrings(done) subrs = self._subset_subrs(seen_subrs) @@ -949,7 +948,8 @@ def _charstring_tokens(data): def _postscript_encoding(self, encoding): """Return a PostScript encoding array for the encoding.""" return '\n'.join([ - '/Encoding 256 array\n0 1 255 { 1 index exch /.notdef put} for', + '/Encoding 256 array', + '0 1 255 { 1 index exch /.notdef put} for', *( f'dup {i} /{glyph} put' for i, glyph in sorted(encoding.items()) diff --git a/lib/matplotlib/tests/baseline_images/test_usetex/test_usetex.pdf b/lib/matplotlib/tests/baseline_images/test_usetex/test_usetex.pdf index f2ebbeb528cc..bce9d583d4d4 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_usetex/test_usetex.pdf and b/lib/matplotlib/tests/baseline_images/test_usetex/test_usetex.pdf differ diff --git a/lib/matplotlib/tests/baseline_images/test_usetex/test_usetex.png b/lib/matplotlib/tests/baseline_images/test_usetex/test_usetex.png index e4a62a1c87ae..9f9d21b22528 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_usetex/test_usetex.png and b/lib/matplotlib/tests/baseline_images/test_usetex/test_usetex.png differ diff --git a/lib/matplotlib/tests/test_usetex.py b/lib/matplotlib/tests/test_usetex.py index 87277f152789..6d7506055ce5 100644 --- a/lib/matplotlib/tests/test_usetex.py +++ b/lib/matplotlib/tests/test_usetex.py @@ -26,10 +26,11 @@ def test_usetex(): kwargs = {"verticalalignment": "baseline", "size": 24, "bbox": dict(pad=0, edgecolor="k", facecolor="none")} ax.text(0.2, 0.7, - # the \LaTeX macro exercises character sizing and placement, + # The \LaTeX macro exercises character sizing and placement, # \left[ ... \right\} draw some variable-height characters, - # \sqrt and \frac draw horizontal rules, \mathrm changes the font - r'\LaTeX\ $\left[\int\limits_e^{2e}' + # \sqrt and \frac draw horizontal rules, \mathrm changes the font, + # the minus sign hits character code 0 in the Type 1 font that LaTeX uses. + r'\LaTeX\ $\left[\int\limits_e^{-2e}' r'\sqrt\frac{\log^3 x}{x}\,\mathrm{d}x \right\}$', **kwargs) ax.text(0.2, 0.3, "lg", **kwargs)