Revision: 8026
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8026&view=rev
Author:   jouni
Date:     2009-12-13 12:06:07 +0000 (Sun, 13 Dec 2009)

Log Message:
-----------
Address mathtext problem with non-BMP characters: 
http://thread.gmane.org/gmane.comp.python.matplotlib.general/19963/focus=19978

Modified Paths:
--------------
    trunk/matplotlib/doc/users/mathtext.rst
    trunk/matplotlib/lib/matplotlib/mathtext.py

Modified: trunk/matplotlib/doc/users/mathtext.rst
===================================================================
--- trunk/matplotlib/doc/users/mathtext.rst     2009-12-12 18:24:54 UTC (rev 
8025)
+++ trunk/matplotlib/doc/users/mathtext.rst     2009-12-13 12:06:07 UTC (rev 
8026)
@@ -23,6 +23,13 @@
 customization variable ``mathtext.fontset`` (see
 :ref:`customizing-matplotlib`)
 
+.. note:: 
+   On `"narrow" <http://wordaligned.org/articles/narrow-python>`_ builds 
+   of Python, if you use the STIX fonts you should also set
+   ``ps.fonttype`` and ``pdf.fonttype`` to 3 (the default), not 42.
+   Otherwise `some characters will not be visible 
+   
<http://thread.gmane.org/gmane.comp.python.matplotlib.general/19963/focus=19978>`_.
+
 Here is a simple example::
 
     # plain text

Modified: trunk/matplotlib/lib/matplotlib/mathtext.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/mathtext.py 2009-12-12 18:24:54 UTC (rev 
8025)
+++ trunk/matplotlib/lib/matplotlib/mathtext.py 2009-12-13 12:06:07 UTC (rev 
8026)
@@ -82,6 +82,14 @@
 TeX/Type1 symbol"""%locals()
         raise ValueError, message
 
+def unichr_safe(index):
+    """Return the Unicode character corresponding to the index,
+or the replacement character if this is a narrow build of Python
+and the requested character is outside the BMP."""
+    try:
+        return unichr(index)
+    except ValueError:
+        return unichr(0xFFFD)
 
 class MathtextBackend(object):
     """
@@ -321,7 +329,8 @@
 
     def render_glyph(self, ox, oy, info):
         oy = self.height - oy + info.offset
-        thetext = unichr(info.num)
+        thetext = unichr_safe(info.num)
+            
         self.svg_glyphs.append(
             (info.font, info.fontsize, thetext, ox, oy, info.metrics))
 
@@ -351,7 +360,7 @@
 
     def render_glyph(self, ox, oy, info):
         oy = self.height - oy + info.offset
-        thetext = unichr(info.num)
+        thetext = unichr_safe(info.num)
         self.glyphs.append(
             (info.font, info.fontsize, thetext, ox, oy))
 
@@ -379,7 +388,7 @@
 
     def render_glyph(self, ox, oy, info):
         oy = oy - info.offset - self.height
-        thetext = unichr(info.num)
+        thetext = unichr_safe(info.num)
         self.glyphs.append(
             (info.font, info.fontsize, thetext, ox, oy))
 
@@ -997,7 +1006,7 @@
             cached_font = self._get_font(i)
             glyphindex = cached_font.charmap.get(uniindex)
             if glyphindex is not None:
-                alternatives.append((i, unichr(uniindex)))
+                alternatives.append((i, unichr_safe(uniindex)))
 
         # The largest size of the radical symbol in STIX has incorrect
         # metrics that cause it to be disconnected from the stem.


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to