Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
parsing font.data
from struct import unpack
with open('font.dat', 'rb') as f:
data = f.read()
# read offset list
offsetList = []
cursor = 0
endOfFS = len(data)
while cursor < endOfFS:
offset = unpack('I', data[cursor:cursor+4])[0]
offsetList.append((offset, cursor // 4))
if offset > 0:
endOfFS = min(endOfFS, offset)
cursor += 4
def getIndex(c):
if ord(c) < 128:
return ord(c)
else:
BASE_CODE = 0x8140
code = unpack('>H', c.encode('shift-jis'))[0]
print(hex(code))
return 319 + code - BASE_CODE - (code - BASE_CODE) // 256
def draw(c):
offset, index = offsetList[getIndex(c)]
if offset == 0:
return
header = unpack('IIIIII', data[offset:offset+24])
size = header[5]
height = header[1]
width = size // height
for i in range(size):
value = data[offset+24+i]
if i % width == 0:
print()
else:
print('X' if value > 0 else ' ', end='')
print()
draw('a')
draw('Z')
draw('は')
draw('日')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.