Commit 6076caa1 authored by Stefano Rivera's avatar Stefano Rivera

Add toilet .tlf reading support

parent 7a7d9b60
Description: The directory-tree handling code is poorer quality than the Zip
file code. This corrects some non-existant variable accessing.
Author: Stefano Rivera <stefano@rivera.za.net>
Forwarded: https://sourceforge.net/tracker/?func=detail&aid=2939614&group_id=200820&atid=975076
Last Update: 2010-01-25
--- a/pyfiglet.py
+++ b/pyfiglet.py
@@ -104,13 +104,13 @@
header = data.pop(0)
if self.reMagicNumber.search(header) is None:
- raise FontError, '%s is not a valid figlet font' % fontPath
+ raise FontError, '%s is not a valid figlet font' % self.font
header = self.reMagicNumber.sub('', header)
header = header.split()
if len(header) < 6:
- raise FontError, 'malformed header for %s' % fontPath
+ raise FontError, 'malformed header for %s' % self.font
hardBlank = header[0]
height, baseLine, maxLength, oldLayout, commentLines = map(int, header[1:6])
dir-error-path.diff
tlf-support.diff
setup.py.diff
Description: Add support for toilet's .tlf files.
There are .tlf files which are compatible with figlet.
Author: Stefano Rivera <stefano@rivera.za.net>
Forwarded: https://sourceforge.net/tracker/?func=detail&aid=2939616&group_id=200820&atid=975076
Last Update: 2010-01-25
--- a/pyfiglet.py
+++ b/pyfiglet.py
@@ -62,7 +62,7 @@
self.width = {}
self.data = None
- self.reMagicNumber = re.compile(r'^flf2.')
+ self.reMagicNumber = re.compile(r'^[ft]lf2.')
self.reEndMarker = re.compile(r'(.)\s*$')
self.readFontFile()
@@ -73,8 +73,11 @@
a superclass to create different font sources.
"""
def readFontFile(self):
- fontPath = '%s/%s.flf' % (self.dir, self.font)
- if os.path.exists(fontPath) is False:
+ for ext in ('flf', 'tlf'):
+ fontPath = '%s/%s.%s' % (self.dir, self.font, ext)
+ if os.path.exists(fontPath):
+ break
+ else:
raise FontNotFound, "%s doesn't exist" % fontPath
try:
@@ -86,7 +89,8 @@
finally: fo.close()
def getFonts(self):
- return [font[:-4] for font in os.walk(self.dir).next()[2] if font.endswith('.flf')]
+ return [font[:-4] for font in os.walk(self.dir).next()[2]
+ if font.endswith('.flf') or font.endswith('.tlf')]
@@ -228,25 +232,27 @@
if os.path.exists(self.zipfile) is False:
raise FontNotFound, "%s doesn't exist" % self.zipfile
- fontPath = 'fonts/%s.flf' % self.font
+ for ext in ('.flf', '.tlf'):
+ fontPath = 'fonts/%s.%s' % (self.font, ext)
- try:
- z = ZipFile(self.zipfile, 'r')
- files = z.namelist()
- if fontPath not in files:
- raise FontNotFound, '%s not found in %s' % (self.font, self.zipfile)
+ try:
+ z = ZipFile(self.zipfile, 'r')
+ files = z.namelist()
+ if fontPath not in files:
+ raise FontNotFound, '%s not found in %s' % (self.font, self.zipfile)
- self.data = z.read(fontPath)
+ self.data = z.read(fontPath)
- except Exception, e:
- raise FontError, "couldn't open %s: %s" % (fontPath, e)
+ except Exception, e:
+ raise FontError, "couldn't open %s: %s" % (fontPath, e)
def getFonts(self):
if os.path.exists(self.zipfile) is False:
raise FontNotFound, "%s doesn't exist" % self.zipfile
z = ZipFile(self.zipfile, 'r')
- return [font[6:-4] for font in z.namelist() if font.endswith('.flf')]
+ return [font[6:-4] for font in z.namelist()
+ if font.endswith('.flf') and font.endswith('.tlf')]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment