kopia lustrzana https://github.com/peterhinch/micropython-font-to-py
Sparse fonts use non-recursive search.
rodzic
3078e311cd
commit
b854d8f078
|
@ -9,17 +9,18 @@ targets: the font file may be incorporated into a firmware build such that it
|
|||
occupies flash memory rather than scarce RAM. Python code built into firmware
|
||||
is known as frozen bytecode.
|
||||
|
||||
## V0.31 notes
|
||||
## V0.32 notes
|
||||
|
||||
10 Sept 2019
|
||||
21 Sept 2019
|
||||
|
||||
1. Reduced output file size for sparse fonts. These result from large gaps
|
||||
between ordinal values of Unicode characters not in the standard ASCII set.
|
||||
2. Output file has comment showing creation command line.
|
||||
3. Repo includes the file `extended`. Using `-k extended` creates fonts
|
||||
comprising the printable ASCII set plus `°μπωϕθαβγδλΩ`. Such a font has 95
|
||||
comprising the printable ASCII set plus `°μπωϕθαβγδλΩ£`. Such a font has 96
|
||||
chars having ordinal values from 32-981.
|
||||
4. Improvements to `font_test.py`.
|
||||
5. Code emitted for sparse fonts now uses non-recursive search algorithm.
|
||||
|
||||
Python files produced are interchangeable with those from prior versions: the
|
||||
API is unchanged.
|
||||
|
|
2
extended
2
extended
|
@ -1 +1 @@
|
|||
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~°Ωαβγδθλμπωϕ
|
||||
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~°Ωαβγδθλμπωϕ£
|
||||
|
|
|
@ -393,7 +393,7 @@ class Font(dict):
|
|||
STR01 = """# Code generated by font_to_py.py.
|
||||
# Font: {}{}
|
||||
# Cmd: {}
|
||||
version = '0.31'
|
||||
version = '0.32'
|
||||
|
||||
"""
|
||||
|
||||
|
@ -409,23 +409,21 @@ def get_ch(ch):
|
|||
width = ifb(_mvfont[doff : ])
|
||||
"""
|
||||
|
||||
# Code emiited for large charsets, assumed by build_arrays() to be sparse
|
||||
# Binary sort of sparse index.
|
||||
# Code emiited for large charsets, assumed by build_arrays() to be sparse.
|
||||
# Binary search of sorted sparse index.
|
||||
STRSP = """_mvfont = memoryview(_font)
|
||||
_mvsp = memoryview(_sparse)
|
||||
ifb = lambda l : l[0] | (l[1] << 8)
|
||||
|
||||
def bs(lst, val):
|
||||
n = len(lst) // 4
|
||||
if n == 1:
|
||||
return ifb(lst[2 : ]) if ifb(lst) == val else 0
|
||||
sp = (n // 2) * 4
|
||||
v = ifb(lst[sp - 4 : ])
|
||||
while True:
|
||||
m = (len(lst) & ~ 7) >> 1
|
||||
v = ifb(lst[m:])
|
||||
if v == val:
|
||||
return ifb(lst[sp - 2 : ])
|
||||
if v > val:
|
||||
return 0 if sp <= 4 else bs(lst[ : sp - 4], val)
|
||||
return bs(lst[sp :], val)
|
||||
return ifb(lst[m + 2:])
|
||||
if not m:
|
||||
return 0
|
||||
lst = lst[m:] if v < val else lst[:m]
|
||||
|
||||
def get_ch(ch):
|
||||
doff = bs(_mvsp, ord(ch))
|
||||
|
|
Ładowanie…
Reference in New Issue