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
|
occupies flash memory rather than scarce RAM. Python code built into firmware
|
||||||
is known as frozen bytecode.
|
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
|
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.
|
between ordinal values of Unicode characters not in the standard ASCII set.
|
||||||
2. Output file has comment showing creation command line.
|
2. Output file has comment showing creation command line.
|
||||||
3. Repo includes the file `extended`. Using `-k extended` creates fonts
|
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.
|
chars having ordinal values from 32-981.
|
||||||
4. Improvements to `font_test.py`.
|
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
|
Python files produced are interchangeable with those from prior versions: the
|
||||||
API is unchanged.
|
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.
|
STR01 = """# Code generated by font_to_py.py.
|
||||||
# Font: {}{}
|
# Font: {}{}
|
||||||
# Cmd: {}
|
# Cmd: {}
|
||||||
version = '0.31'
|
version = '0.32'
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -409,23 +409,21 @@ def get_ch(ch):
|
||||||
width = ifb(_mvfont[doff : ])
|
width = ifb(_mvfont[doff : ])
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Code emiited for large charsets, assumed by build_arrays() to be sparse
|
# Code emiited for large charsets, assumed by build_arrays() to be sparse.
|
||||||
# Binary sort of sparse index.
|
# Binary search of sorted sparse index.
|
||||||
STRSP = """_mvfont = memoryview(_font)
|
STRSP = """_mvfont = memoryview(_font)
|
||||||
_mvsp = memoryview(_sparse)
|
_mvsp = memoryview(_sparse)
|
||||||
ifb = lambda l : l[0] | (l[1] << 8)
|
ifb = lambda l : l[0] | (l[1] << 8)
|
||||||
|
|
||||||
def bs(lst, val):
|
def bs(lst, val):
|
||||||
n = len(lst) // 4
|
while True:
|
||||||
if n == 1:
|
m = (len(lst) & ~ 7) >> 1
|
||||||
return ifb(lst[2 : ]) if ifb(lst) == val else 0
|
v = ifb(lst[m:])
|
||||||
sp = (n // 2) * 4
|
|
||||||
v = ifb(lst[sp - 4 : ])
|
|
||||||
if v == val:
|
if v == val:
|
||||||
return ifb(lst[sp - 2 : ])
|
return ifb(lst[m + 2:])
|
||||||
if v > val:
|
if not m:
|
||||||
return 0 if sp <= 4 else bs(lst[ : sp - 4], val)
|
return 0
|
||||||
return bs(lst[sp :], val)
|
lst = lst[m:] if v < val else lst[:m]
|
||||||
|
|
||||||
def get_ch(ch):
|
def get_ch(ch):
|
||||||
doff = bs(_mvsp, ord(ch))
|
doff = bs(_mvsp, ord(ch))
|
||||||
|
|
Ładowanie…
Reference in New Issue