bitmap_font_simpletest.py
1 # Call this with the font file as the command line argument. 2 3 import os 4 import sys 5 6 # Add paths so this runs in CPython in-place. 7 sys.path.append(os.path.join(sys.path[0], "..")) 8 from adafruit_bitmap_font import bitmap_font # pylint: disable=wrong-import-position 9 10 sys.path.append(os.path.join(sys.path[0], "../test")) 11 font = bitmap_font.load_font(sys.argv[1]) 12 13 _, height, _, dy = font.get_bounding_box() 14 for y in range(height): 15 for c in "Adafruit CircuitPython": 16 glyph = font.get_glyph(ord(c)) 17 if not glyph: 18 continue 19 glyph_y = y + (glyph.height - (height + dy)) + glyph.dy 20 pixels = [] 21 if 0 <= glyph_y < glyph.height: 22 for i in range(glyph.width): 23 value = glyph.bitmap[i, glyph_y] 24 pixel = " " 25 if value > 0: 26 pixel = "#" 27 pixels.append(pixel) 28 else: 29 pixels = "" 30 print("".join(pixels) + " " * (glyph.shift_x - len(pixels)), end="") 31 print()