Revision: 4444
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4444&view=rev
Author:   mdboom
Date:     2007-11-26 07:46:17 -0800 (Mon, 26 Nov 2007)

Log Message:
-----------
Merged revisions 4437-4443 via svnmerge from 
http://matplotlib.svn.sf.net/svnroot/matplotlib/trunk/matplotlib

........
  r4438 | mdboom | 2007-11-26 09:29:49 -0500 (Mon, 26 Nov 2007) | 2 lines
  
  Minor speed improvements in mathtext.  Removing trailing whitespace.
........
  r4441 | mdboom | 2007-11-26 10:31:54 -0500 (Mon, 26 Nov 2007) | 2 lines
  
  Fix colored text in SVG backend.
........
  r4442 | mdboom | 2007-11-26 10:42:10 -0500 (Mon, 26 Nov 2007) | 2 lines
  
  Reduce SVG file sizes.
........
  r4443 | mdboom | 2007-11-26 10:43:26 -0500 (Mon, 26 Nov 2007) | 2 lines
  
  One more SVG color detail (in mathtext)
........

Modified Paths:
--------------
    branches/transforms/lib/matplotlib/backends/backend_svg.py
    branches/transforms/lib/matplotlib/mathtext.py

Property Changed:
----------------
    branches/transforms/


Property changes on: branches/transforms
___________________________________________________________________
Name: svnmerge-integrated
   - /trunk/matplotlib:1-4436
   + /trunk/matplotlib:1-4443

Modified: branches/transforms/lib/matplotlib/backends/backend_svg.py
===================================================================
--- branches/transforms/lib/matplotlib/backends/backend_svg.py  2007-11-26 
15:43:26 UTC (rev 4443)
+++ branches/transforms/lib/matplotlib/backends/backend_svg.py  2007-11-26 
15:46:17 UTC (rev 4444)
@@ -29,7 +29,7 @@
 
 _capstyle_d = {'projecting' : 'square', 'butt' : 'butt', 'round': 'round',}
 class RendererSVG(RendererBase):
-    FONT_SCALE = 1200.0
+    FONT_SCALE = 100.0
 
     def __init__(self, width, height, svgwriter, basename=None):
         self.width=width
@@ -293,7 +293,6 @@
         color = rgb2hex(gc.get_rgb()[:3])
 
         if rcParams['svg.embed_char_paths']:
-
             svg = ['<g style="fill: %s" transform="' % color]
             if angle != 0:
                 svg.append('translate(%s,%s)rotate(%1.1f)' % (x,y,-angle))
@@ -453,7 +452,7 @@
             svg.append('</text>\n')
 
         if len(svg_rects):
-            style = "fill: black; stroke: none"
+            style = "fill: %s; stroke: none" % color
             svg.append('<g style="%s" transform="' % style)
             if angle != 0:
                 svg.append('translate(%s,%s) rotate(%1.1f)'

Modified: branches/transforms/lib/matplotlib/mathtext.py
===================================================================
--- branches/transforms/lib/matplotlib/mathtext.py      2007-11-26 15:43:26 UTC 
(rev 4443)
+++ branches/transforms/lib/matplotlib/mathtext.py      2007-11-26 15:46:17 UTC 
(rev 4444)
@@ -208,7 +208,7 @@
 class MathtextBackendBbox(MathtextBackend):
     """A backend whose only purpose is to get a precise bounding box.
     Only required for the Agg backend."""
-    
+
     def __init__(self, real_backend):
         MathtextBackend.__init__(self)
         self.bbox = [0, 0, 0, 0]
@@ -219,7 +219,7 @@
                      min(self.bbox[1], y1),
                      max(self.bbox[2], x2),
                      max(self.bbox[3], y2)]
