Revision: 3831
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3831&view=rev
Author:   mdboom
Date:     2007-09-11 10:57:47 -0700 (Tue, 11 Sep 2007)

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

........
  r3825 | pkienzle | 2007-09-10 14:45:32 -0400 (Mon, 10 Sep 2007) | 1 line
  
  Windows needs binary open flag for font files
........
  r3827 | jouni | 2007-09-10 16:31:01 -0400 (Mon, 10 Sep 2007) | 2 lines
  
  Better bounding boxes for pdf usetex, including descents.
........
  r3828 | jouni | 2007-09-10 16:55:29 -0400 (Mon, 10 Sep 2007) | 2 lines
  
  Bugfixes in pdf usetex
........
  r3829 | mdboom | 2007-09-11 08:46:27 -0400 (Tue, 11 Sep 2007) | 3 lines
  
  Fix bug in PDF clip routine that resulted in the cryptic error message
  "There are too many arguments" in Adobe Acrobat.
........

Modified Paths:
--------------
    branches/transforms/lib/matplotlib/backends/backend_pdf.py
    branches/transforms/lib/matplotlib/dviread.py
    branches/transforms/ttconv/pprdrv_tt.cpp

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


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

Modified: branches/transforms/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- branches/transforms/lib/matplotlib/backends/backend_pdf.py  2007-09-11 
17:56:13 UTC (rev 3830)
+++ branches/transforms/lib/matplotlib/backends/backend_pdf.py  2007-09-11 
17:57:47 UTC (rev 3831)
@@ -519,12 +519,13 @@
             ul_position, ul_thickness = font.get_ps_font_info()
 
         if fontinfo.encodingfile is not None:
-            differencesArray = [ Name(ch) for ch in  
-                                 dviread.Encoding(fontinfo.encodingfile) ]
+            enc = dviread.Encoding(fontinfo.encodingfile)
+            widths = [ afmdata.get_width_from_char_name(ch)
+                       for ch in enc ]
+            differencesArray = [ Name(ch) for ch in enc ]
             differencesArray = [ 0 ] + differencesArray
             firstchar = 0
             lastchar = len(differencesArray) - 2
-            widths = [ 100 for x in range(firstchar,lastchar+1) ] # XXX TODO
         else:
             widths = [ None for i in range(256) ]
             for ch in range(256):
@@ -1434,7 +1435,7 @@
         fontsize = prop.get_size_in_points()
         dvifile = texmanager.make_dvi(s, fontsize)
         dvi = dviread.Dvi(dvifile, 72)
-        text, boxes = iter(dvi).next()
+        page = iter(dvi).next()
         dvi.close()
 
         if angle == 0:          # avoid rounding errors in common case
@@ -1448,7 +1449,7 @@
         # Gather font information and do some setup for combining
         # characters into strings.
         oldfontnum, seq = None, []
-        for x1, y1, fontnum, glyph, width in text:
+        for x1, y1, fontnum, glyph, width in page.text:
             if fontnum != oldfontnum:
                 texname, fontsize = dvi.fontinfo(fontnum)
                 fontinfo = self.tex_font_mapping(texname)
@@ -1462,8 +1463,8 @@
         seq += [('end',)]
 
         # Find consecutive text strings with constant x coordinate and
-        # combine into one string (if needed kern would be less than
-        # 0.1 points) or several strings interspersed with kerns.
+        # combine into a sequence of strings and kerns, or just one
+        # string (if any kerns would be less than 0.1 points).
         i, curx = 0, 0
         while i < len(seq)-1:
             elt, next = seq[i:i+2]
@@ -1503,7 +1504,7 @@
         boxgc = self.new_gc()
         boxgc.copy_properties(gc)
         boxgc.set_linewidth(0)
-        for x1, y1, h, w in boxes:
+        for x1, y1, h, w in page.boxes:
             (x1, y1), (x2, y2), (x3, y3), (x4, y4) = \
                 mytrans(x1, y1), mytrans(x1+w, y1), \
                 mytrans(x1+w, y1+h), mytrans(x1, y1+h)
@@ -1653,14 +1654,9 @@
             fontsize = prop.get_size_in_points()
             dvifile = texmanager.make_dvi(s, fontsize)
             dvi = dviread.Dvi(dvifile, 72)
-            text, boxes = iter(dvi).next()
-            # TODO: better bounding box -- this is not quite right:
-            l = min(p[0] for p in text+boxes)
-            r = max(p[0] for p in text+boxes) + fontsize
-            b = min(p[1] for p in text+boxes)
-            t = max(p[1] for p in text+boxes) + fontsize
-            # (not to even mention finding the baseline)
-            return r-l, t-b, t-b
+            page = iter(dvi).next()
+            dvi.close()
+            return page.width, page.height, page.descent
         if ismath:
             w, h, d, glyphs, rects, used_characters = \
                 self.mathtext_parser.parse(s, 72, prop)
@@ -1837,7 +1833,7 @@
             cmds.extend(self.pop())
         # Unless we hit the right one, set the clip polygon
         if (self._cliprect, self._clippath) != (cliprect, clippath):
-            cmds.append(self.push())
+            cmds.extend(self.push())
             if self._cliprect != cliprect:
                 cmds.extend([t for t in cliprect] + 
                             [Op.rectangle, Op.clip, Op.endpath])

