Revision: 7273
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7273&view=rev
Author:   evilguru
Date:     2009-07-19 21:33:18 +0000 (Sun, 19 Jul 2009)

Log Message:
-----------
Port over the Cairo backend to mathtex. Just PS and OS X left.

Modified Paths:
--------------
    branches/mathtex/lib/matplotlib/backends/backend_cairo.py

Modified: branches/mathtex/lib/matplotlib/backends/backend_cairo.py
===================================================================
--- branches/mathtex/lib/matplotlib/backends/backend_cairo.py   2009-07-19 
13:35:15 UTC (rev 7272)
+++ branches/mathtex/lib/matplotlib/backends/backend_cairo.py   2009-07-19 
21:33:18 UTC (rev 7273)
@@ -42,12 +42,14 @@
      FigureManagerBase, FigureCanvasBase
 from matplotlib.cbook        import is_string_like
 from matplotlib.figure       import Figure
-from matplotlib.mathtext     import MathTextParser
 from matplotlib.path         import Path
 from matplotlib.transforms   import Bbox, Affine2D
 from matplotlib.font_manager import ttfFontProperty
 from matplotlib import rcParams
 
+from mathtex.mathtex_main import Mathtex
+from mathtex.backends.backend_cairo import MathtexBackendCairo
+
 _debug = False
 #_debug = True
 
@@ -94,7 +96,6 @@
         self.gc = GraphicsContextCairo (renderer=self)
         self.text_ctx = cairo.Context (
            cairo.ImageSurface (cairo.FORMAT_ARGB32,1,1))
-        self.mathtext_parser = MathTextParser('Cairo')
 
     def set_ctx_from_surface (self, surface):
         self.gc.ctx = cairo.Context (surface)
@@ -203,35 +204,18 @@
         if _debug: print '%s.%s()' % (self.__class__.__name__, _fn_name())
 
         ctx = gc.ctx
-        width, height, descent, glyphs, rects = self.mathtext_parser.parse(
-            s, self.dpi, prop)
 
+        m = Mathtex(s, rcParams['mathtext.fontset'], 
prop.get_size_in_points(), self.dpi)
+        b = MathtexBackendCairo()
+        m.render_to_backend(b)
+
         ctx.save()
-        ctx.translate(x, y)
+        ctx.translate(x, y - m.height - m.depth)
         if angle:
            ctx.rotate (-angle * npy.pi / 180)
 
-        for font, fontsize, s, ox, oy in glyphs:
-           ctx.new_path()
-           ctx.move_to(ox, oy)
+        b.render_to_context(ctx)
 
-           fontProp = ttfFontProperty(font)
-           ctx.save()
-           ctx.select_font_face (fontProp.name,
-                                 self.fontangles [fontProp.style],
-                                 self.fontweights[fontProp.weight])
-
-           size = fontsize * self.dpi / 72.0
-           ctx.set_font_size(size)
-           ctx.show_text(s.encode("utf-8"))
-           ctx.restore()
-
-        for ox, oy, w, h in rects:
-           ctx.new_path()
-           ctx.rectangle (ox, oy, w, h)
-           ctx.set_source_rgb (0, 0, 0)
-           ctx.fill_preserve()
-
         ctx.restore()
 
 
@@ -250,9 +234,8 @@
     def get_text_width_height_descent(self, s, prop, ismath):
         if _debug: print '%s.%s()' % (self.__class__.__name__, _fn_name())
         if ismath:
-            width, height, descent, fonts, used_characters = 
self.mathtext_parser.parse(
-               s, self.dpi, prop)
-            return width, height, descent
+            m = Mathtex(s, rcParams['mathtext.fontset'], 
prop.get_size_in_points(), self.dpi)
+            return m.width, m.height, m.depth
 
         ctx = self.text_ctx
         ctx.save()


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

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to