Revision: 4493
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4493&view=rev
Author:   mdboom
Date:     2007-11-28 12:36:22 -0800 (Wed, 28 Nov 2007)

Log Message:
-----------
Fix PDF font size bug.

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

Modified: branches/transforms/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- branches/transforms/lib/matplotlib/backends/backend_pdf.py  2007-11-28 
20:13:47 UTC (rev 4492)
+++ branches/transforms/lib/matplotlib/backends/backend_pdf.py  2007-11-28 
20:36:22 UTC (rev 4493)
@@ -175,7 +175,7 @@
     # A bounding box
     elif isinstance(obj, BboxBase):
         return fill([pdfRepr(val) for val in obj.bounds])
-    
+
     else:
         raise TypeError, \
             "Don't know a PDF representation for %s objects." \
@@ -341,7 +341,7 @@
             self.passed_in_file_object = True
         else:
             raise ValueError("filename must be a path or a file-like object")
-        
+
         self.fh = fh
         self.currentstream = None # stream object to write to, if any
         fh.write("%PDF-1.4\n")    # 1.4 is the first version to have alpha
@@ -530,7 +530,7 @@
 
         firstchar = 0
         lastchar = len(fontinfo.widths) - 1
-        
+
         fontdict = {
             'Type':           Name('Font'),
             'Subtype':        Name('Type1'),
@@ -575,7 +575,7 @@
             'XHeight':     500, # TODO: this one too
             'FontFile':    fontfileObject,
             'FontFamily':  familyname,
-            'StemV':       50, # TODO 
+            'StemV':       50, # TODO
             # (see also revision 3874; but not all TeX distros have AFM files!)
             #'FontWeight': a number where 400 = Regular, 700 = Bold
             }
@@ -620,7 +620,7 @@
 CMapName currentdict /CMap defineresource pop
 end
 end"""
-    
+
     def embedTTF(self, filename, characters):
         """Embed the TTF font from the named file into the document."""
 
@@ -833,7 +833,7 @@
             unicode_cmap = (self._identityToUnicodeCMap %
                             (len(unicode_groups),
                              "\n".join(unicode_bfrange)))
-                
+
             # CIDToGIDMap stream
             cid_to_gid_map = "".join(cid_to_gid_map).encode("utf-16be")
             self.beginStream(cidToGidMapObject.id,
@@ -848,7 +848,7 @@
                              {'Length': unicode_cmap})
             self.currentstream.write(unicode_cmap)
             self.endStream()
-            
+
             descriptor['MaxWidth'] = max_width
 
             # Write everything out
@@ -902,7 +902,7 @@
             warnings.warn(("'%s' can not be subsetted into a Type 3 font. " +
                            "The entire font will be embedded in the output.") %
                            os.path.basename(filename))
-        
+
         if fonttype == 3:
             return embedTTFType3(font, characters, descriptor)
         elif fonttype == 42:
@@ -1054,7 +1054,7 @@
                      'SMask': smaskObject})
                 self.currentstream.write(data) # TODO: predictors (i.e., 
output png)
                 self.endStream()
-                
+
             img.flipud_out()
 
     def markerObject(self, path, trans, fillp, lw):
@@ -1068,7 +1068,7 @@
         else:
             name = result[0]
         return name
-    
+
     def writeMarkers(self):
         for tup in self.markers.values():
             name, object, path, trans, fillp, lw = tup
@@ -1088,7 +1088,7 @@
     [EMAIL PROTECTED]
     def pathOperations(path, transform):
         tpath = transform.transform_path(path)
-        
+
         cmds = []
         for points, code in tpath.iter_segments():
             if code == Path.MOVETO:
@@ -1109,11 +1109,11 @@
                 cmds.append(Op.closepath)
         return cmds
     pathOperations = staticmethod(pathOperations)
-            
+
     def writePath(self, path, transform):
         cmds = self.pathOperations(path, transform)
         self.output(*cmds)
-        
+
     def reserveObject(self, name=''):
         """Reserve an ID for an indirect object.
         The name is used for debugging in case we forget to print out
@@ -1249,7 +1249,7 @@
                    marker, Op.use_xobject)
             lastx, lasty = x, y
         output(Op.grestore)