Modified: branches/transforms/lib/matplotlib/dviread.py
===================================================================
--- branches/transforms/lib/matplotlib/dviread.py       2007-09-11 17:56:13 UTC 
(rev 3830)
+++ branches/transforms/lib/matplotlib/dviread.py       2007-09-11 17:57:47 UTC 
(rev 3831)
@@ -6,19 +6,21 @@
 Interface:
 
     dvi = Dvi(filename, 72)
-    for text, boxes in dvi:          # iterate over pages
-        text, boxes = dvi.output(72)
-        for x,y,font,glyph,width in text:
+    for page in dvi:          # iterate over pages
+        w, h, d = page.width, page.height, page.descent
+        for x,y,font,glyph,width in page.text:
             fontname, pointsize = dvi.fontinfo(font)
             ...
-        for x,y,height,width in boxes:
+        for x,y,height,width in page.boxes:
             ...
 """
 
-# TODO: support for TeX virtual fonts (*.vf) which are a dvi-like format
+# TODO: support TeX virtual fonts (*.vf) which are a sort of
+#       subroutine collections for dvi files
 
 import matplotlib
 import matplotlib.cbook as mpl_cbook
+import numpy as npy
 import os
 import struct
 
@@ -74,21 +76,34 @@
     def _output(self):
         """
         Output the text and boxes belonging to the most recent page.
-        text, boxes = dvi._output()
+        page = dvi._output()
         """
-        t0 = self.text[0]
-        minx, miny, maxx, maxy = t0[0], t0[1], t0[0], t0[1]
+        minx, miny, maxx, maxy = npy.inf, npy.inf, -npy.inf, -npy.inf
+        maxy_pure = -npy.inf
         for elt in self.text + self.boxes:
-            x,y = elt[:2]
-            if x < minx: minx = x
-            if y < miny: miny = y
-            if x > maxx: maxx = x
-            if y > maxy: maxy = y
+            if len(elt) == 4:   # box
+                x,y,h,w = elt
+                e = 0           # zero depth
+            else:               # glyph
+                x,y,f,g,w = elt
+                font = self.fonts[f]
+                h = (font.scale * font.tfm.height[g]) >> 20
+                e = (font.scale * font.tfm.depth[g]) >> 20
+            minx = min(minx, x)
+            miny = min(miny, y - h)
+            maxx = max(maxx, x + w)
+            maxy = max(maxy, y + e)
+            maxy_pure = max(maxy_pure, y)
+
         d = self.dpi / (72.27 * 2**16) # from TeX's "scaled points" to dpi 
units
         text =  [ ((x-minx)*d, (maxy-y)*d, f, g, w*d) for (x,y,f,g,w) in 
self.text ]
         boxes = [ ((x-minx)*d, (maxy-y)*d, h*d, w*d) for (x,y,h,w) in 
self.boxes ]
-        return text, boxes
 
+        return mpl_cbook.Bunch(text=text, boxes=boxes, 
+                               width=(maxx-minx)*d, 
+                               height=(maxy_pure-miny)*d, 
+                               descent=(maxy-maxy_pure)*d)
+
     def fontinfo(self, f):
         """
         texname, pointsize = dvi.fontinfo(fontnum)
@@ -361,6 +376,7 @@
       width[i]: width of character #i, needs to be scaled 
         by the factor specified in the dvi file
         (this is a dict because indexing may not start from 0)
+      height[i], depth[i]: height and depth of character #i
     """
 
     def __init__(self, filename):
@@ -368,22 +384,29 @@
 
         try:
             header1 = file.read(24)
-            lh, bc, ec, nw = \
-                struct.unpack('!4H', header1[2:10])
+            lh, bc, ec, nw, nh, nd = \
+                struct.unpack('!6H', header1[2:14])
             header2 = file.read(4*lh)
             self.checksum, self.design_size = \
                 struct.unpack('!2I', header2[:8])
             # there is also encoding information etc.
             char_info = file.read(4*(ec-bc+1))
             widths = file.read(4*nw)
+            heights = file.read(4*nh)
+            depths = file.read(4*nd)
         finally:
             file.close()
 
-        widths = struct.unpack('!%dI' % nw, widths)
-        self.width = {}
+        self.width, self.height, self.depth = {}, {}, {}
+        widths, heights, depths = \
+            [ struct.unpack('!%dI' % n, x) 
+              for n,x in [(nw, widths), (nh, heights), (nd, depths)] ]
         for i in range(ec-bc):
             self.width[bc+i] = widths[ord(char_info[4*i])]
+            self.height[bc+i] = heights[ord(char_info[4*i+1]) >> 4]
+            self.depth[bc+i] = depths[ord(char_info[4*i+1]) & 0xf]
 
+
 class PsfontsMap(object):
     """
     A psfonts.map formatted file, mapping TeX fonts to PS fonts.

Modified: branches/transforms/ttconv/pprdrv_tt.cpp
===================================================================
--- branches/transforms/ttconv/pprdrv_tt.cpp    2007-09-11 17:56:13 UTC (rev 
3830)
+++ branches/transforms/ttconv/pprdrv_tt.cpp    2007-09-11 17:57:47 UTC (rev 
3831)
@@ -1088,7 +1088,7 @@
     font.filename=filename;
 
     /* Open the font file */
-    if( (font.file = fopen(filename,"r")) == (FILE*)NULL )
+    if( (font.file = fopen(filename,"rb")) == (FILE*)NULL )
        throw TTException("Failed to open TrueType font");
 
     /* Allocate space for the unvarying part of the offset table. */


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
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to