-        
+
     def render_glyph(self, ox, oy, info):
         self._update_bbox(ox + info.metrics.xmin,
                           oy - info.metrics.ymax,
@@ -251,14 +251,14 @@
         self.real_backend.fonts_object = self.fonts_object
         self.real_backend.ox = self.bbox[0]
         self.real_backend.oy = self.bbox[1]
-        
+
 class MathtextBackendAggRender(MathtextBackend):
     def __init__(self):
         self.ox = 0
         self.oy = 0
         self.image = None
         MathtextBackend.__init__(self)
-    
+
     def set_canvas_size(self, w, h, d):
         MathtextBackend.set_canvas_size(self, w, h, d)
         self.image = FT2Image(ceil(w), ceil(h + d))
@@ -284,11 +284,11 @@
 
 def MathtextBackendAgg():
     return MathtextBackendBbox(MathtextBackendAggRender())
-    
+
 class MathtextBackendBitmapRender(MathtextBackendAggRender):
     def get_results(self, box):
         return self.image
-    
+
 def MathtextBackendBitmap():
     return MathtextBackendBbox(MathtextBackendBitmapRender())
 
@@ -310,7 +310,7 @@
 """ % locals()
             self.lastfont = postscript_name, fontsize
             self.pswriter.write(ps)
-        
+
         ps = """%(ox)f %(oy)f moveto
 /%(symbol_name)s glyphshow\n
 """ % locals()
@@ -426,7 +426,7 @@
         """Fix any cyclical references before the object is about
         to be destroyed."""
         self.used_characters = None
-        
+
     def get_kern(self, font1, sym1, fontsize1,
                  font2, sym2, fontsize2, dpi):
         """
@@ -737,7 +737,7 @@
 
     fontmap = {}
     use_cmex = True
-    
+
     def __init__(self, *args, **kwargs):
         # This must come first so the backend's owner is set correctly
         if rcParams['mathtext.fallback_to_cm']:
@@ -758,7 +758,7 @@
 
     def _map_virtual_font(self, fontname, font_class, uniindex):
         return fontname, uniindex
-    
+
     def _get_glyph(self, fontname, font_class, sym, fontsize):
         found_symbol = False
 
@@ -767,7 +767,7 @@
             if uniindex is not None:
                 fontname = 'ex'
                 found_symbol = True
-                
+
         if not found_symbol:
             try:
                 uniindex = get_unicode_index(sym)
@@ -780,7 +780,7 @@
 
         fontname, uniindex = self._map_virtual_font(
             fontname, font_class, uniindex)
-                
+
         # Only characters in the "Letter" class should be italicized in 'it'
         # mode.  Greek capital letters should be Roman.
         if found_symbol:
@@ -830,13 +830,16 @@
         return [(fontname, sym)]
 
 class StixFonts(UnicodeFonts):
+    """
+    A font handling class for the STIX fonts
+    """
     _fontmap = { 'rm'  : 'STIXGeneral',
                  'it'  : 'STIXGeneralItalic',
                  'bf'  : 'STIXGeneralBol',
                  'nonunirm' : 'STIXNonUni',
                  'nonuniit' : 'STIXNonUniIta',
                  'nonunibf' : 'STIXNonUniBol',
-                 
+
                  0 : 'STIXGeneral',
                  1 : 'STIXSiz1Sym',
                  2 : 'STIXSiz2Sym',
@@ -849,7 +852,6 @@
     cm_fallback = False
 
     def __init__(self, *args, **kwargs):
-        self._sans = kwargs.pop("sans", False)
         TruetypeFonts.__init__(self, *args, **kwargs)
         if not len(self.fontmap):
             for key, name in self._fontmap.iteritems():
@@ -891,14 +893,14 @@
                 # This will generate a dummy character
                 uniindex = 0x1
                 fontname = 'it'
-        
+
         # Handle private use area glyphs
         if (fontname in ('it', 'rm', 'bf') and
             uniindex >= 0xe000 and uniindex <= 0xf8ff):
             fontname = 'nonuni' + fontname
 
         return fontname, uniindex
-                
+
     _size_alternatives = {}
     def get_sized_alternatives_for_symbol(self, fontname, sym):
         alternatives = self._size_alternatives.get(sym)
@@ -919,7 +921,14 @@
 
         self._size_alternatives[sym] = alternatives
         return alternatives
-    
+
+class StixSansFonts(StixFonts):
+    """
+    A font handling class for the STIX fonts (using sans-serif
+    characters by default).
+    """
+    _sans = True
+
 class StandardPsFonts(Fonts):
     """
     Use the standard postscript fonts for rendering to backend_ps
@@ -1085,7 +1094,8 @@
 # Note that (as TeX) y increases downward, unlike many other parts of
 # matplotlib.
 
-# How much text shrinks when going to the next-smallest level
+# How much text shrinks when going to the next-smallest level.  GROW_FACTOR
+# must be the inverse of SHRINK_FACTOR.
 SHRINK_FACTOR   = 0.7
 GROW_FACTOR     = 1.0 / SHRINK_FACTOR
 # The number of different sizes of chars to use, beyond which they will not
@@ -1160,10 +1170,16 @@
         pass
 
 class Vbox(Box):
+    """
+    A box with only height (zero width).
+    """
     def __init__(self, height, depth):
         Box.__init__(self, 0., height, depth)
 
 class Hbox(Box):
+    """
+    A box with only width (zero height and depth).
+    """
     def __init__(self, width):
         Box.__init__(self, width, 0., 0.)
 
@@ -1241,8 +1257,9 @@
         self.depth    *= GROW_FACTOR
 
 class Accent(Char):
-    """The font metrics need to be dealt with differently for accents, since 
they
-    are already offset correctly from the baseline in TrueType fonts."""
+    """The font metrics need to be dealt with differently for accents,
+    since they are already offset correctly from the baseline in
+    TrueType fonts."""
     def _update_metrics(self):
         metrics = self._metrics = self.font_output.get_metrics(
             self.font, self.font_class, self.c, self.fontsize, self.dpi)
@@ -1741,7 +1758,7 @@
         self.cur_s    += 1
         self.max_push = max(self.cur_s, self.max_push)
         clamp         = self.clamp
-        
+
         for p in box.children:
             if isinstance(p, Char):
                 p.render(self.cur_h + self.off_h, self.cur_v + self.off_v)
@@ -1864,7 +1881,7 @@
     empty = Empty()
     empty.setParseAction(raise_error)
     return empty
-    
+
 class Parser(object):
     _binary_operators = Set(r'''
       + *
@@ -1922,7 +1939,7 @@
     _dropsub_symbols = Set(r'''\int \oint'''.split())
 
     _fontnames = Set("rm cal it tt sf bf default bb frak circled scr".split())
-    
+
     _function_names = Set("""
       arccos csc ker min arcsin deg lg Pr arctan det lim sec arg dim
       liminf sin cos exp limsup sinh cosh gcd ln sup cot hom log tan
@@ -1935,7 +1952,7 @@
     _leftDelim = Set(r"( [ { \lfloor \langle \lceil".split())
 
     _rightDelim = Set(r") ] } \rfloor \rangle \rceil".split())
-    
+
     def __init__(self):
         # All forward declarations are here
         font = Forward().setParseAction(self.font).setName("font")
@@ -1947,7 +1964,7 @@
         self._expression = 
Forward().setParseAction(self.finish).setName("finish")
 
         float        = Regex(r"-?[0-9]+\.?[0-9]*")
-        
+
         lbrace       = Literal('{').suppress()
         rbrace       = Literal('}').suppress()
         start_group  = (Optional(latexfont) + lbrace)
@@ -1993,7 +2010,7 @@
         c_over_c     =(Suppress(bslash)
                      + oneOf(self._char_over_chars.keys())
                      ).setParseAction(self.char_over_chars)
-        
+
         accent       = Group(
                          Suppress(bslash)
                        + accent
@@ -2055,7 +2072,7 @@
                      ) | Error("Expected symbol or group")
 
         simple      <<(space
-                     | customspace  
+                     | customspace
                      | font
                      | subsuper
                      )
@@ -2105,11 +2122,11 @@
               + (Suppress(math_delim)
                  | Error("Expected end of math '$'"))
               + non_math
-            )  
+            )
           ) + StringEnd()
 
         self._expression.enablePackrat()
