diff --git a/ft-view.py b/ft-view.py index c875c1e..01fb4f0 100755 --- a/ft-view.py +++ b/ft-view.py @@ -1,57 +1,53 @@ #!/usr/bin/env python3 -# coding: utf8 +# coding: utf8 -help = """FreeType View - get a FreeType font file and display it's bitmap representation (for all characters or a single char). -This script is useful to get font sizing (in pixels) and its representation (under bitmap format). - -Usage: - ft-view.py [--char=] [--descenders=] [--special-align=] - -Options: - -h --help This helps screen +""" +FreeType View - display the bitmap representation of a FreeType font file. -Examples: - python3 ft-view.py ttf-fonts/Vera.ttf 13 --> Will displays all the characters - python3 ft-view.py ttf-fonts/Vera.ttf 13 --char=A --> Display only the char "A" - python3 ft-view.py tft-fonts/heydings_icons.ttf 23 --char=A --descenders= --> ignore all descenders - python3 ft-view.py ttf-fonts/Vera.ttf 13 --descenders=p,q,j,#34 --> change the descenders - python3 ft-view.py ttf-fonts/Vera.ttf 13 --descenders= --> No descenders so baseline = bottomline! - python3 ft-view.py ttf-fonts/Vera.ttf 13 --special-align=a:T,=:B,#126:M --> change the special alignment instruction. a on TOP, = on Bottom, ~(#126) in middle (between the baseline and top) - python3 ft-view.py ttf-fonts/Vera.ttf 13 --special-align= --> delete special alignments. All chars on Bottom line (ideal for Wingdings chars). +This script is useful for obtaining font sizing (in pixels) and its bitmap representation. -Happy Electronic Hacking. -MCHobby.be -""" +Usage: + ft-view.py [--char=] [--descenders=] [--special-align=] + ft-view.py -h | --help + +Options: + -h --help Show this help message and exit + --char= Display only the specified character + --descenders= Define custom descenders (comma-separated list) + --special-align= Define special alignment instructions (comma-separated list) +""" # FreeType generator common items from ftcommon import * from docopt import docopt -import sys -if __name__ == '__main__': - arguments = docopt( help ) +def main(): + # Parse command line arguments + arguments = docopt(__doc__) + + char_filter = arguments['--char'] # e.g., 'B' or None - char_filter = arguments['--char'] # eg: 'B' or None + # Load font and set size + print("Load font %s, set size to %i" % (arguments[''], int(arguments['']))) + font_loader = FreeTypeLoader(font_file=arguments[''], font_size=int(arguments[''])) - print( "Load font %s, set size to %i" % (arguments[''], int(arguments[''])) ) - font_loader = FreeTypeLoader( font_file=arguments[''], font_size=int(arguments['']) ) - if arguments['--descenders'] != None: # redefine the default descenders - font_loader.set_descenders( arguments['--descenders'] ) - if arguments['--special-align' ] != None: # redefine the default special alignments - font_loader.set_special_align( arguments['--special-align' ] ) + # Set custom descenders + if arguments['--descenders'] is not None: + font_loader.set_descenders(arguments['--descenders'].split(',')) - print( "max size (width,height): %i,%i" %(font_loader.max_width, font_loader.max_height ) ) - print( 'descender size = %i' % font_loader.descender_size ) + # Set special alignments + if arguments['--special-align'] is not None: + font_loader.set_special_align(arguments['--special-align'].split(',')) + print("Max size (width,height): %i,%i" % (font_loader.max_width, font_loader.max_height)) + print('Descender size = %i' % font_loader.descender_size) - # for ordinal in font_loader.characters.keys(): + # Print the bitmap representation of each character for ordinal in font_loader.char_ordinals: - if (char_filter != None) and (ord(char_filter) != ordinal ): + if char_filter is not None and ord(char_filter) != ordinal: continue + font_loader.print_character(ordinal) - # print the bitmap representation of a character - # include separator & dimension - font_loader.print_character( ordinal ) - - +if __name__ == '__main__': + main()