kopia lustrzana https://github.com/peterhinch/micropython-font-to-py
font_to_py.py Fix bug with non-contiguous charset.
rodzic
7f4f840dda
commit
e4e33f787b
|
@ -337,15 +337,18 @@ class Font(dict):
|
||||||
|
|
||||||
def build_arrays(self, hmap, reverse):
|
def build_arrays(self, hmap, reverse):
|
||||||
data = bytearray()
|
data = bytearray()
|
||||||
index = bytearray((0, 0))
|
index = bytearray() #((0, 0))
|
||||||
for char in self.charset:
|
for char in self.charset:
|
||||||
if char == '':
|
if char == '':
|
||||||
index += (len(data)).to_bytes(2, byteorder='little')
|
index += bytearray((0, 0, 0, 0))
|
||||||
|
index[-1] = index[3]
|
||||||
|
index[-2] = index[2]
|
||||||
else:
|
else:
|
||||||
|
index += (len(data)).to_bytes(2, byteorder='little') # Start
|
||||||
width = self[char][1]
|
width = self[char][1]
|
||||||
data += (width).to_bytes(2, byteorder='little')
|
data += (width).to_bytes(2, byteorder='little')
|
||||||
data += bytearray(self.stream_char(char, hmap, reverse))
|
data += bytearray(self.stream_char(char, hmap, reverse))
|
||||||
index += (len(data)).to_bytes(2, byteorder='little')
|
index += (len(data)).to_bytes(2, byteorder='little') # End
|
||||||
return data, index
|
return data, index
|
||||||
|
|
||||||
def build_binary_array(self, hmap, reverse, sig):
|
def build_binary_array(self, hmap, reverse, sig):
|
||||||
|
@ -360,21 +363,18 @@ class Font(dict):
|
||||||
|
|
||||||
STR01 = """# Code generated by font-to-py.py.
|
STR01 = """# Code generated by font-to-py.py.
|
||||||
# Font: {}{}
|
# Font: {}{}
|
||||||
version = '0.2'
|
version = '0.25'
|
||||||
"""
|
"""
|
||||||
|
|
||||||
STR02 = """_mvfont = memoryview(_font)
|
STR02 = """_mvfont = memoryview(_font)
|
||||||
|
|
||||||
def _chr_addr(ordch):
|
|
||||||
offset = 2 * (ordch - {})
|
|
||||||
return int.from_bytes(_index[offset:offset + 2], 'little')
|
|
||||||
|
|
||||||
def get_ch(ch):
|
def get_ch(ch):
|
||||||
ordch = ord(ch)
|
ordch = ord(ch)
|
||||||
ordch = ordch + 1 if ordch >= {} and ordch <= {} else {}
|
ordch = ordch + 1 if ordch >= {} and ordch <= {} else {}
|
||||||
offset = _chr_addr(ordch)
|
idx_offs = 4 * (ordch - {})
|
||||||
|
offset = int.from_bytes(_index[idx_offs : idx_offs + 2], 'little')
|
||||||
|
next_offs = int.from_bytes(_index[idx_offs + 2 : idx_offs + 4], 'little')
|
||||||
width = int.from_bytes(_font[offset:offset + 2], 'little')
|
width = int.from_bytes(_font[offset:offset + 2], 'little')
|
||||||
next_offs = _chr_addr(ordch +1)
|
|
||||||
return _mvfont[offset + 2:next_offs], {}, width
|
return _mvfont[offset + 2:next_offs], {}, width
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -421,7 +421,7 @@ def write_data(stream, fnt, font_path, hmap, reverse):
|
||||||
bw_index = ByteWriter(stream, '_index')
|
bw_index = ByteWriter(stream, '_index')
|
||||||
bw_index.odata(index)
|
bw_index.odata(index)
|
||||||
bw_index.eot()
|
bw_index.eot()
|
||||||
stream.write(STR02.format(minchar, minchar, maxchar, minchar, height))
|
stream.write(STR02.format(minchar, maxchar, minchar, minchar, height))
|
||||||
|
|
||||||
# BINARY OUTPUT
|
# BINARY OUTPUT
|
||||||
# hmap reverse magic bytes
|
# hmap reverse magic bytes
|
||||||
|
|
Ładowanie…
Reference in New Issue