8000 Fix problem with AFM files that don't specify the font's full name or… · cirosantilli/matplotlib@72c10b4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 72c10b4

Browse files
committed
Fix problem with AFM files that don't specify the font's full name or family name
svn path=/branches/v0_91_maint/; revision=6149
1 parent 15a4174 commit 72c10b4

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

API_CHANGES

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
AFM.get_fullname() and get_familyname() no longer raise an
2+
exception if the AFM file does not specify these optional
3+
attributes, but returns a guess based on the required FontName
4+
attribute.
5+
16
Deprecated all mlab2 functions in mlab
27

38
matplotlib.image.imread now no longer always returns RGBA -- if

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2008-10-05 Fix problem with AFM files that don't specify the font's
2+
full name or family name. - JKS
3+
14
2008-09-11 Fix use of backticks in PS - MGD
25

36
2008-09-07 Changed full arrows slightly to avoid an xpdf rendering

lib/matplotlib/afm.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
John D. Hunter <jdhunter@ace.bsd.uchicago.edu>
3535
"""
3636

37-
import sys, os
37+
import sys, os, re
3838
from _mathtext_data import uni2type1
3939

4040
#Convert string the a python type
@@ -433,11 +433,21 @@ def get_fontname(self):
433433

434434
def get_fullname(self):
435435
"Return the font full name, eg, Times-Roman"
436-
return self._header['FullName']
436+
name = self._header.get('FullName')
437+
if name is None: # use FontName as a substitute
438+
name = self._header['FontName']
439+
return name
437440

438441
def get_familyname(self):
439442
"Return the font family name, eg, Times"
440-
return self._header['FamilyName']
443+
name = self._header.get('FamilyName')
444+
if name is not None:
445+
return name
446+
447+
# FamilyName not specified so we'll make a guess
448+
name = self.get_fullname()
449+
extras = r'(?i)([ -](regular|plain|italic|oblique|bold|semibold|light|ultralight|extra|condensed))+$'
450+
return re.sub(extras, '', name)
441451

442452
def get_weight(self):
443453
"Return the font weight, eg, 'Bold' or 'Roman'"

0 commit comments

Comments
 (0)
0