def __init__(self, fontfilename=config.scriptPath("bigblocks.bsfont")): try: lines = open(fontfilename, encoding="utf-8").readlines() except Exception as e: die("Couldn't find font file “{0}”:\n{1}", fontfilename, e) self.metadata, lines = parseMetadata(lines) self.characters = parseCharacters(self.metadata, lines)
def __init__(self, fontfilename=config.scriptPath("bigblocks.bsfont")): try: lines = io.open(fontfilename, 'r', encoding="utf-8").readlines() except Exception as e: die("Couldn't find font file “{0}”:\n{1}", fontfilename, e) self.metadata, lines = parseMetadata(lines) self.characters = parseCharacters(self.metadata, lines)
try: if outputFilename == "-": sys.stdout.write("".join(lines)) else: with open(outputFilename, "w", encoding="utf-8") as f: f.write("".join(lines)) except Exception as e: die( "Something prevented me from saving the output document to {0}:\n{1}", outputFilename, e, ) if __name__ == "__main__": import argparse argparser = argparse.ArgumentParser( description="Outputs text as giant ASCII art.") argparser.add_argument( "--font", dest="fontPath", default=config.scriptPath("bigblocks.bsfont"), help="What .bsfont file to use to render the text with.", ) argparser.add_argument("text", help="Text to ASCII-ify.") options = argparser.parse_args() font = Font(options.fontPath) for line in font.write(options.text): print(line, end="")
def __init__(self, fontfilename=config.scriptPath("bigblocks.bsfont")): try: lines = io.open(fontfilename, 'r', encoding="utf-8").readlines() except Exception, e: die("Couldn't find font file “{0}”:\n{1}", fontfilename, e)
return [] except IOError: die("Couldn't open the input file '{0}'.", inputFilename) return [] return lines, inputFilename def writeOutputLines(outputFilename, inputFilename, lines): if outputFilename is None: outputFilename = inputFilename try: if outputFilename == "-": sys.stdout.write(''.join(lines)) else: with io.open(outputFilename, "w", encoding="utf-8") as f: f.write(''.join(lines)) except Exception, e: die("Something prevented me from saving the output document to {0}:\n{1}", outputFilename, e) if __name__ == "__main__": import argparse argparser = argparse.ArgumentParser(description="Outputs text as giant ASCII art.") argparser.add_argument("--font", dest="fontPath", default=config.scriptPath("bigblocks.bsfont"), help="What .bsfont file to use to render the text with.") argparser.add_argument("text", help="Text to ASCII-ify.") options = argparser.parse_args() font = Font(options.fontPath) for line in font.write(options.text): print line,