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