diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2024-02-21 12:07:07 +0200 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2024-02-21 12:07:07 +0200 |
| commit | 927c018f12e73c254cec32c0f60e1c01b9fc0319 (patch) | |
| tree | 21fbb975e3567cb0d9ab3fb34519c50325571d6c /atk16-utils/convert_ttf.py | |
| parent | a0b4a1a6107e4dc905b21858d8ac76c47293cfb4 (diff) | |
Refactor names
Diffstat (limited to 'atk16-utils/convert_ttf.py')
| -rw-r--r-- | atk16-utils/convert_ttf.py | 52 |
1 files changed, 0 insertions, 52 deletions
diff --git a/atk16-utils/convert_ttf.py b/atk16-utils/convert_ttf.py deleted file mode 100644 index c1135cb..0000000 --- a/atk16-utils/convert_ttf.py +++ /dev/null @@ -1,52 +0,0 @@ -from PIL import Image, ImageFont, ImageDraw - -import sys - -if len(sys.argv) != 3: - print("usage: convert_ttf.py <infile.ttf> <outfile.txt>") - sys.exit(1) - -# Define the font file and size -font_file = sys.argv[1] -out_file = sys.argv[2] -font_size = 8 # 8x8 pixels - -# Create a font object -font = ImageFont.truetype(font_file, font_size) - - -# backspace 0x8, tab 0x9, newline 0xA, space 0x20 - -# Define the characters to render -#characters = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ' - -def to_char_code(i: int) -> str: - if i == 10: - return " " - return chr(i) - -characters = [to_char_code(i) for i in range(0, 256)] - - -# Open a file to write the bitmaps to -with open(out_file, 'w') as bitmap_file: - for char_idx, char in enumerate(characters): - # Create a new image with a white background - image = Image.new('1', (8, 8), 1) - - # Create a drawing context - draw = ImageDraw.Draw(image) - - # Draw the character - draw.text((0, 0), char, font=font, fill=0) - - # Convert the image to a list of 0's and 1's - pixels = image.getdata() - bitmap = [1 if pixel == 0 else 0 for pixel in pixels] - - # Write the bitmap to the file - bitmap_file.write(f'Character {char_idx}: {char}\n') - for i in range(0, 64, 8): - row = bitmap[i:i+8] - bitmap_file.write(''.join(str(bit) for bit in row) + '\n') - bitmap_file.write('\n') |
