mirror of
git://projects.qi-hardware.com/setfont2.git
synced 2024-11-15 07:29:43 +02:00
Add kernel 6x10 font
This commit is contained in:
parent
30bc035768
commit
1284c1e965
14
kernel-6x10/README
Normal file
14
kernel-6x10/README
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
This is a 6x10 console font.
|
||||||
|
It allows for 53x24 terminal size on Ben Nanonote.
|
||||||
|
This a fork of 6x11 regular (i.e. colored) kernel font.
|
||||||
|
|
||||||
|
This font doesn't use setfont2 (i.e. SubLCD technique),
|
||||||
|
so it looks worse than setfont2 font.
|
||||||
|
From the other hand side, it provides colors,
|
||||||
|
which might be important in some applications.
|
||||||
|
|
||||||
|
This font and conversion tools (png2font and font2png)
|
||||||
|
are in setfont2 repo because they fit with setfont2's purpose:
|
||||||
|
Provide better looking console fonts for Ben Nanonote.
|
||||||
|
|
||||||
|
Credits go to mth.
|
93
kernel-6x10/font2png.py
Executable file
93
kernel-6x10/font2png.py
Executable file
@ -0,0 +1,93 @@
|
|||||||
|
#!/usr/bin/env python2
|
||||||
|
# Converts Linux font character array to PNG.
|
||||||
|
|
||||||
|
import sys
|
||||||
|
# Python Imaging Library
|
||||||
|
# http://www.pythonware.com/products/pil/
|
||||||
|
import Image
|
||||||
|
|
||||||
|
def readSource(inp):
|
||||||
|
data = []
|
||||||
|
meta = {}
|
||||||
|
inData = False
|
||||||
|
inMeta = False
|
||||||
|
for line in inp.readlines():
|
||||||
|
csta = line.find('/*')
|
||||||
|
if csta != -1:
|
||||||
|
cend = line.index('*/') + 2
|
||||||
|
line = line[ : csta] + line[cend : ]
|
||||||
|
line = line.strip()
|
||||||
|
if inData:
|
||||||
|
if line == '};':
|
||||||
|
inData = False
|
||||||
|
elif line:
|
||||||
|
valStr = line.rstrip(',')
|
||||||
|
# Chars wider than 8 not supported yet.
|
||||||
|
assert ',' not in valStr
|
||||||
|
data.append(int(valStr, 16))
|
||||||
|
elif inMeta:
|
||||||
|
if line == '};':
|
||||||
|
inMeta = False
|
||||||
|
elif line:
|
||||||
|
key, value = line.split('=')
|
||||||
|
key = key.strip().lstrip('.')
|
||||||
|
value = value.strip().rstrip(',')
|
||||||
|
meta[key] = value
|
||||||
|
elif line.startswith('static const unsigned char'):
|
||||||
|
assert line[-1] == '{'
|
||||||
|
inData = True
|
||||||
|
elif line.startswith('const struct font_desc'):
|
||||||
|
assert line[-1] == '{'
|
||||||
|
inMeta = True
|
||||||
|
return data, meta
|
||||||
|
|
||||||
|
def createImage(width, height, data):
|
||||||
|
assert len(data) == height * 256
|
||||||
|
|
||||||
|
# Reserve space for a 32 * 8 grid of characters.
|
||||||
|
image = Image.new('P', (32 * (width + 1) + 1, 8 * (height + 1) + 1))
|
||||||
|
palette = [0, 0, 0] * 256
|
||||||
|
palette[3 : 6] = [255, 255, 255] # foreground
|
||||||
|
palette[6 : 9] = [128, 0, 0] # grid
|
||||||
|
image.putpalette(palette)
|
||||||
|
|
||||||
|
# Draw grid.
|
||||||
|
for y in xrange(0, image.size[1], height + 1):
|
||||||
|
for x in xrange(0, image.size[0]):
|
||||||
|
image.putpixel((x, y), 2)
|
||||||
|
for x in xrange(0, image.size[0], width + 1):
|
||||||
|
for y in xrange(0, image.size[1]):
|
||||||
|
image.putpixel((x, y), 2)
|
||||||
|
|
||||||
|
# Draw characters.
|
||||||
|
for c in xrange(256):
|
||||||
|
row, col = divmod(c, 32)
|
||||||
|
y = 1 + row * (height + 1)
|
||||||
|
for i in xrange(c * height, (c + 1) * height):
|
||||||
|
x = 1 + col * (width + 1)
|
||||||
|
pat = data[i]
|
||||||
|
for bit in xrange(width):
|
||||||
|
if pat & 128:
|
||||||
|
image.putpixel((x, y), 1)
|
||||||
|
pat <<= 1
|
||||||
|
x += 1
|
||||||
|
y += 1
|
||||||
|
return image
|
||||||
|
|
||||||
|
if len(sys.argv) != 2:
|
||||||
|
print >>sys.stderr, 'Usage: python font2png.py <source_file>'
|
||||||
|
sys.exit(2)
|
||||||
|
else:
|
||||||
|
fileName = sys.argv[1]
|
||||||
|
assert fileName.endswith('.c')
|
||||||
|
outFileName = fileName[ : -2] + '.png'
|
||||||
|
|
||||||
|
inp = open(fileName, 'r')
|
||||||
|
try:
|
||||||
|
data, meta = readSource(inp)
|
||||||
|
finally:
|
||||||
|
inp.close()
|
||||||
|
width = int(meta['width'])
|
||||||
|
height = int(meta['height'])
|
||||||
|
image = createImage(width, height, data)
|
||||||
|
image.save(outFileName)
|
3086
kernel-6x10/font_6x10.c
Normal file
3086
kernel-6x10/font_6x10.c
Normal file
File diff suppressed because it is too large
Load Diff
87
kernel-6x10/png2font.py
Executable file
87
kernel-6x10/png2font.py
Executable file
@ -0,0 +1,87 @@
|
|||||||
|
#!/usr/bin/env python2
|
||||||
|
# Converts PNG to Linux font character array.
|
||||||
|
|
||||||
|
import sys
|
||||||
|
# Python Imaging Library
|
||||||
|
# http://www.pythonware.com/products/pil/
|
||||||
|
import Image
|
||||||
|
|
||||||
|
def getCellSize(image):
|
||||||
|
x, y = image.size
|
||||||
|
width = (x / 32) - 1
|
||||||
|
height = (y / 8) - 1
|
||||||
|
assert 32 * (width + 1) + 1 == x, x
|
||||||
|
assert 8 * (height + 1) + 1 == y, y
|
||||||
|
return width, height
|
||||||
|
|
||||||
|
def createData(width, height, image):
|
||||||
|
data = []
|
||||||
|
|
||||||
|
# Scan characters.
|
||||||
|
for c in xrange(256):
|
||||||
|
row, col = divmod(c, 32)
|
||||||
|
y = 1 + row * (height + 1)
|
||||||
|
for i in xrange(height):
|
||||||
|
x = 1 + col * (width + 1)
|
||||||
|
pat = 0
|
||||||
|
mask = 128
|
||||||
|
for bit in xrange(width):
|
||||||
|
if image.getpixel((x, y)):
|
||||||
|
pat |= mask
|
||||||
|
mask >>= 1
|
||||||
|
x += 1
|
||||||
|
y += 1
|
||||||
|
data.append(pat)
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
if len(sys.argv) != 2:
|
||||||
|
print >>sys.stderr, 'Usage: python png2font.py <image_file>'
|
||||||
|
sys.exit(2)
|
||||||
|
else:
|
||||||
|
fileName = sys.argv[1]
|
||||||
|
assert fileName.endswith('.png')
|
||||||
|
outFileName = fileName[ : -4] + '.c'
|
||||||
|
|
||||||
|
image = Image.open(fileName)
|
||||||
|
width, height = getCellSize(image)
|
||||||
|
data = createData(width, height, image)
|
||||||
|
arrayName = 'fontdata_%dx%d' % (width, height)
|
||||||
|
|
||||||
|
out = open(outFileName, 'w')
|
||||||
|
try:
|
||||||
|
print >>out, '#include <linux/font.h>'
|
||||||
|
print >>out
|
||||||
|
# print >>out, '#define FONTDATAMAX (%d*256)' % height
|
||||||
|
# print >>out
|
||||||
|
print >>out, 'static const unsigned char %s[] = {' % arrayName
|
||||||
|
print >>out
|
||||||
|
for c in xrange(256):
|
||||||
|
if c < 32:
|
||||||
|
cs = '^%s' % chr(c + 64)
|
||||||
|
elif c >= 128:
|
||||||
|
cs = '\\%o' % c
|
||||||
|
else:
|
||||||
|
cs = chr(c)
|
||||||
|
print >>out, "\t/* %d 0x%02X '%s' */" % (c, c, cs)
|
||||||
|
for i in xrange(c * height, (c + 1) * height):
|
||||||
|
d = data[i]
|
||||||
|
ds = ''.join(
|
||||||
|
str((d >> bit) & 1)
|
||||||
|
for bit in reversed(xrange(8))
|
||||||
|
)
|
||||||
|
print >>out, '\t0x%02X, /* %s */' % (d, ds)
|
||||||
|
print >>out
|
||||||
|
print >>out, '};'
|
||||||
|
print >>out
|
||||||
|
print >>out, 'const struct font_desc font_%dx%d = {' \
|
||||||
|
% (width, height)
|
||||||
|
print >>out, '\t.idx\t= FONT%dx%d_IDX,' % (width, height)
|
||||||
|
print >>out, '\t.name\t= "%dx%d",' % (width, height)
|
||||||
|
print >>out, '\t.width\t= %d,' % width
|
||||||
|
print >>out, '\t.height\t= %d,' % height
|
||||||
|
print >>out, '\t.data\t= %s,' % arrayName
|
||||||
|
print >>out, '\t.pref\t= 0,'
|
||||||
|
print >>out, '};'
|
||||||
|
finally:
|
||||||
|
out.close()
|
Loading…
Reference in New Issue
Block a user