-        
+
     def _setup_textpos(self, x, y, angle, oldx=0, oldy=0, oldangle=0):
         if angle == oldangle == 0:
             self.file.output(x - oldx, y - oldy, Op.textpos)
@@ -1285,11 +1285,12 @@
                 fonttype = 42
             else:
                 fonttype = global_fonttype
-            
+
             if fonttype == 42 or num <= 255:
                 self._setup_textpos(ox, oy, 0, oldx, oldy)
                 oldx, oldy = ox, oy
                 if (fontname, fontsize) != prev_font:
+                    fontsize *= self.dpi/72.0
                     self.file.output(self.file.fontName(fontname), fontsize,
                                      Op.selectfont)
                     prev_font = fontname, fontsize
@@ -1300,11 +1301,12 @@
         # as XObjects using the 'Do' command.
         if global_fonttype == 3:
             for ox, oy, fontname, fontsize, num, symbol_name in glyphs:
+                fontsize *= self.dpi/72.0
                 if is_opentype_cff_font(fontname):
                     fonttype = 42
                 else:
                     fonttype = global_fonttype
-                
+
                 if fonttype == 3 and num > 255:
                     self.file.output(Op.gsave,
                                      0.001 * fontsize, 0,
@@ -1427,7 +1429,7 @@
         self.check_gc(gc, gc._rgb)
         if ismath: return self.draw_mathtext(gc, x, y, s, prop, angle)
 
-        fontsize = prop.get_size_in_points()
+        fontsize = prop.get_size_in_points() * self.dpi/72.0
 
         if rcParams['pdf.use14corefonts']:
             font = self._get_font_afm(prop)
@@ -1441,12 +1443,12 @@
             y += font.get_descent() / 64.0
 
             fonttype = rcParams['pdf.fonttype']
-                
+
             # We can't subset all OpenType fonts, so switch to Type 42
             # in that case.
             if is_opentype_cff_font(font.fname):
                 fonttype = 42
-            
+
         def check_simple_method(s):
             """Determine if we should use the simple or woven method
             to output this text, and chunks the string into 1-byte and
@@ -1476,7 +1478,7 @@
             """Outputs text using the simple method."""
             self.file.output(Op.begin_text,
                              self.file.fontName(prop),
-                             prop.get_size_in_points(),
+                             fontsize,
                              Op.selectfont)
             self._setup_textpos(x, y, angle)
             self.file.output(self.encode_string(s, fonttype), Op.show, 
Op.end_text)
@@ -1503,7 +1505,7 @@
                 if mode == 1:
                     self.file.output(Op.begin_text,
                                      self.file.fontName(prop),
-                                     prop.get_size_in_points(),
+                                     fontsize,
                                      Op.selectfont)
 
                 for chunk_type, chunk in chunks:
@@ -1566,7 +1568,7 @@
         elif rcParams['pdf.use14corefonts']:
             font = self._get_font_afm(prop)
             l, b, w, h, d = font.get_str_bbox_and_descent(s)
-            scale = prop.get_size_in_points() / 1000.0
+            scale = prop.get_size_in_points()
             w *= scale
             h *= scale
             d *= scale
@@ -1574,10 +1576,11 @@
             font = self._get_font_ttf(prop)
             font.set_text(s, 0.0, flags=LOAD_NO_HINTING)
             w, h = font.get_width_height()
-            w /= 64.0
-            h /= 64.0
+            scale = (1.0 / 64.0)
+            w *= scale
+            h *= scale
             d = font.get_descent()
-            d /= 64.0
+            d *= scale
         return w, h, d
 
     def _get_font_afm(self, prop):
@@ -1780,7 +1783,7 @@
                     different = ours.shape != theirs.shape or npy.any(ours != 
theirs)
                 if different:
                     break
-                
+
             if different:
                 theirs = [getattr(other, p) for p in params]
                 cmds.extend(cmd(self, *theirs))
@@ -1841,10 +1844,10 @@
         pass
 
     filetypes = {'pdf': 'Portable Document Format'}
-    
+
     def get_default_filetype(self):
         return 'pdf'
-    
+
     def print_pdf(self, filename, **kwargs):
         dpi = kwargs.get('dpi', 72)
         self.figure.set_dpi(dpi) # Override the dpi kwarg


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

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to