From 8c4eb2ddf99a5fc0cb10796d57c087c4779f0a24 Mon Sep 17 00:00:00 2001 From: mrkubax10 Date: Tue, 5 Mar 2024 11:20:11 +0100 Subject: [PATCH] Exporting now uses Unicode pages --- project.py | 47 +++++++++++++++++------------------------------ 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/project.py b/project.py index c14bb71..ea1bc73 100644 --- a/project.py +++ b/project.py @@ -54,45 +54,32 @@ class Project: last_char_idx = len(chars) - 1 page_res = (self.char_res[0] * 16,self.char_res[1] * 16) + pages={} - page = 0 - page_char_x = 0 - page_char_y = 0 for char_idx, char in enumerate(chars): - if page_char_x == 0 and page_char_y == 0: - page_arr = create_zeroed_array(page_res[0]*page_res[1]) - char_map_string = "" + char_id=ord(char[0]) + page=char_id//256 + char_offset_in_page=char_id-page*256 + if not page in pages: + pages[page] = create_zeroed_array(page_res[0]*page_res[1]) char_bitmap=self.decode_char(char[0]) + char_x=char_offset_in_page%16*self.char_res[0] + char_y=char_offset_in_page//16*self.char_res[1] # put char_bitmap onto page_img at correct position for i in range(len(char_bitmap)): - x=i//self.char_res[1]+page_char_x*self.char_res[0] - y=i%self.char_res[1]+page_char_y*self.char_res[1] - page_arr[y*page_res[0]+x]=char_bitmap[i] + x=i//self.char_res[1]+char_x + y=i%self.char_res[1]+char_y + pages[page][y*page_res[0]+x]=char_bitmap[i] - char_map_string += char[0] - page_char_x += 1 + ## save page + for page,page_data in pages.items(): + for x in range(len(page_data)): + page_data[x]*=255 + page_img = PIL.Image.frombytes("L",page_res,bytes(page_data)) + page_img.save(f"{path}/page_{page}.png") - if page_char_x == 16: - page_char_x = 0 - page_char_y += 1 - - if page_char_y == 16 or char_idx == last_char_idx: - ## save page - for x in range(len(page_arr)): - page_arr[x]*=255 - page_img = PIL.Image.frombytes("L",page_res,bytes(page_arr)) - - # save page - page_img.save(f"{path}/page_{page}.png") - - # save char map - with open(f"{path}/page_{page}.txt", "w", encoding="utf-8") as f: - f.write(char_map_string) - - page += 1 - page_char_y = 0 self.export_path=path