Skip to content

Commit a62bea7

Browse files
committed
Commit Nicolas Grilly's use14corefonts patch
svn path=/trunk/matplotlib/; revision=6904
1 parent dacd9bb commit a62bea7

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

CHANGELOG

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2009-02-10 Fixed a bug in backend_pdf so it doesn't break when the setting
2+
pdf.use14corefonts=True is used. Added test case in
3+
unit/test_pdf_use14corefonts.py. - NGR
4+
15
2009-02-08 Added a new imsave function to image.py and exposed it in
26
the pyplot interface - GR
37

lib/matplotlib/backends/backend_pdf.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1465,7 +1465,7 @@ def draw_tex(self, gc, x, y, s, prop, angle):
14651465
self.draw_path(boxgc, path, mytrans, gc._rgb)
14661466

14671467
def encode_string(self, s, fonttype):
1468-
if fonttype == 3:
1468+
if fonttype in (1, 3):
14691469
return s.encode('cp1252', 'replace')
14701470
return s.encode('utf-16be', 'replace')
14711471

@@ -1492,7 +1492,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
14921492
font = self._get_font_afm(prop)
14931493
l, b, w, h = font.get_str_bbox(s)
14941494
descent = -b * fontsize / 1000
1495-
fonttype = 42
1495+
fonttype = 1
14961496
else:
14971497
font = self._get_font_ttf(prop)
14981498
self.track_characters(font, s)
@@ -1627,9 +1627,9 @@ def get_text_width_height_descent(self, s, prop, ismath):
16271627
font = self._get_font_afm(prop)
16281628
l, b, w, h, d = font.get_str_bbox_and_descent(s)
16291629
scale = prop.get_size_in_points()
1630-
w *= scale
1631-
h *= scale
1632-
d *= scale
1630+
w *= scale / 1000
1631+
h *= scale / 1000
1632+
d *= scale / 1000
16331633
else:
16341634
font = self._get_font_ttf(prop)
16351635
font.set_text(s, 0.0, flags=LOAD_NO_HINTING)

unit/test_pdf_use14corefonts.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# encoding: utf-8
2+
3+
import matplotlib
4+
matplotlib.use('PDF')
5+
6+
from matplotlib import rcParams
7+
import pylab
8+
9+
rcParams['pdf.use14corefonts'] = True
10+
rcParams['font.family'] = 'sans-serif'
11+
rcParams['font.size'] = 8
12+
rcParams['font.sans-serif'] = ['Helvetica']
13+
14+
title = u'Test PDF backend with option use14corefonts=True'
15+
16+
text = u'''A three-line text positioned just above a blue line
17+
and containing some French characters and the euro symbol:
18+
"Merci pépé pour les 10 €"'''
19+
20+
pylab.figure(figsize=(6, 4))
21+
pylab.title(title)
22+
pylab.text(0.5, 0.5, text, horizontalalignment='center')
23+
pylab.axhline(0.5, linewidth=0.5)
24+
pylab.savefig('test_pdf_use14corefonts.pdf')
25+
pylab.close()

0 commit comments

Comments
 (0)