This commit is contained in:
Yuzhen Qin 2022-11-08 14:46:42 +08:00
parent 538a31ab3c
commit cdad2621dc
Signed by: YuzhenQin
GPG Key ID: 92191894C8EF7171
3 changed files with 26 additions and 0 deletions

BIN
DinkieBitmap-7pxDemo.ttf Normal file

Binary file not shown.

BIN
U+4E00.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 KiB

26
fontconv.py Normal file
View File

@ -0,0 +1,26 @@
FONT_PATH = 'DinkieBitmap-7pxDemo.ttf'
GRID_SIZE = 7
GRID_PADD = 1
UNIC_FIRS = '4E00'
UNIC_LAST = '9FFF'
from PIL import Image, ImageDraw, ImageFont
first = int(UNIC_FIRS, base=16)
last = int(UNIC_LAST, base=16)
im_width = (GRID_SIZE + GRID_PADD * 2) * 16
im_height: int = int((GRID_SIZE + GRID_PADD * 2) * ((last - first + 1) / 16))
im = Image.new('RGB', (im_width, im_height), color='#FFFFFF')
draw = ImageDraw.Draw(im)
font = ImageFont.truetype(FONT_PATH, GRID_SIZE, encoding='utf-8')
x, y = 0, 0
for i in range(first, last + 1):
if y == 16:
x = x + 1
y = 0
draw.text(((GRID_SIZE + GRID_PADD * 2) * y + GRID_PADD, (GRID_SIZE + GRID_PADD * 2) * x + GRID_PADD), chr(i), '#000000', font=font)
y = y + 1
im.save(f'U+{UNIC_FIRS}.png')