-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdosfnt2bmp.py
executable file
·73 lines (57 loc) · 2.18 KB
/
dosfnt2bmp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
import traceback
import argparse
from PIL import ImageFont, ImageDraw, Image
from latin import LatinFont
from dkb844 import Hangul844Font
from fontx import FontXFont
bmpdir = './bmp'
basefilemap = {}
for i in os.listdir(bmpdir):
key = i[0:4]
basefilemap[key] = i
def renderInRange(charRange, fontRenderer):
for i in range(charRange[0], charRange[1] + 1):
try:
image = fontRenderer.render(i)
imageKey = "{:04x}".format(i)
if imageKey in basefilemap:
os.unlink("{}/{}".format(bmpdir, basefilemap[imageKey]))
image.save("{}/{}4.bmp".format(bmpdir, imageKey), "bmp")
except (UnicodeEncodeError, ValueError):
print("WARN: Unsupported char 0x{:04x}".format(i))
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('--latin', nargs='?', help='Latin font file')
parser.add_argument('--dkb844', nargs='?', help='Dokkaebi 844 font file')
parser.add_argument('--fontx', nargs='?', help='FONTX font file')
args = parser.parse_args()
hangulFontRenderer = Hangul844Font(args.dkb844)
#latinFontRenderer = LatinFont("./VGA-ROM.F16", 0, 8, 16)
latinFontRenderer = LatinFont(args.latin, 1626, 8, 16)
japaneseFontRenderer = FontXFont(args.fontx)
# ASCII
renderInRange((0x0000, 0x007F), latinFontRenderer)
# Hangul Jamo
renderInRange((0x1100, 0x1112), hangulFontRenderer)
renderInRange((0x1161, 0x1175), hangulFontRenderer)
renderInRange((0x11A8, 0x11C2), hangulFontRenderer)
# Hangul Compat Jamo
renderInRange((0x3131, 0x314E), hangulFontRenderer)
renderInRange((0x314F, 0x3163), hangulFontRenderer)
# Hangul Syllables
renderInRange((0xAC00, 0xD7A3), hangulFontRenderer)
# CJK Symbols and Punctuation
renderInRange((0x3000, 0x303F), japaneseFontRenderer)
# Letterlike symbols
renderInRange((0x2100, 0x214F), japaneseFontRenderer)
# Hiragana
renderInRange((0x3040, 0x309F), japaneseFontRenderer)
# Katakana
renderInRange((0x30A0, 0x30FF), japaneseFontRenderer)
# CJK Unified ideograph
renderInRange((0x4E00, 0x9FFF), japaneseFontRenderer)
# CJK Unified ideograph Extension A
renderInRange((0x3400, 0x4DBF), japaneseFontRenderer)