You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

704 lines
15 KiB

#!/usr/bin/env python3
# MIT License
#
# Copyright (c) 2021 Eugenio Parodi <ceccopierangiolieugenio AT googlemail DOT com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# The 5x5 font mapping is freely adapted from:
# https://github.com/marekmaskarinec/minifont
fontMap = {
' ': [
0,0,0,0,0,0,
0,0,0,0,0,0,
0,0,0,0,0,0,
0,0,0,0,0,0,
0,0,0,0,0,0,
0,0,0,0,0,0, ],
'!': [
0,0,0,0,0,0,
0,0,1,0,0,0,
0,0,1,0,0,0,
0,0,1,0,0,0,
0,0,0,0,0,0,
0,0,1,0,0,0, ],
'\'': [
0,0,0,0,0,0,
0,0,1,0,0,0,
0,0,1,0,0,0,
0,0,0,0,0,0,
0,0,0,0,0,0,
0,0,0,0,0,0, ],
'"': [
0,0,0,0,0,0,
0,1,0,1,0,0,
0,1,0,1,0,0,
0,0,0,0,0,0,
0,0,0,0,0,0,
0,0,0,0,0,0, ],
'#': [
0,0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0,0,
0,1,0,1,0,0,
0,0,1,0,0,0,
0,1,0,1,0,0, ],
'y': [
0,0,0,0,0,0,
0,0,0,0,0,0,
0,1,0,1,0,0,
0,1,0,1,0,0,
0,0,1,0,0,0,
0,1,0,0,0,0, ],
'z': [
0,0,0,0,0,0,
0,0,0,0,0,0,
0,1,1,1,0,0,
0,0,1,1,0,0,
0,1,1,0,0,0,
0,1,1,1,0,0, ],
'~': [
0,0,0,0,0,0,
0,0,0,0,0,0,
0,1,0,0,0,0,
1,0,1,0,1,0,
0,0,0,1,0,0,
0,0,0,0,0,0, ],
}
def chFromBitMap(a,b,c,d):
# 0x00 0x01 0x02 0x03
quad = [ ' ', '', '', '',
# 0x04 0x05 0x06 0x07
'', '', '', '',
# 0x08 0x09 0x0A 0x0B
'', '', '', '',
# 0x0C 0x0D 0x0E 0x0F
'', '', '', '']
return quad[0x01*a+0x02*b+0x04*c+0x08*d]
print("fontMap = {")
for f in fontMap:
if f == '\'' or f == '\\':
print (f" '\\{f}':[")
else:
print (f" '{f}':[")
for y in range(3):
print(' "', end='')
for x in range(3):
a = fontMap[f][y*12 + x*2]
b = fontMap[f][y*12 + x*2+1]
c = fontMap[f][y*12+6 + x*2]
d = fontMap[f][y*12+6 + x*2+1]
ch = chFromBitMap(a,b,c,d)
#print(f"'{ch}',", end='')
print(f"{ch}", end='')
print('",')
print(' ],')
print("}")