pyfiglet-0.6.1+dfsg.orig/0000755000000000000000000000000012074301204013706 5ustar rootrootpyfiglet-0.6.1+dfsg.orig/doc/0000755000000000000000000000000012024601053014453 5ustar rootrootpyfiglet-0.6.1+dfsg.orig/doc/pyfiglet.10000644000000000000000000000225712024601053016366 0ustar rootroot.TH PYFIGLET "1" "June 2011" "pyfiglet 0.6" "User Commands" .SH NAME pyfiglet \- display text in large ASCII art fonts. .SH SYNOPSIS .B pyfiglet.py [\fIoptions\fR] \fItext\fR... .SH DESCRIPTION pyFIGlet is a program that creates large characters out of ordinary screen characters. It takes ASCII text (\fItext\fR) and renders it in ASCII art fonts. .P This version of pyfiglet supports FIGlet fonts \fB.flf\fR and the FIGlet-compatible toilet-fonts \fB.tlf\fR. .SH OPTIONS .TP \fB\-\-version\fR show program's version number and exit .TP \fB\-h\fR, \fB\-\-help\fR show this help message and exit .TP \fB\-f\fR \fIFONT\fR, \fB\-\-font\fR=\fIFONT\fR font to render with (default: future) .TP \fB\-D\fR \fIDIRECTION\fR, \fB\-\-direction\fR=\fIDIRECTION\fR set direction text will be formatted in (default: auto) .TP \fB\-j\fR \fISIDE\fR, \fB\-\-justify\fR=\fISIDE\fR set justification, defaults to print direction .TP \fB\-w\fR \fICOLS\fR, \fB\-\-width\fR=\fICOLS\fR set terminal width for wrapping/justification (default: 80) .TP \fB\-r\fR, \fB\-\-reverse\fR shows mirror image of output text .TP \fB\-F\fR, \fB\-\-flip\fR flips rendered output text over .SH "SEE ALSO" .BR toilet (1), .BR figlet (1) pyfiglet-0.6.1+dfsg.orig/setup.py0000755000000000000000000000065312024601053015427 0ustar rootroot#!/usr/bin/env python from setuptools import setup setup(name='pyfiglet', version='0.6.1', description='Pure-python FIGlet implementation', author='Peter Waller (Thanks to Christopher Jones and Stefano Rivera)', author_email='peter.waller@gmail.com', url='https://github.com/pwaller/pyfiglet', packages=['pyfiglet', 'pyfiglet.fonts'], package_data={'pyfiglet.fonts' : ['*.flf']}, ) pyfiglet-0.6.1+dfsg.orig/README0000644000000000000000000001064512024601053014574 0ustar rootrootAll of the documentation and the majority of the work done was by Christopher Jones (cjones@insub.org). Packaged by Peter Waller , various enhancements by Stefano Rivera . _|_| _| _| _| _|_|_| _| _| _| _|_|_| _| _|_| _|_|_|_| _| _| _| _| _|_|_|_| _| _| _| _| _|_|_|_| _| _| _| _| _| _| _| _| _| _| _| _| _|_|_| _|_|_| _| _| _|_|_| _| _|_|_| _|_| _| _| _| _| _|_| _|_| SYNOPSIS pyfiglet is a full port of FIGlet (http://www.figlet.org/) into pure python. It takes ASCII text and renders it in ASCII art fonts (like the title above, which is the 'block' font). FAQ Q. Why? WHY?! A. I was bored. Really bored. Q. What the hell does this do that FIGlet doesn't? A. Not much, except allow your font collection to live in one big zipfile. The point of this code is to embed dynamic figlet rendering in Python without having to execute an external program, although it operates on the commandline as well. See below for USAGE details. You can think of this as a python FIGlet driver. Q. Does this support kerning/smushing like FIGlet? A. Yes, yes it does. Output should be identical to FIGlet. If not, this is a bug, which you should report to me! Q. Can I use/modify/redstribute this code? A. Yes, under the terms of the GPL (see LICENSE below). Q. I improved this code, what should I do with it? A. You can mail patches to . Particularly bugfixes. If you make changes to the kerning/mushing/rendering portion, PLEASE test it throroughly. The code is fragile and complex. USAGE You can use pyfiglet in one of two ways. First, it operates on the commandline as C figlet does and supports most of the same options. Run with --help to see a full list of tweaks. Mostly you will only use -f to change the font. It defaults to standard.flf. ./pyfiglet 'text to render' Pyfiglet is also a library that can be used in python code: from pyfiglet import Figlet f = Figlet(font='slant', dir='/usr/local/share/figlet') # or zipfile=PATH print f.renderText('text to render') pyfiglet also supports reading fonts from a zip archive. pyfiglet comes with a file called fonts.zip which includes all of the default fonts FIGlet comes with as well as the standard collection of user- contributed fonts. By default, pyfiglet uses this for fonts. Specifying a directory (on the commandline or in the Figlet() object) will override this behavior. You may also specify a zipfile to use with -z or zipfile=PATH in the Figlet() constructor. If you wish to add/remove fonts or create your own font package, be aware that there *must* be a folder in the root of the zipfile called "fonts". You can examine the bunlded fonts.zip to see how it should be packaged. AUTHOR pyfiglet is a *port* of FIGlet, and much of the code is directly translated from the C source. I optimized some bits where I could, but because the smushing and kerning code is so incredibly complex, it was safer and easier to port the logic almost exactly. Therefore, I can't really take much credit for authorship, just translation. The original authors of FIGlet are listed on their website at http://www.figlet.org/. The Python port was done by Christopher Jones (http://gruntle.org/). LICENSE Copyright (C) 2007 Christopher Jones This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA (see LICENSE for full details) pyfiglet-0.6.1+dfsg.orig/LICENSE0000644000000000000000000004311412024601053014716 0ustar rootroot GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. pyfiglet-0.6.1+dfsg.orig/pyfiglet/0000755000000000000000000000000012024601053015531 5ustar rootrootpyfiglet-0.6.1+dfsg.orig/pyfiglet/__init__.py0000755000000000000000000004317112024601053017653 0ustar rootroot#!/usr/bin/env python """ Python FIGlet adaption """ import os import pkg_resources import re import sys from optparse import OptionParser __version__ = '0.6.1dev' __author__ = 'Peter Waller ' __copyright__ = """ Copyright (C) 2007 Christopher Jones Tweaks (C) 2011 Peter Waller (C) 2011 Stefano Rivera This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA """ DEFAULT_FONT='standard' def figlet_format(text, font=DEFAULT_FONT, **kwargs): fig = Figlet(font) return fig.renderText(text, **kwargs) def print_figlet(text, font=DEFAULT_FONT, **kwargs): print figlet_format(text, font, **kwargs) class FigletError(Exception): def __init__(self, error): self.error = error def __str__(self): return self.error class FontNotFound(FigletError): """ Raised when a font can't be located """ class FontError(FigletError): """ Raised when there is a problem parsing a font file """ class FigletFont(object): """ This class represents the currently loaded font, including meta-data about how it should be displayed by default """ reMagicNumber = re.compile(r'^[tf]lf2.') reEndMarker = re.compile(r'(.)\s*$') def __init__(self, font=DEFAULT_FONT): self.font = font self.comment = '' self.chars = {} self.width = {} self.data = None for extension in ('tlf', 'flf'): fn = '%s.%s' % (font, extension) if pkg_resources.resource_exists('pyfiglet.fonts', fn): self.data = pkg_resources.resource_string('pyfiglet.fonts', fn) break else: raise FontNotFound(font) self.loadFont() @classmethod def getFonts(self): return [font.rsplit('.', 2)[0] for font in pkg_resources.resource_listdir('pyfiglet', 'fonts') if font.endswith(('.flf', '.tlf')) and self.reMagicNumber.search(pkg_resources.resource_stream( 'pyfiglet.fonts', font).readline())] def loadFont(self): """ Parse loaded font data for the rendering engine to consume """ try: # Parse first line of file, the header data = self.data.splitlines() header = data.pop(0) if self.reMagicNumber.search(header) is None: 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' % self.font) hardBlank = header[0] height, baseLine, maxLength, oldLayout, commentLines = map(int, header[1:6]) printDirection = fullLayout = codeTagCount = None # these are all optional for backwards compat if len(header) > 6: printDirection = int(header[6]) if len(header) > 7: fullLayout = int(header[7]) if len(header) > 8: codeTagCount = int(header[8]) # if the new layout style isn't available, # convert old layout style. backwards compatability if fullLayout is None: if oldLayout == 0: fullLayout = 64 elif oldLayout < 0: fullLayout = 0 else: fullLayout = (oldLayout & 31) | 128 # Some header information is stored for later, the rendering # engine needs to know this stuff. self.height = height self.hardBlank = hardBlank self.printDirection = printDirection self.smushMode = fullLayout # Strip out comment lines for i in range(0, commentLines): self.comment += data.pop(0) # Load characters for i in range(32, 127): end = None width = 0 chars = [] for j in range(0, height): line = data.pop(0) if end is None: end = self.reEndMarker.search(line).group(1) end = re.compile(re.escape(end) + r'{1,2}$') line = end.sub('', line) if len(line) > width: width = len(line) chars.append(line) if ''.join(chars) != '': self.chars[i] = chars self.width[i] = width except Exception as e: raise FontError('problem parsing %s font: %s' % (self.font, e)) def __str__(self): return '' % self.font class FigletString(str): """ Rendered figlet font """ # translation map for reversing ascii art / -> \, etc. __reverse_map__ = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&\')(*+,-.\\0123456789:;>= v, etc. __flip_map__ = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&\'()*+,-.\\0123456789:;<=>?@VBCDEFGHIJKLWNObQbSTUAMXYZ[/]v-`aPcdefghijklwnopqrstu^mxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff' def reverse(self): out = [] for row in self.splitlines(): out.append(row.translate(self.__reverse_map__)[::-1]) return self.newFromList(out) def flip(self): out = [] for row in self.splitlines()[::-1]: out.append(row.translate(self.__flip_map__)) return self.newFromList(out) def newFromList(self, list): return FigletString('\n'.join(list) + '\n') class FigletRenderingEngine(object): """ This class handles the rendering of a FigletFont, including smushing/kerning/justification/direction """ def __init__(self, base=None): self.base = base # constants.. lifted from figlet222 self.SM_EQUAL = 1 # smush equal chars (not hardblanks) self.SM_LOWLINE = 2 # smush _ with any char in hierarchy self.SM_HIERARCHY = 4 # hierarchy: |, /\, [], {}, (), <> self.SM_PAIR = 8 # hierarchy: [ + ] -> |, { + } -> |, ( + ) -> | self.SM_BIGX = 16 # / + \ -> X, > + < -> X self.SM_HARDBLANK = 32 # hardblank + hardblank -> hardblank self.SM_KERN = 64 self.SM_SMUSH = 128 def smushChars(self, left='', right=''): """ Given 2 characters which represent the edges rendered figlet fonts where they would touch, see if they can be smushed together. Returns None if this cannot or should not be done. """ if left.isspace() is True: return right if right.isspace() is True: return left # Disallows overlapping if previous or current char has a width of 1 or zero if (self.prevCharWidth < 2) or (self.curCharWidth < 2): return # kerning only if (self.base.Font.smushMode & self.SM_SMUSH) == 0: return # smushing by universal overlapping if (self.base.Font.smushMode & 63) == 0: # Ensure preference to visiable characters. if left == self.base.Font.hardBlank: return right if right == self.base.Font.hardBlank: return left # Ensures that the dominant (foreground) # fig-character for overlapping is the latter in the # user's text, not necessarily the rightmost character. if self.base.direction == 'right-to-left': return left else: return right if self.base.Font.smushMode & self.SM_HARDBLANK: if left == self.base.Font.hardBlank and right == self.base.Font.hardBlank: return left if left == self.base.Font.hardBlank or right == self.base.Font.hardBlank: return if self.base.Font.smushMode & self.SM_EQUAL: if left == right: return left if self.base.Font.smushMode & self.SM_LOWLINE: if (left == '_') and (right in r'|/\[]{}()<>'): return right if (right == '_') and (left in r'|/\[]{}()<>'): return left if self.base.Font.smushMode & self.SM_HIERARCHY: if (left == '|') and (right in r'|/\[]{}()<>'): return right if (right == '|') and (left in r'|/\[]{}()<>'): return left if (left in r'\/') and (right in '[]{}()<>'): return right if (right in r'\/') and (left in '[]{}()<>'): return left if (left in '[]') and (right in '{}()<>'): return right if (right in '[]') and (left in '{}()<>'): return left if (left in '{}') and (right in '()<>'): return right if (right in '{}') and (left in '()<>'): return left if (left in '()') and (right in '<>'): return right if (right in '()') and (left in '<>'): return left if self.base.Font.smushMode & self.SM_PAIR: for pair in [left+right, right+left]: if pair in ['[]', '{}', '()']: return '|' if self.base.Font.smushMode & self.SM_BIGX: if (left == '/') and (right == '\\'): return '|' if (right == '/') and (left == '\\'): return 'Y' if (left == '>') and (right == '<'): return 'X' return def smushAmount(self, left=None, right=None, buffer=[], curChar=[]): """ Calculate the amount of smushing we can do between this char and the last If this is the first char it will throw a series of exceptions which are caught and cause appropriate values to be set for later. This differs from C figlet which will just get bogus values from memory and then discard them after. """ if (self.base.Font.smushMode & (self.SM_SMUSH | self.SM_KERN)) == 0: return 0 maxSmush = self.curCharWidth for row in range(0, self.base.Font.height): lineLeft = buffer[row] lineRight = curChar[row] if self.base.direction == 'right-to-left': lineLeft, lineRight = lineRight, lineLeft linebd = len(lineLeft.rstrip()) - 1 if linebd < 0: linebd = 0 if linebd < len(lineLeft): ch1 = lineLeft[linebd] else: linebd = 0 ch1 = '' charbd = len(lineRight) - len(lineRight.lstrip()) if charbd < len(lineRight): ch2 = lineRight[charbd] else: charbd = len(lineRight) ch2 = '' amt = charbd + len(lineLeft) - 1 - linebd if ch1 == '' or ch1 == ' ': amt += 1 elif ch2 != '' and self.smushChars(left=ch1, right=ch2) is not None: amt += 1 if amt < maxSmush: maxSmush = amt return maxSmush def render(self, text): """ Render an ASCII text string in figlet """ self.curCharWidth = self.prevCharWidth = 0 buffer = ['' for i in range(self.base.Font.height)] for c in map(ord, list(text)): if self.base.Font.chars.has_key(c) is False: continue curChar = self.base.Font.chars[c] self.curCharWidth = self.base.Font.width[c] maxSmush = self.smushAmount(buffer=buffer, curChar=curChar) # Add a character to the buffer and do smushing/kerning for row in range(0, self.base.Font.height): addLeft = buffer[row] addRight = curChar[row] if self.base.direction == 'right-to-left': addLeft, addRight = addRight, addLeft for i in range(0, maxSmush): idx = len(addLeft) - maxSmush + i if idx >= 0 and idx < len(addLeft): left = addLeft[idx] else: left = '' right = addRight[i] smushed = self.smushChars(left=left, right=right) l = list(addLeft) idx = len(l)-maxSmush+i if idx >= 0 and idx < len(l): l[idx] = smushed addLeft = ''.join(l) buffer[row] = addLeft + addRight[maxSmush:] self.prevCharWidth = self.curCharWidth # Justify text. This does not use str.rjust/str.center # specifically because the output would not match FIGlet if self.base.justify == 'right': for row in range(0, self.base.Font.height): buffer[row] = (' ' * (self.base.width - len(buffer[row]) - 1)) + buffer[row] elif self.base.justify == 'center': for row in range(0, self.base.Font.height): buffer[row] = (' ' * int((self.base.width - len(buffer[row])) / 2)) + buffer[row] # return rendered ASCII with hardblanks replaced buffer = '\n'.join(buffer) + '\n' buffer = buffer.replace(self.base.Font.hardBlank, ' ') return FigletString(buffer) class Figlet(object): """ Main figlet class. """ def __init__(self, font=DEFAULT_FONT, direction='auto', justify='auto', width=80): self.font = font self._direction = direction self._justify = justify self.width = width self.setFont() self.engine = FigletRenderingEngine(base=self) def setFont(self, **kwargs): if kwargs.has_key('font'): self.font = kwargs['font'] self.Font = FigletFont(font=self.font) def getDirection(self): if self._direction == 'auto': direction = self.Font.printDirection if direction == 0: return 'left-to-right' elif direction == 1: return 'right-to-left' else: return 'left-to-right' else: return self._direction direction = property(getDirection) def getJustify(self): if self._justify == 'auto': if self.direction == 'left-to-right': return 'left' elif self.direction == 'right-to-left': return 'right' else: return self._justify justify = property(getJustify) def renderText(self, text): # wrapper method to engine return self.engine.render(text) def getFonts(self): return self.Font.getFonts() def main(): parser = OptionParser(version=__version__, usage='%prog [options] text..') parser.add_option('-f', '--font', default=DEFAULT_FONT, help='font to render with (default: %default)', metavar='FONT') parser.add_option('-D', '--direction', type='choice', choices=('auto', 'left-to-right', 'right-to-left'), default='auto', metavar='DIRECTION', help='set direction text will be formatted in (default: %default)') parser.add_option('-j', '--justify', type='choice', choices=('auto', 'left', 'center', 'right'), default='auto', metavar='SIDE', help='set justification, defaults to print direction') parser.add_option('-w', '--width', type='int', default=80, metavar='COLS', help='set terminal width for wrapping/justification (default: %default)' ) parser.add_option('-r', '--reverse', action='store_true', default=False, help='shows mirror image of output text') parser.add_option('-F', '--flip', action='store_true', default=False, help='flips rendered output text over') opts, args = parser.parse_args() if len(args) == 0: parser.print_help() return 1 text = ' '.join(args) f = Figlet( font=opts.font, direction=opts.direction, justify=opts.justify, width=opts.width, ) r = f.renderText(text) if opts.reverse is True: r = r.reverse() if opts.flip is True: r = r.flip() print r return 0 if __name__ == '__main__': sys.exit(main()) pyfiglet-0.6.1+dfsg.orig/pyfiglet/test.py0000755000000000000000000000344212024601053017070 0ustar rootroot#!/usr/bin/env python import os.path import sys from optparse import OptionParser from pyfiglet import Figlet from subprocess import Popen, STDOUT, PIPE __version__ = '0.1' def dump(text): for line in text.split('\n'): print repr(line) def main(): parser = OptionParser(version=__version__) parser.add_option('-s', '--show', action='store_true', default=False, help='pause at each failure and compare output ' '(default: %default)') opts, args = parser.parse_args() f = Figlet() ok = 0 fail = 0 failed = [] skip = ['runic'] # known bug.. for font in f.getFonts(): if font in skip: continue f.setFont(font=font) outputPyfiglet = f.renderText('foo') fontpath = os.path.join('pyfiglet', 'fonts', font) if os.path.isfile(fontpath + '.flf'): cmd = ('figlet', '-d', 'pyfiglet/fonts', '-f', font, 'foo') elif os.path.isfile(fontpath + '.tlf'): cmd = ('toilet', '-d', 'pyfiglet/fonts', '-f', font, 'foo') else: raise Exception('Missing font file') p = Popen(cmd, bufsize=1,stdout=PIPE) outputFiglet = p.communicate()[0] if outputPyfiglet == outputFiglet: print '[OK] %s' % font ok += 1 continue print '[FAIL] %s' % font fail += 1 failed.append(font) if opts.show is True: print '[PYTHON] *** %s\n\n' % font dump(outputPyfiglet) print '[FIGLET] *** %s\n\n' % font dump(outputFiglet) raw_input() print 'OK = %d, FAIL = %d' % (ok, fail) if len(failed) > 0: print 'FAILED = %s' % repr(failed) return 0 if __name__ == '__main__': sys.exit(main()) pyfiglet-0.6.1+dfsg.orig/MANIFEST.in0000644000000000000000000000003512024601053015442 0ustar rootrootinclude pyfiglet/fonts/*.flf