From 1f8ce8c64a8ae345d51b1e200ee9a12e2dd7c020 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Wed, 22 Dec 2021 19:29:13 -0500 Subject: [PATCH] still need main glyph info --- .gitignore | 1 + tdfdisc.py | 47 +++++++++++++++++++++++++++++++++++++---------- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 485dee6..d48c759 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .idea +.vscode \ No newline at end of file diff --git a/tdfdisc.py b/tdfdisc.py index a428717..a48a4c7 100644 --- a/tdfdisc.py +++ b/tdfdisc.py @@ -1,8 +1,15 @@ -class tdf: - def __init__(self, f): - self.fonts = [] - f.read(1) # character 19 - if f.read(18) == b"TheDraw FONTS file" +import sys + +_CHARLIST= "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; + + + +def char_lookup(c, font): + for i in range(0, len(_CHARLIST) - 1): + if _CHARLIST[i] == c and not(font.characters_define[i] == [b'0xFF', b'0xFF']): + return i + return None + class font: def __init__(self): @@ -14,12 +21,32 @@ class font: self.characters_define = None self.data = None +class tdf: + def __init__(self, f): + self.fonts = [] + f.read(1) # character 19 + if not(f.read(18) == b"TheDraw FONTS file"): # fix string + print("file is seemingly invalid") + sys.exit(1) + f.read(1) # character 26 +# while True: # just one for nao + if not(f.read(4) == b'U\xaa\x00\xff'): # fix string + return + construction = font() + construction.font_name_length = f.read(1) + construction.font_name = f.read(12).decode("ascii") + f.read(4) + construction.font_type = f.read(1) + construction.letter_spacing = f.read(1) + construction.block_size = int.from_bytes(f.read(2), byteorder="little") + construction.characters_define = [f.read(188)[x:x+5] for x in range(0, 188,2)] + construction.data = f.read(construction.block_size) + self.fonts.append(construction) + + + f = open("pittyx.tdf", "rb") loaded = tdf(f) -print(r[25:25+12]) f.close() -""" -for b in r: - print(b) -""" \ No newline at end of file +print(loaded.fonts[0].block_size) \ No newline at end of file