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

Skip to content

Commit ed9eaba

Browse files
committed
svn path=/trunk/matplotlib/; revision=8026
1 parent 7b2a3ec commit ed9eaba

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

doc/users/mathtext.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ that you provide. The mathtext font can be selected with the
2323
customization variable ``mathtext.fontset`` (see
2424
:ref:`customizing-matplotlib`)
2525

26+
.. note::
27+
On `"narrow" <http://wordaligned.org/articles/narrow-python>`_ builds
28+
of Python, if you use the STIX fonts you should also set
29+
``ps.fonttype`` and ``pdf.fonttype`` to 3 (the default), not 42.
30+
Otherwise `some characters will not be visible
31+
<http://thread.gmane.org/gmane.comp.python.matplotlib.general/19963/focus=19978>`_.
32+
2633
Here is a simple example::
2734

2835
# plain text

lib/matplotlib/mathtext.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ def get_unicode_index(symbol):
8282
TeX/Type1 symbol"""%locals()
8383
raise ValueError, message
8484

85+
def unichr_safe(index):
86+
"""Return the Unicode character corresponding to the index,
87+
or the replacement character if this is a narrow build of Python
88+
and the requested character is outside the BMP."""
89+
try:
90+
return unichr(index)
91+
except ValueError:
92+
return unichr(0xFFFD)
8593

8694
class MathtextBackend(object):
8795
"""
@@ -321,7 +329,8 @@ def __init__(self):
321329

322330
def render_glyph(self, ox, oy, info):
323331
oy = self.height - oy + info.offset
324-
thetext = unichr(info.num)
332+
thetext = unichr_safe(info.num)
333+
325334
self.svg_glyphs.append(
326335
(info.font, info.fontsize, thetext, ox, oy, info.metrics))
327336

@@ -351,7 +360,7 @@ def __init__(self):
351360

352361
def render_glyph(self, ox, oy, info):
353362
oy = self.height - oy + info.offset
354-
thetext = unichr(info.num)
363+
thetext = unichr_safe(info.num)
355364
self.glyphs.append(
356365
(info.font, info.fontsize, thetext, ox, oy))
357366

@@ -379,7 +388,7 @@ def __init__(self):
379388

380389
def render_glyph(self, ox, oy, info):
381390
oy = oy - info.offset - self.height
382-
thetext = unichr(info.num)
391+
thetext = unichr_safe(info.num)
383392
self.glyphs.append(
384393
(info.font, info.fontsize, thetext, ox, oy))
385394

@@ -997,7 +1006,7 @@ def get_sized_alternatives_for_symbol(self, fontname, sym):
9971006
cached_font = self._get_font(i)
9981007
glyphindex = cached_font.charmap.get(uniindex)
9991008
if glyphindex is not None:
1000-
alternatives.append((i, unichr(uniindex)))
1009+
alternatives.append((i, unichr_safe(uniindex)))
10011010

10021011
# The largest size of the radical symbol in STIX has incorrect
10031012
# metrics that cause it to be disconnected from the stem.

0 commit comments

Comments
 (0)