Revision: 3815
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3815&view=rev
Author:   mdboom
Date:     2007-09-07 13:28:01 -0700 (Fri, 07 Sep 2007)

Log Message:
-----------
Support characters composed of multiple characters.  Only one
supported at the moment is AA (angstrom).

Modified Paths:
--------------
    trunk/matplotlib/lib/matplotlib/mathtext.py

Modified: trunk/matplotlib/lib/matplotlib/mathtext.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/mathtext.py 2007-09-07 19:45:48 UTC (rev 
3814)
+++ trunk/matplotlib/lib/matplotlib/mathtext.py 2007-09-07 20:28:01 UTC (rev 
3815)
@@ -153,13 +153,6 @@
 ####################
 
 
-# a character over another character
-charOverChars = {
-    # The first 2 entires in the tuple are (font, char, sizescale) for
-    # the two symbols under and over.  The third entry is the space
-    # between the two symbols in points
-    r'\angstrom' : (  ('rm', 'A', 1.0), (None, '\circ', 0.5), 0.0 ),
-    }
 
 ##############################################################################
 # FONTS
@@ -1771,7 +1764,7 @@
 
 def Error(msg):
     def raise_error(s, loc, toks):
-        raise ParseFatalException(msg)
+        raise ParseFatalException(msg + "\n" + s)
 
     empty = Empty()
     empty.setParseAction(raise_error)
@@ -1854,8 +1847,7 @@
 
         bslash       = Literal('\\')
 
-        accent       = oneOf("hat check dot breve acute ddot grave tilde bar "
-                             "vec \" ` ' ~ . ^ widehat widetilde")
+        accent       = oneOf(self._accent_map.keys() + 
list(self._wide_accents))
 
         function     = oneOf("arccos csc ker min arcsin deg lg Pr arctan det "
                              "lim sec arg dim liminf sin cos exp limsup sinh "
@@ -1890,8 +1882,13 @@
                        )
                      ).setParseAction(self.symbol).leaveWhitespace()
 
+        c_over_c     =(Suppress(bslash)
+                     + oneOf(self._char_over_chars.keys())
+                     ).setParseAction(self.char_over_chars)
+        
         accent       = Group(
-                         Combine(bslash + accent)
+                         Suppress(bslash)
+                       + accent
                        + placeable
                      ).setParseAction(self.accent).setName("accent")
 
@@ -1930,7 +1927,7 @@
                          Suppress(Literal("["))
                        + Group(
                            OneOrMore(
-                             symbol
+                             (c_over_c | symbol)
                            ^ font
                            )
                          )
@@ -1942,7 +1939,7 @@
 
         placeable   <<(accent
                      ^ function
-                     ^ symbol
+                     ^ (c_over_c | symbol)
                      ^ group
                      ^ frac
                      ^ sqrt
@@ -2120,25 +2117,69 @@
                            do_kern = False)]
         return [char]
 
+    _char_over_chars = {
+        # The first 2 entires in the tuple are (font, char, sizescale) for
+        # the two symbols under and over.  The third element is the space
+        # (in multiples of underline height)
+        r'AA' : (  ('rm', 'A', 1.0), (None, '\circ', 0.5), 0.0),
+    }
+    
+    def char_over_chars(self, s, loc, toks):
+        sym = toks[0]
+        state = self.get_state()
+        thickness = state.font_output.get_underline_thickness(
+            state.font, state.fontsize, state.dpi)
+
+        under_desc, over_desc, space = \
+            self._char_over_chars.get(sym, (None, None, 0.0))
+        if under_desc is None:
+            raise ParseFatalException("Error parsing symbol")
+        
+        over_state = state.copy()
+        if over_desc[0] is not None:
+            over_state.font = over_desc[0]
+        over_state.fontsize *= over_desc[2]
+        over = Accent(over_desc[1], over_state)
+
+        under_state = state.copy()
+        if under_desc[0] is not None:
+            under_state.font = under_desc[0]
+        under_state.fontsize *= under_desc[2]
+        under = Char(under_desc[1], under_state)
+
+        width = max(over.width, under.width)
+        
+        over_centered = HCentered([over])
+        over_centered.hpack(width, 'exactly')
+
+        under_centered = HCentered([under])
+        under_centered.hpack(width, 'exactly')
+        
+        return Vlist([
+                over_centered,
+                Vbox(0., thickness * space),
+                under_centered
+                ])
+        
     _accent_map = {
-        r'\hat'   : r'\circumflexaccent',
-        r'\breve' : r'\combiningbreve',
-        r'\bar'   : r'\combiningoverline',
-        r'\grave' : r'\combininggraveaccent',
-        r'\acute' : r'\combiningacuteaccent',
-        r'\ddot'  : r'\combiningdiaeresis',
-        r'\tilde' : r'\combiningtilde',
-        r'\dot'   : r'\combiningdotabove',
-        r'\vec'   : r'\combiningrightarrowabove',
-        r'\"'     : r'\combiningdiaeresis',
-        r"\`"     : r'\combininggraveaccent',
-        r"\'"     : r'\combiningacuteaccent',
-        r'\~'     : r'\combiningtilde',
-        r'\.'     : r'\combiningdotabove',
-        r'\^'     : r'\circumflexaccent'
+        r'hat'   : r'\circumflexaccent',
+        r'breve' : r'\combiningbreve',
+        r'bar'   : r'\combiningoverline',
+        r'grave' : r'\combininggraveaccent',
+        r'acute' : r'\combiningacuteaccent',
+        r'ddot'  : r'\combiningdiaeresis',
+        r'tilde' : r'\combiningtilde',
+        r'dot'   : r'\combiningdotabove',
+        r'vec'   : r'\combiningrightarrowabove',
+        r'"'     : r'\combiningdiaeresis',
+        r"`"     : r'\combininggraveaccent',
+        r"'"     : r'\combiningacuteaccent',
+        r'~'     : r'\combiningtilde',
+        r'.'     : r'\combiningdotabove',
+        r'^'     : r'\circumflexaccent'
         }
 
-    _wide_accents = Set(r"\widehat \widetilde".split())
+    _wide_accents = Set(r"widehat widetilde".split())
 
     def accent(self, s, loc, toks):
         assert(len(toks)==1)
@@ -2150,7 +2191,7 @@
         accent, sym = toks[0]
         if accent in self._wide_accents:
             accent = AutoWidthChar(
-                accent, sym.width, state, char_class=Accent)
+                '\\' + accent, sym.width, state, char_class=Accent)
         else:
             accent = Accent(self._accent_map[accent], state)
         centered = HCentered([accent])


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

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to