-        
+
         self.clear()
 
     def clear(self):
@@ -2156,7 +2173,7 @@
                 self.font_class = name
             self._font = name
         font = property(_get_font, _set_font)
-        
+
     def get_state(self):
         return self._state_stack[-1]
 
@@ -2214,7 +2231,7 @@
 
     def customspace(self, s, loc, toks):
         return [self._make_space(float(toks[1]))]
-    
+
     def symbol(self, s, loc, toks):
         # print "symbol", toks
         c = toks[0]
@@ -2240,7 +2257,7 @@
         # (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()
@@ -2251,7 +2268,7 @@
             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]
@@ -2265,19 +2282,19 @@
         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',
@@ -2601,7 +2618,7 @@
     return is width, height, fonts
     """
     _parser = None
-    
+
     _backend_mapping = {
         'Bitmap': MathtextBackendBitmap,
         'Agg'   : MathtextBackendAgg,
@@ -2611,6 +2628,13 @@
         'Cairo' : MathtextBackendCairo
         }
 
+    _font_type_mapping = {
+        'cm'       : BakomaFonts,
+        'stix'     : StixFonts,
+        'stixsans' : StixSansFonts,
+        'custom'   : UnicodeFonts
+        }
+
     def __init__(self, output):
         self._output = output
         self._cache = {}
@@ -2618,7 +2642,7 @@
     def parse(self, s, dpi = 72, prop = None):
         if prop is None:
             prop = FontProperties()
-        
+
         cacheKey = (s, dpi, hash(prop))
         result = self._cache.get(cacheKey)
         if result is not None:
@@ -2629,16 +2653,13 @@
         else:
             backend = self._backend_mapping[self._output]()
             fontset = rcParams['mathtext.fontset']
-            if fontset == 'cm':
-                font_output = BakomaFonts(prop, backend)
-            elif fontset == 'stix':
-                font_output = StixFonts(prop, backend)
-            elif fontset == 'stixsans':
-                font_output = StixFonts(prop, backend, sans=True)
-            elif fontset == 'custom':
-                font_output = UnicodeFonts(prop, backend)
+            fontset_class = self._font_type_mapping.get(fontset)
+            if fontset_class is not None:
+                font_output = fontset_class(prop, backend)
             else:
-                raise ValueError("mathtext.fontset must be either 'cm', 
'stix', 'stixsans', or 'custom'")
+                raise ValueError(
+                    "mathtext.fontset must be either 'cm', 'stix', "
+                    "'stixsans', or 'custom'")
 
         fontsize = prop.get_size_in_points()
 
@@ -2646,7 +2667,7 @@
         # with each request.
         if self._parser is None:
             self.__class__._parser = Parser()
-            
+
         box = self._parser.parse(s, font_output, fontsize, dpi)
         font_output.set_canvas_size(box.width, box.height, box.depth)
         result = font_output.get_results(box)
@@ -2658,5 +2679,5 @@
         font_output.destroy()
         font_output.mathtext_backend.fonts_object = None
         font_output.mathtext_backend = None
-        
+
         return result


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: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to