galmuri/files/updateChar.py

31 lines
1.5 KiB
Python
Raw Normal View History

2022-10-23 12:32:37 +03:00
#!/usr/bin/env python
import os
import re
from bs4 import BeautifulSoup
fonts = ['Galmuri14', 'Galmuri11', 'Galmuri11-Bold', 'Galmuri11-Condensed', 'Galmuri9', 'Galmuri7']
chars = ['hangul', 'ksx1001', 'ksc5601', 'cp949', 'jis0201', 'jis0208', 'jis0212', 'shiftjis', 'cp932']
for font in fonts:
with open(os.getcwd() + '/dist/' + font + '.bdf', 'rt', encoding='utf8') as f:
fontArr = re.findall(r'^STARTCHAR U\+([\d\w]{4})', f.read(), re.MULTILINE)
for char in chars:
with open(os.getcwd() + '/files/charsets/' + char + '.txt', 'rt', encoding='utf8') as c:
if char == 'hangul':
charArr = re.findall(r'^\d{1,5}\t(?:-|[\d\w]{4})\t(?:-|[\d\w]{4})\t(?:-|[\d\w]{4})\t(?:-|[\d\w]{4})\t(?:-|[\d\w]{4})\t([\d\w]{4})', c.read(), re.MULTILINE)
else:
charArr = re.findall(r'^0x[\d\w]{2,4}(?:\t|\s{2})0x([\d\w]{4})', c.read(), re.MULTILINE)
2022-10-23 13:17:56 +03:00
available = len(set(fontArr) & set(charArr))
2022-10-23 12:32:37 +03:00
all = len(set(charArr))
with open(os.getcwd() + '/charsets.html', 'rt', encoding='utf8') as h:
bs = BeautifulSoup(h.read(), 'html.parser')
2022-10-23 13:17:56 +03:00
bs.select_one('#' + font + '_' + char + '>span:first-child').string = str(available) + ' / ' + str(all)
2022-10-23 12:32:37 +03:00
bs.select_one('#' + font + '_' + char + '>span:last-child').string = str(round(available / all * 100, 3)) + ' %'
bs.select_one('style').append('#' + font + '_' + char + '::before{width:' + str(available / all * 100) + '%}')
with open(os.getcwd() + '/charsets.html', 'wt', encoding='utf8') as h:
h.write(str(bs))