peterhinch / micropython-font-to-py

A Python 3 utility to convert fonts to Python source capable of being frozen as bytecode
MIT License
368 stars 67 forks source link

tried to create large font file with thousands of character #41

Closed tljk closed 2 years ago

tljk commented 2 years ago

图片 this is what i got from a 3.5k characters file named chinese the font index seems simply cannot exceed 255, -l or --largest Ordinal value of largest character to be stored. Default 126. so, what is the correct way to do so

peterhinch commented 2 years ago

I think your deduction is incorrect. The index can accept values up to 65535, and your font exceeds that. The following was issued under CPython 3.8.10:

>>> x = 4
>>> x.to_bytes(2, byteorder="little")
b'\x04\x00'
>>> x = 65535
>>> x.to_bytes(2, byteorder="little")
b'\xff\xff'
>>> x = 65536
>>> x.to_bytes(2, byteorder="little")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: int too big to convert
>>>