Files
V2_micropython/websocket_server/test_font.py
jeremygan2021 e0776a1839 t
2026-03-02 22:43:04 +08:00

56 lines
1.6 KiB
Python

import os
FONT_FILE = "/Users/jeremygan/Desktop/python_dev/epaper2/websocket_server/GB2312-16.bin"
def test_font():
if not os.path.exists(FONT_FILE):
print(f"Error: File not found at {FONT_FILE}")
return
file_size = os.path.getsize(FONT_FILE)
print(f"Font file size: {file_size} bytes")
# Expected size for GB2312-16 (94x94 chars * 32 bytes)
expected_size = 94 * 94 * 32
print(f"Expected size: {expected_size} bytes")
if file_size != expected_size:
print(f"Warning: File size mismatch! (Diff: {file_size - expected_size})")
# Try to render '中' (0xD6D0)
# Area: 0xD6 - 0xA0 = 54
# Index: 0xD0 - 0xA0 = 48
area = 0xD6 - 0xA0
index = 0xD0 - 0xA0
offset = ((area - 1) * 94 + (index - 1)) * 32
print(f"Testing character '' (0xD6D0)")
print(f"Area: {area}, Index: {index}, Offset: {offset}")
with open(FONT_FILE, "rb") as f:
f.seek(offset)
data = f.read(32)
if len(data) != 32:
print("Error: Could not read 32 bytes")
return
print("Bitmap data:")
for i in range(16):
# Each row is 2 bytes (16 bits)
byte1 = data[i*2]
byte2 = data[i*2+1]
# Print as bits
line = ""
for b in range(8):
if (byte1 >> (7-b)) & 1: line += "##"
else: line += ".."
for b in range(8):
if (byte2 >> (7-b)) & 1: line += "##"
else: line += ".."
print(line)
if __name__ == "__main__":
test_font()