The PDF backend breaks when the setting pdf.use14corefonts=True is
used. You'll find a test case reproducing this bug in the attached
file 'test_pdf_use14corefonts.py'.

This setting is very useful because it produces very lightweight PDF
files. The files are lightweight because they only use the 14 core
fonts built in every PDF viewers (like Helvetica and Times).

Attached to this email is a patch against the current trunk containing
the bug fix and the related test case. Do you agree to commit it?

Thanks,

Nicolas Grilly
Index: unit/test_pdf_use14corefonts.py
===================================================================
--- unit/test_pdf_use14corefonts.py	(révision 0)
+++ unit/test_pdf_use14corefonts.py	(révision 0)
@@ -0,0 +1,25 @@
+# encoding: utf-8
+
+import matplotlib
+matplotlib.use('PDF')
+
+from matplotlib import rcParams
+import pylab
+
+rcParams['pdf.use14corefonts'] = True
+rcParams['font.family'] = 'sans-serif'
+rcParams['font.size'] = 8
+rcParams['font.sans-serif'] = ['Helvetica']
+
+title = u'Test PDF backend with option use14corefonts=True'
+
+text = u'''A three lines text positionned just above a blue line
+and containing some french characters and the euro symbol:
+"Merci pépé pour les 10 €"'''
+
+pylab.figure(figsize=(6, 4))
+pylab.title(title)
+pylab.text(0.5, 0.5, text, horizontalalignment='center')
+pylab.axhline(0.5, linewidth=0.5)
+pylab.savefig('test.pdf')
+pylab.close()

Index: CHANGELOG
===================================================================
--- CHANGELOG	(révision 6903)
+++ CHANGELOG	(copie de travail)
@@ -1,3 +1,7 @@
+2009-02-10 Fixed a bug in backend_pdf so it doesn't break when the setting
+           pdf.use14corefonts=True is used. Added test case in
+           unit/test_pdf_use14corefonts.py. - NGR
+
 2009-02-08 Added a new imsave function to image.py and exposed it in
            the pyplot interface - GR
 
Index: lib/matplotlib/backends/backend_pdf.py
===================================================================
--- lib/matplotlib/backends/backend_pdf.py	(révision 6903)
+++ lib/matplotlib/backends/backend_pdf.py	(copie de travail)
@@ -1465,7 +1465,7 @@
             self.draw_path(boxgc, path, mytrans, gc._rgb)
 
     def encode_string(self, s, fonttype):
-        if fonttype == 3:
+        if fonttype in (1, 3):
             return s.encode('cp1252', 'replace')
         return s.encode('utf-16be', 'replace')
 
@@ -1492,7 +1492,7 @@
             font = self._get_font_afm(prop)
             l, b, w, h = font.get_str_bbox(s)
             descent = -b * fontsize / 1000
-            fonttype = 42
+            fonttype = 1
         else:
             font = self._get_font_ttf(prop)
             self.track_characters(font, s)
@@ -1627,9 +1627,9 @@
             font = self._get_font_afm(prop)
             l, b, w, h, d = font.get_str_bbox_and_descent(s)
             scale = prop.get_size_in_points()
-            w *= scale
-            h *= scale
-            d *= scale
+            w *= scale / 1000
+            h *= scale / 1000
+            d *= scale / 1000
         else:
             font = self._get_font_ttf(prop)
             font.set_text(s, 0.0, flags=LOAD_NO_HINTING)
# encoding: utf-8

import matplotlib
matplotlib.use('PDF')

from matplotlib import rcParams
import pylab

rcParams['pdf.use14corefonts'] = True
rcParams['font.family'] = 'sans-serif'
rcParams['font.size'] = 8
rcParams['font.sans-serif'] = ['Helvetica']

title = u'Test PDF backend with option use14corefonts=True'

text = u'''A three lines text positionned just above a blue line
and containing some french characters and the euro symbol:
"Merci pépé pour les 10 €"'''

pylab.figure(figsize=(6, 4))
pylab.title(title)
pylab.text(0.5, 0.5, text, horizontalalignment='center')
pylab.axhline(0.5, linewidth=0.5)
pylab.savefig('test.pdf')
pylab.close()
------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to