Re: [Matplotlib-users] matplotlib svn bug: Found an unknown keyword in AFM header...?

2007-08-21 Thread Michael Droettboom
Andrew,

I believe this bug was recently discussed on matplotlib-devel and is 
likely related to recent changes in the font manager cache.

http://www.mail-archive.com/[EMAIL PROTECTED]/msg01531.html

I believe it's being looked into, but I haven't seen a resolution 
(unless I missed it).

Cheers,
Mike

Andrew Jaffe wrote:
 Hi All,
 
 I've got Intel OSX 10.4.10 with SVN versions of numpy, scipy and 
 matplotlib.
 
 The latest matplotlib seems to fail on import pylab or ipython 
 -pylab with very many lines of the form
 
 Found an unknown keyword in AFM header (was
 followed either by a legit character or lots of junk.
 
 For what it's worth, I tend to install eggs rather than simple setup.py 
 install; moving back to r3421 which I had prevviously seems to work fine.
 
 Any ideas?
 
 Yours,
 
 Andrew
 
 
 -
 This SF.net email is sponsored by: Splunk Inc.
 Still grepping through log files to find problems?  Stop.
 Now Search log events and configuration files using AJAX and a browser.
 Download your FREE copy of Splunk now   http://get.splunk.com/
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users


-
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now   http://get.splunk.com/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] matplotlib svn bug: Found an unknown keyword in AFM header...?

2007-08-21 Thread Andrew Jaffe
Michael Droettboom wrote:
 Andrew,
 
 I believe this bug was recently discussed on matplotlib-devel and is 
 likely related to recent changes in the font manager cache.
 
 http://www.mail-archive.com/[EMAIL PROTECTED]/msg01531.html
 
 I believe it's being looked into, but I haven't seen a resolution 
 (unless I missed it).

Ah, sorry, this is indeed the same problem.

Adding

pdf.use14corefonts :  True

to matplotlibrc does fix it, FWIW.

Andrew




 Cheers,
 Mike
 
 Andrew Jaffe wrote:
 Hi All,

 I've got Intel OSX 10.4.10 with SVN versions of numpy, scipy and 
 matplotlib.

 The latest matplotlib seems to fail on import pylab or ipython 
 -pylab with very many lines of the form

 Found an unknown keyword in AFM header (was
 followed either by a legit character or lots of junk.

 For what it's worth, I tend to install eggs rather than simple setup.py 
 install; moving back to r3421 which I had prevviously seems to work fine.

 Any ideas?

 Yours,

 Andrew


 -
 This SF.net email is sponsored by: Splunk Inc.
 Still grepping through log files to find problems?  Stop.
 Now Search log events and configuration files using AJAX and a browser.
 Download your FREE copy of Splunk now   http://get.splunk.com/
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users
 
 
 -
 This SF.net email is sponsored by: Splunk Inc.
 Still grepping through log files to find problems?  Stop.
 Now Search log events and configuration files using AJAX and a browser.
 Download your FREE copy of Splunk now   http://get.splunk.com/


-
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now   http://get.splunk.com/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] matplotlib svn bug: Found an unknown keyword in AFM header...?

2007-08-21 Thread Eric Firing
Andrew Jaffe wrote:
 Michael Droettboom wrote:
 Andrew,

 I believe this bug was recently discussed on matplotlib-devel and is 
 likely related to recent changes in the font manager cache.

 http://www.mail-archive.com/[EMAIL PROTECTED]/msg01531.html

 I believe it's being looked into, but I haven't seen a resolution 
 (unless I missed it).
 
 Ah, sorry, this is indeed the same problem.
 
 Adding
 
 pdf.use14corefonts :  True
 
 to matplotlibrc does fix it, FWIW.

It solves the immediate problem for people who run into it, and it 
provides a clue about what the underlying problem is, but it does not 
fully identify or solve that problem.

To make real progress on it, we need an OSX user who understands 
something about font matters--or maybe only enough about OSX to do some 
exploration.

In font_manager.py, in the FontManager class, is the following:

 if rcParams['pdf.use14corefonts']:
 # Load only the 14 PDF core fonts. These fonts do not need 
to be
 # embedded; every PDF viewing application is required to 
have them:
 # Helvetica, Helvetica-Bold, Helvetica-Oblique, 
Helvetica-BoldOblique,
 # Courier, Courier-Bold, Courier-Oblique, Courier-BoldOblique,
 # Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic, 
Symbol,
 # ZapfDingbats.
 afmpath = 
os.path.join(rcParams['datapath'],'fonts','pdfcorefonts')
 afmfiles = findSystemFonts(afmpath, fontext='afm')
 self.afmdict = createFontDict(afmfiles, fontext='afm')
 else:
 self.afmfiles = findSystemFonts(paths, fontext='afm') + \
 findSystemFonts(fontext='afm')
 self.afmdict = createFontDict(self.afmfiles, fontext='afm')


I think that the problem is occurring in the last line.  This remains to 
be verified.  It looks like *.afm files are being found, but when 
createFontDict tries to parse them it doesn't find what it expects.

My guess is that this problem has been lurking all along, but was only 
triggered when I changed font_manager to look for *all* system fonts 
instead of only truetype, so that it could generate a complete cache and 
then never have to search again unless the cache (actually a pickle of 
the FontManager instance) is deleted.

Eric

 
 Andrew
 
 
 
 
 Cheers,
 Mike

 Andrew Jaffe wrote:
 Hi All,

 I've got Intel OSX 10.4.10 with SVN versions of numpy, scipy and 
 matplotlib.

 The latest matplotlib seems to fail on import pylab or ipython 
 -pylab with very many lines of the form

 Found an unknown keyword in AFM header (was
 followed either by a legit character or lots of junk.

 For what it's worth, I tend to install eggs rather than simple setup.py 
 install; moving back to r3421 which I had prevviously seems to work fine.

 Any ideas?

 Yours,

 Andrew

-
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now   http://get.splunk.com/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] matplotlib svn bug: Found an unknown keyword in AFM header...?

2007-08-21 Thread Jouni K . Seppänen
Eric Firing [EMAIL PROTECTED] writes:

 My guess is that this problem has been lurking all along, but was only 
 triggered when I changed font_manager to look for *all* system fonts 
 instead of only truetype, 

Another data point: a recent svn version of matplotlib segfaults on my
OS X system, and ktrace suggests it occurs while it is reading
CharcoalCY.dfont. Running under gdb causes it to exit with a traceback
that ends like this:

  File 
/Users/jks/Hacking/matplotlib/matplotlib/lib/matplotlib/font_manager.py, line 
200, in get_fontconfig_fonts
status, output = commands.getstatusoutput(fc-list file)
  File 
/Library/Frameworks/Python.framework/Versions/2.4//lib/python2.4/commands.py, 
line 54, in getstatusoutput
text = pipe.read()
IOError: [Errno 4] Interrupted system call

Investigating...

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


-
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now   http://get.splunk.com/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] matplotlib svn bug: Found an unknown keyword in AFM header...?

2007-08-21 Thread Jouni K . Seppänen
Jouni K. Seppänen [EMAIL PROTECTED] writes:

 Another data point: a recent svn version of matplotlib segfaults on my
 OS X system, and ktrace suggests it occurs while it is reading
 CharcoalCY.dfont. 

Looks like a freetype bug: the following code segfaults when linked
against libfreetype.6.3.10 but not when linked against
libfreetype.6.3.16. Freetype has some code to read dfont files, which
apparently had a bug in the older version, and this is triggered by the
new code that reads in all font files.

#include ft2build.h
#include FT_FREETYPE_H

int main()
{
  FT_Library library;
  FT_Face face;
  int error;

  error = FT_Init_FreeType(library);
  if (error) {
printf(FT_Init_FreeType error %d\n, error);
return;
  }

  error = FT_New_Face(library, /Library/Fonts/CharcoalCY.dfont, 0, face);
  if (error) {
printf(FT_New_Face error %d\n, error);
return;
  }

  return;
}

-- 
Jouni K. Seppänen
http://www.iki.fi/jks
-
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now   http://get.splunk.com/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] matplotlib svn bug: Found an unknown keyword in AFM header...?

2007-08-21 Thread Jouni K . Seppänen
Eric Firing [EMAIL PROTECTED] writes:

 I think that the problem is occurring in the last line.  This remains to 
 be verified.  It looks like *.afm files are being found, but when 
 createFontDict tries to parse them it doesn't find what it expects.

The cause of the problem is a combination of two things: first, for 
some reason the afmfiles list contains non-AFM files, which is probably 
a bug; second, the AFM parser doesn't quit when faced with a malformed
file. I committed a sanity check (diff attached) in afm.py to fix the 
second problem, but the first one remains.

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

Index: lib/matplotlib/afm.py
===
--- lib/matplotlib/afm.py   (revision 3726)
+++ lib/matplotlib/afm.py   (revision 3727)
@@ -53,7 +53,27 @@
 else: return True
 
 
+def _sanity_check(fh):
+
+Check if the file at least looks like AFM. 
+If not, raise RuntimeError.
+
 
+# Remember the file position in case the caller wants to
+# do something else with the file.
+pos = fh.tell()
+try:
+line = fh.readline()
+finally:
+fh.seek(pos, 0)
+
+# AFM spec, Section 4: The StartFontMetrics keyword [followed by a
+# version number] must be the first line in the file, and the
+# EndFontMetrics keyword must be the last non-empty line in the
+# file. We just check the first line.
+if not line.startswith('StartFontMetrics'):
+raise RuntimeError('Not an AFM file')
+
 def _parse_header(fh):
 
 Reads the font metrics header (up to the char metrics) and returns
@@ -255,6 +275,7 @@
 dkernpairs : a parse_kern_pairs dict, possibly {}
 dcomposite : a parse_composites dict , possibly {}
 
+_sanity_check(fh)
 dhead =  _parse_header(fh)
 dcmetrics =  _parse_char_metrics(fh)
 doptional = _parse_optional(fh)
-
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now   http://get.splunk.com/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] matplotlib svn bug: Found an unknown keyword in AFM header...?

2007-08-21 Thread Jouni K . Seppänen
Andrew Jaffe [EMAIL PROTECTED] writes:

 I admit I don't understand the problems or the speccific code involved, 
 but I *think* it may be that the OSX-specific code isn't restricted to 
 afm files. Hence I wonder if the following is a fix:

 -for f in OSXInstalledFonts():
 +for f in OSXInstalledFonts(fontext=fontext):

It helps in this particular case, but I think the intention behind this
code is to allow loading non-TrueType fonts even when fontext='ttf'. On
OS X there are various non-TrueType font formats (dfont, otf,
resource-fork fonts), at least some of which are supported by freetype,
so if you always pass fontext to OSXInstalledFonts, you unnecessarily
limit the fonts found to those whose filename indicates ttf format.
(Macs also don't care as much about filename extensions as the rest of
the world.)

But I'm just guessing here as to the reasoning behind the code. Somebody
else might know better?

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


-
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now   http://get.splunk.com/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users