Revision: 6296
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6296&view=rev
Author:   mdboom
Date:     2008-10-22 17:51:36 +0000 (Wed, 22 Oct 2008)

Log Message:
-----------
Fix text alignment in PDF backend.  (At suggestion of Stan West).

Modified Paths:
--------------
    trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py

Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py     2008-10-22 
17:29:41 UTC (rev 6295)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py     2008-10-22 
17:51:36 UTC (rev 6296)
@@ -1268,14 +1268,15 @@
                 lastx, lasty = x, y
         output(Op.grestore)
 
-    def _setup_textpos(self, x, y, angle, oldx=0, oldy=0, oldangle=0):
+    def _setup_textpos(self, x, y, descent, angle, oldx=0, oldy=0, 
olddescent=0, oldangle=0):
         if angle == oldangle == 0:
-            self.file.output(x - oldx, y - oldy, Op.textpos)
+            self.file.output(x - oldx, (y + descent) - (oldy + olddescent), 
Op.textpos)
         else:
             angle = angle / 180.0 * pi
             self.file.output( cos(angle), sin(angle),
                              -sin(angle), cos(angle),
                               x,        y,         Op.textmatrix)
+            self.file.output(0, descent, Op.textpos)
 
     def draw_mathtext(self, gc, x, y, s, prop, angle):
         # TODO: fix positioning and encoding
@@ -1305,7 +1306,7 @@
                 fonttype = global_fonttype
 
             if fonttype == 42 or num <= 255:
-                self._setup_textpos(ox, oy, 0, oldx, oldy)
+                self._setup_textpos(ox, oy, 0, 0, oldx, oldy)
                 oldx, oldy = ox, oy
                 if (fontname, fontsize) != prev_font:
                     fontsize *= self.dpi/72.0
@@ -1398,7 +1399,7 @@
                 self.file.output(elt[1], elt[2], Op.selectfont)
             elif elt[0] == 'text':
                 curx, cury = mytrans.transform((elt[1], elt[2]))
-                self._setup_textpos(curx, cury, angle, oldx, oldy)
+                self._setup_textpos(curx, cury, 0, angle, oldx, oldy)
                 oldx, oldy = curx, cury
                 if len(elt[3]) == 1:
                     self.file.output(elt[3][0], Op.show)
@@ -1447,13 +1448,13 @@
         if rcParams['pdf.use14corefonts']:
             font = self._get_font_afm(prop)
             l, b, w, h = font.get_str_bbox(s)
-            y -= b * fontsize / 1000
+            descent = -b * fontsize / 1000
             fonttype = 42
         else:
             font = self._get_font_ttf(prop)
             self.track_characters(font, s)
             font.set_text(s, 0.0, flags=LOAD_NO_HINTING)
-            y += font.get_descent() / 64.0
+            descent = font.get_descent() / 64.0
 
             fonttype = rcParams['pdf.fonttype']
 
@@ -1493,7 +1494,7 @@
                              self.file.fontName(prop),
                              fontsize,
                              Op.selectfont)
-            self._setup_textpos(x, y, angle)
+            self._setup_textpos(x, y, descent, angle)
             self.file.output(self.encode_string(s, fonttype), Op.show, 
Op.end_text)
 
         def draw_text_woven(chunks):
@@ -1514,6 +1515,7 @@
             # output all the 2-byte characters.
             for mode in (1, 2):
                 newx = oldx = 0
+                olddescent = 0
                 # Output a 1-byte character chunk
                 if mode == 1:
                     self.file.output(Op.begin_text,
@@ -1523,9 +1525,10 @@
 
                 for chunk_type, chunk in chunks:
                     if mode == 1 and chunk_type == 1:
-                        self._setup_textpos(newx, 0, 0, oldx, 0, 0)
+                        self._setup_textpos(newx, 0, descent, 0, oldx, 0, 
olddescent, 0)
                         self.file.output(self.encode_string(chunk, fonttype), 
Op.show)
                         oldx = newx
+                        olddescent = descent
 
                     lastgind = None
                     for c in chunk:


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 the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to