Re: [Matplotlib-users] Problem in afm.py with 0.98.3

2008-10-05 Thread Jouni K . Seppänen
[EMAIL PROTECTED] (Berthold
Höllmann) writes:

> (Pdb) print self._header
> {'Notice': 'Copyright (c) 1999 Ministry of Education, Taipei, Taiwan. All 
> Rights Reserved.', 'Ascender': 880.0, 'FontBBox': [-123, -250, 1000, 880], 
> 'Weight': 'Regular', 'Descender': -250.0, 'CharacterSet': 'Adobe-CNS1-0', 
> 'IsFixedPitch': False, 'FontName': 'MOEKai-Regular', 'StartFontMetrics': 
> 4.0996, 'CapHeight': 880.0, 'Version': '1.000', 
> 'UnderlinePosition': -100, 'Characters': 13699, 'UnderlineThickness': 50, 
> 'ItalicAngle': 0.0, 'StartCharMetrics': 13699}

That AFM file doesn't include a family name or a full name for the font
it describes. It seems that both are in fact optional attributes. I have
committed a change (on the trunk, and in the maintenance branch) that
should fix this, but since I don't have any AFM files like this, I can't
check that it works. Can you check out either the trunk or the
maintenance branch from Subversion, or apply the following patch and try
again?

-- 
Jouni K. Seppänen
http://www.iki.fi/jks

Index: lib/matplotlib/afm.py
===
--- lib/matplotlib/afm.py	(revision 6149)
+++ lib/matplotlib/afm.py	(revision 6150)
@@ -34,7 +34,7 @@
   John D. Hunter <[EMAIL PROTECTED]>
 """
 
-import sys, os
+import sys, os, re
 from _mathtext_data import uni2type1
 
 #Convert string the a python type
@@ -433,12 +433,22 @@
 
 def get_fullname(self):
 "Return the font full name, eg, 'Times-Roman'"
-return self._header['FullName']
+name = self._header.get('FullName')
+if name is None: # use FontName as a substitute
+name = self._header['FontName']
+return name
 
 def get_familyname(self):
 "Return the font family name, eg, 'Times'"
-return self._header['FamilyName']
+name = self._header.get('FamilyName')
+if name is not None:
+return name
 
+# FamilyName not specified so we'll make a guess
+name = self.get_fullname()
+extras = r'(?i)([ -](regular|plain|italic|oblique|bold|semibold|light|ultralight|extra|condensed))+$'
+return re.sub(extras, '', name)
+
 def get_weight(self):
 "Return the font weight, eg, 'Bold' or 'Roman'"
 return self._header['Weight']
-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Problem in afm.py with 0.98.3

2008-10-04 Thread Berthold Höllmann

I have a problem with every matplot version since 0.90.1. One of my
installed fonts causes afm.py to bail out. I am sure I reported this
problem before without reaction. After I installed python 1.6 and a
recent numpy 0.90.1 does not work anymore so I tried the latest again,
and get the afm error again:

> python -i -c "from matplotlib import pylab"
/usr/local/lib/python2.6/site-packages/matplotlib-0.98.3-py2.6-linux-i686.egg/matplotlib/__init__.py:96:
 DeprecationWarning: the md5 module is deprecated; use hashlib instead
  import md5, os, re, shutil, sys, warnings
/usr/local/lib/python2.6/site-packages/matplotlib-0.98.3-py2.6-linux-i686.egg/pytz/tzinfo.py:5:
 DeprecationWarning: the sets module is deprecated
  from sets import Set
Found an unknown keyword in AFM header (was MetricsSets)
Found an unknown keyword in AFM header (was IsBaseFont)
Found an unknown keyword in AFM header (was IsCIDFont)
Found an unknown keyword in AFM header (was StartDirection)
Found an unknown keyword in AFM header (was EndDirection)
Traceback (most recent call last):
  File "", line 1, in 
  File 
"/usr/local/lib/python2.6/site-packages/matplotlib-0.98.3-py2.6-linux-i686.egg/matplotlib/pylab.py",
 line 206, in 
from matplotlib import mpl  # pulls in most modules
  File 
"/usr/local/lib/python2.6/site-packages/matplotlib-0.98.3-py2.6-linux-i686.egg/matplotlib/mpl.py",
 line 2, in 
from matplotlib import axis
  File 
"/usr/local/lib/python2.6/site-packages/matplotlib-0.98.3-py2.6-linux-i686.egg/matplotlib/axis.py",
 line 9, in 
import matplotlib.font_manager as font_manager
  File 
"/usr/local/lib/python2.6/site-packages/matplotlib-0.98.3-py2.6-linux-i686.egg/matplotlib/font_manager.py",
 line 1129, in 
_rebuild()
  File 
"/usr/local/lib/python2.6/site-packages/matplotlib-0.98.3-py2.6-linux-i686.egg/matplotlib/font_manager.py",
 line 1120, in _rebuild
fontManager = FontManager()
  File 
"/usr/local/lib/python2.6/site-packages/matplotlib-0.98.3-py2.6-linux-i686.egg/matplotlib/font_manager.py",
 line 910, in __init__
self.afmdict = createFontDict(self.afmfiles, fontext='afm')
  File 
"/usr/local/lib/python2.6/site-packages/matplotlib-0.98.3-py2.6-linux-i686.egg/matplotlib/font_manager.py",
 line 521, in createFontDict
prop = afmFontProperty(font)
  File 
"/usr/local/lib/python2.6/site-packages/matplotlib-0.98.3-py2.6-linux-i686.egg/matplotlib/font_manager.py",
 line 420, in afmFontProperty
name = font.get_familyname()
  File 
"/usr/local/lib/python2.6/site-packages/matplotlib-0.98.3-py2.6-linux-i686.egg/matplotlib/afm.py",
 line 440, in get_familyname
return self._header['FamilyName']
KeyError: 'FamilyName'
>>> import pdb
>>> pdb.pm()
> /usr/local/lib/python2.6/site-packages/matplotlib-0.98.3-py2.6-linux-i686.egg/matplotlib/afm.py(440)get_familyname()
-> return self._header['FamilyName']
(Pdb) print self._header
{'Notice': 'Copyright (c) 1999 Ministry of Education, Taipei, Taiwan. All 
Rights Reserved.', 'Ascender': 880.0, 'FontBBox': [-123, -250, 1000, 880], 
'Weight': 'Regular', 'Descender': -250.0, 'CharacterSet': 'Adobe-CNS1-0', 
'IsFixedPitch': False, 'FontName': 'MOEKai-Regular', 'StartFontMetrics': 
4.0996, 'CapHeight': 880.0, 'Version': '1.000', 
'UnderlinePosition': -100, 'Characters': 13699, 'UnderlineThickness': 50, 
'ItalicAngle': 0.0, 'StartCharMetrics': 13699}
(Pdb) 

What is there to do?

Regards
Berthold

-- 
A: Weil es die Lesbarkeit des Textes verschlechtert.
F: Warum ist TOFU so schlimm?
A: TOFU
F: Was ist das größte Ärgernis im Usenet?

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users