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

Skip to content

Commit 176df19

Browse files
committed
Throw in dummy characters for symbols not in the Bakoma fonts.
svn path=/trunk/matplotlib/; revision=4160
1 parent 4307aaa commit 176df19

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

lib/matplotlib/mathtext.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ def __init__(self, *args, **kwargs):
672672
_slanted_symbols = Set(r"\int \oint".split())
673673

674674
def _get_glyph(self, fontname, sym, fontsize):
675+
symbol_name = None
675676
if fontname in self.fontmap and latex_to_bakoma.has_key(sym):
676677
basename, num = latex_to_bakoma[sym]
677678
slanted = (basename == "cmmi10") or sym in self._slanted_symbols
@@ -682,10 +683,20 @@ def _get_glyph(self, fontname, sym, fontsize):
682683
slanted = (fontname == "it")
683684
cached_font = self._get_font(fontname)
684685
num = ord(sym)
685-
symbol_name = cached_font.font.get_glyph_name(
686-
cached_font.charmap[num])
687-
else:
688-
raise ValueError('unrecognized symbol "%s"' % sym)
686+
gid = cached_font.charmap.get(num)
687+
if gid is not None:
688+
symbol_name = cached_font.font.get_glyph_name(
689+
cached_font.charmap[num])
690+
691+
if symbol_name is None:
692+
warn("Unrecognized symbol '%s'. Substituting with a dummy symbol."
693+
% sym.encode('ascii', 'backslashreplace'), MathTextWarning)
694+
fontname = 'it'
695+
cached_font = self._get_font(fontname)
696+
num = 0x3F # currency character, for lack of anything better
697+
gid = cached_font.charmap[num]
698+
symbol_name = cached_font.font.get_glyph_name(gid)
699+
slanted = False
689700

690701
return cached_font, num, symbol_name, fontsize, slanted
691702

0 commit comments

Comments
 (0)