53
53
meta-data about how it should be displayed by default
55
55
class FigletFont(object):
56
def __init__(self, dir='.', font='standard'):
56
def __init__(self, dir='.', font='future'):
73
73
a superclass to create different font sources.
75
75
def readFontFile(self):
76
fontPath = '%s/%s.flf' % (self.dir, self.font)
77
if os.path.exists(fontPath) is False:
76
for ext in ('flf', 'tlf'):
77
fontPath = '%s/%s.%s' % (self.dir, self.font, ext)
78
if os.path.exists(fontPath):
78
81
raise FontNotFound, "%s doesn't exist" % fontPath
105
109
header = data.pop(0)
106
110
if self.reMagicNumber.search(header) is None:
107
raise FontError, '%s is not a valid figlet font' % fontPath
111
raise FontError, '%s is not a valid figlet font' % self.font
109
113
header = self.reMagicNumber.sub('', header)
110
114
header = header.split()
112
116
if len(header) < 6:
113
raise FontError, 'malformed header for %s' % fontPath
117
raise FontError, 'malformed header for %s' % self.font
115
119
hardBlank = header[0]
116
120
height, baseLine, maxLength, oldLayout, commentLines = map(int, header[1:6])
220
224
Use this Font class if it exists inside of a zipfile.
222
226
class ZippedFigletFont(FigletFont):
223
def __init__(self, dir='.', font='standard', zipfile='fonts.zip'):
227
def __init__(self, dir='.', font='future', zipfile='fonts.zip'):
224
228
self.zipfile = zipfile
225
229
FigletFont.__init__(self, dir=dir, font=font)
228
232
if os.path.exists(self.zipfile) is False:
229
233
raise FontNotFound, "%s doesn't exist" % self.zipfile
231
fontPath = 'fonts/%s.flf' % self.font
234
z = ZipFile(self.zipfile, 'r')
236
if fontPath not in files:
237
raise FontNotFound, '%s not found in %s' % (self.font, self.zipfile)
239
self.data = z.read(fontPath)
242
raise FontError, "couldn't open %s: %s" % (fontPath, e)
235
for ext in ('.flf', '.tlf'):
236
fontPath = 'fonts/%s.%s' % (self.font, ext)
239
z = ZipFile(self.zipfile, 'r')
241
if fontPath not in files:
242
raise FontNotFound, '%s not found in %s' % (self.font, self.zipfile)
244
self.data = z.read(fontPath)
247
raise FontError, "couldn't open %s: %s" % (fontPath, e)
244
249
def getFonts(self):
245
250
if os.path.exists(self.zipfile) is False:
246
251
raise FontNotFound, "%s doesn't exist" % self.zipfile
248
253
z = ZipFile(self.zipfile, 'r')
249
return [font[6:-4] for font in z.namelist() if font.endswith('.flf')]
254
return [font[6:-4] for font in z.namelist()
255
if font.endswith('.flf') and font.endswith('.tlf')]
456
462
Main figlet class.
458
464
class Figlet(object):
459
def __init__(self, dir=None, zipfile=None, font='standard', direction='auto', justify='auto', width=80):
465
def __init__(self, dir=None, zipfile=None, font='future', direction='auto', justify='auto', width=80):
462
468
self._direction = direction
535
541
parser = OptionParser(version=__version__, usage='%prog [options] text..')
537
parser.add_option( '-f', '--font', default='standard',
543
parser.add_option( '-f', '--font', default='future',
538
544
help='font to render with (default: %default)', metavar='FONT' )
540
parser.add_option( '-d', '--fontdir', default=None,
546
parser.add_option( '-d', '--fontdir', default='/usr/share/figlet',
541
547
help='location of font files', metavar='DIR' )
543
549
parser.add_option( '-z', '--zipfile', default=dir+'/fonts.zip',