Add files via upload

This commit is contained in:
icyqwq
2020-05-19 16:21:30 +08:00
committed by GitHub
parent 9f3d0ee5c4
commit eafc73a7ab
4 changed files with 90 additions and 22 deletions
+90 -22
View File
@@ -5,10 +5,8 @@ import re
import math
import time
import json
#import Gerenator
font_dict = {}
list_ctrl_id = 0
import threading
import queue
def MessageDialog(self, level, msg):
if level == wx.LOG_Warning: # 1
@@ -24,6 +22,37 @@ def MessageDialog(self, level, msg):
dialog.Destroy()
return res
class Thread_Creator (threading.Thread):
def __init__(self, threadID, q, unicode_block, parent, font_size, font_spacing, filename):
threading.Thread.__init__(self)
self.threadID = threadID
self.queue = q
self.unicode_block = unicode_block
self.runFlag = True
self.exit = False
self.parent = parent
self.font_size = font_size
self.font_spacing = font_spacing
self.filename = filename
def run(self):
print("Start Thread " + self.name)
self.Process()
print("Exit Thread " + self.name)
def isExit(self):
return self.exit
def Terminate(self):
self.runFlag = False
def Process(self):
frame = Frame_Gerenate(parent = self.parent, font_size = self.font_size)
# frame.Show()
flash_size = frame.Generate(self.unicode_block, self.font_spacing, self.font_size, self.filename)
self.queue.put(('DONE', flash_size))
class Frame_Gerenate(Gerenate):
def __init__(self, parent, font_size):
super(Frame_Gerenate, self).__init__(parent)
@@ -31,7 +60,6 @@ class Frame_Gerenate(Gerenate):
self.parent = parent
self.parent.Disable()
self.bmp = wx.Bitmap(64, 64, depth=1)
#font_dict[self.listctrl_fontinfo.GetItemText(0, 3)]
def OnClose_Cb( self, event):
self.parent.Enable()
@@ -45,8 +73,6 @@ class Frame_Gerenate(Gerenate):
ox = base_offset + lr
oy = base_offset + ud
x = self.dc.DrawText(chr(unicode), ox, oy)
#print('%04X' %unicode)
#self.dc.DrawText('%04X' %unicode, font_size, 0)
bitmap = []
for y in range(base_offset, base_offset + font_size):
@@ -127,6 +153,11 @@ class Frame_Gerenate(Gerenate):
unicode_start = blocks[0][0]
unicode_end = blocks[-1][1]
total = 0
for block in blocks:
total += block[1] - block[0]
total += len(blocks)
# Write Bitmap
dst.write('/* This file is automatically generated by a Unicode to GFX script */\n')
dst.write('/* by icyqwq@gmail.com */\n\n')
@@ -141,12 +172,22 @@ class Frame_Gerenate(Gerenate):
base_list = []
base_list.append(0)
base = 0
current_index = 0
for block in blocks:
block[2].SetPixelSize(wx.Size(0, font_size))
self.dc.SetFont(block[2])
print('0x%04X - 0x%04X' %(block[0], block[1]))
if block[1] - block[0] > 50:
for i in range(0, len(self.parent.unicode_range_list)):
if self.parent.unicode_range_list[i][0] == block[0]:
self.parent.listctrl_fontinfo.SetItemBackgroundColour(i, (0, 192, 0))
else:
self.parent.listctrl_fontinfo.SetItemBackgroundColour(i, (255, 255, 255))
for unicode in range(block[0], block[1] + 1):
self.parent.button_gen.SetLabelText('%04X' %unicode)
current_index += 1
self.parent.button_gen.SetLabelText('%d / %d' %(current_index, total))
base += 1
glyph = self.GetBitmapAttribute(self.RenderBitmap(unicode, font_size, block[3], block[4]), unicode, font_spacing, font_size)
gfxglyph_buffer.append('{0x%X, %d, %d, %d, %d, %d}, /* 0x%04X */\n' %(bitmap_offset, glyph[2], glyph[3], glyph[4], glyph[5], glyph[6], glyph[7]))
@@ -174,7 +215,7 @@ class Frame_Gerenate(Gerenate):
dst.write('};/* 0x%04X */\n\n' %(unicode))
base_list.pop()
if len(blocks) is not len(base_list):
if len(blocks) != len(base_list):
print("Error %d != %d" %(len(blocks), len(base_list)))
#Write Index
@@ -210,6 +251,25 @@ class Frame_MainFrame(MainFrame):
self.listctrl_fontinfo.InsertColumn(1, 'Unicode Start', width = 100)
self.listctrl_fontinfo.InsertColumn(2, 'Unicode End', width = 100)
self.unicode_block = []
self.thread = None
self.queue_info = queue.Queue(100)
self.filename = None
self.unicode_range_list = []
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.OnTimer_CB)
def OnTimer_CB(self, event):
if not self.queue_info.empty():
queue_data = self.queue_info.get()
print(queue_data)
if queue_data[0] == 'DONE':
flash_size = queue_data[1]
MessageDialog(self, wx.LOG_Message, '%s Generated, Approx. %.1f KiB' %(self.filename, flash_size/1024.0))
self.Enable()
self.button_gen.SetLabelText('Gerenate')
print(('Done, Approx. %.1f KiB' %(flash_size/1024.0)))
self.timer.Stop()
def OnListItemSelect_Cb( self, event ):
self.fontinfo_onselect.clear()
@@ -273,6 +333,15 @@ class Frame_MainFrame(MainFrame):
lr = data[key][2]
self.unicode_block.append([start, end, font, ud, lr])
self.listctrl_fontinfo.Append([font.GetFaceName(), payload[0], payload[1]])
self.unicode_range_list = []
item = -1
while True:
item = self.listctrl_fontinfo.GetNextItem(item)
if item == -1:
break
self.unicode_range_list.append((int(self.listctrl_fontinfo.GetItemText(item, 1), 16),\
int(self.listctrl_fontinfo.GetItemText(item, 2), 16)))
except:
MessageDialog(self, wx.LOG_Error, 'Invalid configuration file')
@@ -306,18 +375,13 @@ class Frame_MainFrame(MainFrame):
filename = self.InputBox_FontName.GetValue()
if 'Enter a font name' in filename or len(filename) < 1:
filename = 'M5_Font'
filename = "%s_%dpx" %(filename, font_size)
self.filename = "%s_%dpx" %(filename, font_size)
self.Disable()
self.button_gen.SetLabelText('Generating...')
frame = Frame_Gerenate(parent=self, font_size = font_size)
frame.Show()
flash_size = frame.Generate(self.unicode_block, font_spacing, font_size, filename)
MessageDialog(self, wx.LOG_Message, '%s Generated, Approx. %.1f KiB' %(filename, flash_size/1024.0))
self.Enable()
self.button_gen.SetLabelText('Gerenate')
print(('Done, Approx. %.1f KiB' %(flash_size/1024.0)))
self.thread = Thread_Creator(1, self.queue_info, self.unicode_block, self, font_size, font_spacing, self.filename)
self.thread.start()
self.timer.Start(50)
class Frame_NewFont(NewFont):
def __init__(self, parent):
@@ -422,16 +486,16 @@ class Frame_NewFont(NewFont):
if unicode_start > unicode_end or unicode_start < 0 or unicode_end > 0xFFFF:
raise Exception('Invalid Unicode Block: start bigger than end')
unicode_block_list = []
unicode_range_list = []
item = -1
while True:
item = self.parent.listctrl_fontinfo.GetNextItem(item)
if item == -1:
break
unicode_block_list.append((int(self.parent.listctrl_fontinfo.GetItemText(item, 1), 16),\
unicode_range_list.append((int(self.parent.listctrl_fontinfo.GetItemText(item, 1), 16),\
int(self.parent.listctrl_fontinfo.GetItemText(item, 2), 16)))
for block in unicode_block_list:
for block in unicode_range_list:
if unicode_start >= block[0] and unicode_start <= block[1]:
raise Exception('Conflict Unicode Block: start in other block (0x%04X - 0x%04X)' %(block[0], block[1]))
if unicode_end >= block[0] and unicode_end <= block[1]:
@@ -444,6 +508,7 @@ class Frame_NewFont(NewFont):
raise Exception('Invalid Font: %s' %self.font_name)
self.parent.listctrl_fontinfo.Append([self.font_name, '0x%04X' %unicode_start, '0x%04X' %unicode_end])
self.parent.unicode_block.append([unicode_start, unicode_end, self.preview_font, self.offset_UD, self.offset_LR])
self.parent.unicode_range_list = unicode_range_list
self.FrameOnClose_Cb(event)
except Exception as err:
MessageDialog(self, wx.LOG_Warning, str(err))
@@ -454,6 +519,9 @@ class Frame_NewFont(NewFont):
def __del__( self ):
pass
queueLock = threading.Lock()
app = wx.App(False)
frame = Frame_MainFrame(parent=None)
frame.Show()
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.