summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2020-04-14 19:00:04 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2020-04-14 19:00:04 (GMT)
commita77301ec64b9c3f88e699e89c554b21aa18fc50b (patch)
tree3dd03ce0045adf69be350a20c95e8b943c62524b
parent64afea0d0700edde10723bd243c2a4193d41063d (diff)
fonts: Add sans36 (numerals only)
At 36pt this is already gobbling a fair bit of flash so, for now, we've restricted this only numerals (and colon).
-rw-r--r--wasp/fonts/__init__.py18
-rw-r--r--wasp/fonts/sans36.py149
2 files changed, 167 insertions, 0 deletions
diff --git a/wasp/fonts/__init__.py b/wasp/fonts/__init__.py
new file mode 100644
index 0000000..917fb00
--- /dev/null
+++ b/wasp/fonts/__init__.py
@@ -0,0 +1,18 @@
+# SPDX-License-Identifier: LGPL-3.0-or-later
+# Copyright (C) 2020 Daniel Thompson
+
+import fonts.sans24 as sans24
+import fonts.sans36 as sans36
+
+def height(font):
+ return font.height()
+
+def width(font, s):
+ w = 0
+ for ch in s:
+ (_, _, wc) = font.get_ch(ch)
+ w += wc + 1
+
+ return w
+
+
diff --git a/wasp/fonts/sans36.py b/wasp/fonts/sans36.py
new file mode 100644
index 0000000..683dbb5
--- /dev/null
+++ b/wasp/fonts/sans36.py
@@ -0,0 +1,149 @@
+# Code generated by font_to_py.py.
+# Font: DejaVuSans.ttf
+# Cmd: tools/micropython-font-to-py/font_to_py.py /usr/share/fonts/dejavu/DejaVuSans.ttf --xmap 36 -e 58 -s 48 -l 58 wasp/fonts/sans36.py
+version = '0.33'
+
+def height():
+ return 36
+
+def baseline():
+ return 35
+
+def max_width():
+ return 30
+
+def hmap():
+ return True
+
+def reverse():
+ return False
+
+def monospaced():
+ return False
+
+def min_ch():
+ return 48
+
+def max_ch():
+ return 58
+
+_font =\
+b'\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\
+b'\x00\x00\x00\x00\x00\x00\x00\x00\x03\xe0\x03\xe0\x03\xe0\x03\xe0'\
+b'\x03\xe0\x03\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\
+b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\xe0\x03\xe0'\
+b'\x03\xe0\x03\xe0\x03\xe0\x03\xe0\x00\x00\x1e\x00\x00\x0f\xc0\x00'\
+b'\x00\x7f\xf8\x00\x00\xff\xfc\x00\x01\xff\xfe\x00\x03\xf0\x3f\x00'\
+b'\x03\xe0\x1f\x00\x07\xc0\x0f\x80\x07\x80\x07\x80\x0f\x80\x07\xc0'\
+b'\x0f\x00\x03\xc0\x0f\x00\x03\xc0\x0f\x00\x03\xc0\x1e\x00\x01\xe0'\
+b'\x1e\x00\x01\xe0\x1e\x00\x01\xe0\x1e\x00\x01\xe0\x1e\x00\x01\xe0'\
+b'\x1e\x00\x01\xe0\x1e\x00\x01\xe0\x1e\x00\x01\xe0\x1e\x00\x01\xe0'\
+b'\x1e\x00\x01\xe0\x1e\x00\x01\xe0\x1e\x00\x01\xe0\x0f\x00\x03\xc0'\
+b'\x0f\x00\x03\xc0\x0f\x00\x03\xc0\x0f\x00\x07\xc0\x07\x80\x07\x80'\
+b'\x07\xc0\x0f\x80\x07\xe0\x1f\x00\x03\xf0\x3f\x00\x01\xff\xfe\x00'\
+b'\x00\xff\xfc\x00\x00\x7f\xf8\x00\x00\x1f\xe0\x00\x1e\x00\x00\x00'\
+b'\x00\x00\x00\x1f\x80\x00\x01\xff\x80\x00\x07\xff\x80\x00\x07\xff'\
+b'\x80\x00\x07\xe7\x80\x00\x06\x07\x80\x00\x00\x07\x80\x00\x00\x07'\
+b'\x80\x00\x00\x07\x80\x00\x00\x07\x80\x00\x00\x07\x80\x00\x00\x07'\
+b'\x80\x00\x00\x07\x80\x00\x00\x07\x80\x00\x00\x07\x80\x00\x00\x07'\
+b'\x80\x00\x00\x07\x80\x00\x00\x07\x80\x00\x00\x07\x80\x00\x00\x07'\
+b'\x80\x00\x00\x07\x80\x00\x00\x07\x80\x00\x00\x07\x80\x00\x00\x07'\
+b'\x80\x00\x00\x07\x80\x00\x00\x07\x80\x00\x00\x07\x80\x00\x00\x07'\
+b'\x80\x00\x00\x07\x80\x00\x00\x07\x80\x00\x07\xff\xff\x80\x07\xff'\
+b'\xff\x80\x07\xff\xff\x80\x07\xff\xff\x80\x00\x00\x00\x00\x1e\x00'\
+b'\x00\x7f\xc0\x00\x03\xff\xf8\x00\x0f\xff\xfc\x00\x0f\xff\xff\x00'\
+b'\x0f\xe0\x3f\x00\x0e\x00\x0f\x80\x08\x00\x07\x80\x00\x00\x07\xc0'\
+b'\x00\x00\x03\xc0\x00\x00\x03\xc0\x00\x00\x03\xc0\x00\x00\x03\xc0'\
+b'\x00\x00\x03\xc0\x00\x00\x07\x80\x00\x00\x0f\x80\x00\x00\x0f\x00'\
+b'\x00\x00\x1f\x00\x00\x00\x3e\x00\x00\x00\x7c\x00\x00\x00\xf8\x00'\
+b'\x00\x01\xf0\x00\x00\x03\xe0\x00\x00\x07\xc0\x00\x00\x0f\x80\x00'\
+b'\x00\x1f\x00\x00\x00\x3e\x00\x00\x00\x7c\x00\x00\x00\xf8\x00\x00'\
+b'\x01\xf0\x00\x00\x03\xe0\x00\x00\x07\xc0\x00\x00\x0f\xff\xff\xc0'\
+b'\x0f\xff\xff\xc0\x0f\xff\xff\xc0\x0f\xff\xff\xc0\x00\x00\x00\x00'\
+b'\x1e\x00\x00\xff\xe0\x00\x07\xff\xf8\x00\x07\xff\xfe\x00\x07\xff'\
+b'\xff\x00\x07\x00\x3f\x80\x00\x00\x0f\x80\x00\x00\x07\xc0\x00\x00'\
+b'\x03\xc0\x00\x00\x03\xc0\x00\x00\x03\xc0\x00\x00\x03\xc0\x00\x00'\
+b'\x03\xc0\x00\x00\x07\x80\x00\x00\x0f\x80\x00\x00\x3f\x00\x00\x3f'\
+b'\xfe\x00\x00\x3f\xf8\x00\x00\x3f\xfc\x00\x00\x3f\xff\x00\x00\x00'\
+b'\x3f\x80\x00\x00\x0f\xc0\x00\x00\x03\xc0\x00\x00\x03\xe0\x00\x00'\
+b'\x01\xe0\x00\x00\x01\xe0\x00\x00\x01\xe0\x00\x00\x01\xe0\x00\x00'\
+b'\x01\xe0\x00\x00\x03\xe0\x00\x00\x07\xc0\x08\x00\x0f\xc0\x0f\x00'\
+b'\x3f\x80\x0f\xff\xff\x00\x0f\xff\xfe\x00\x07\xff\xf8\x00\x00\x7f'\
+b'\xc0\x00\x1e\x00\x00\x00\x00\x00\x00\x00\xfc\x00\x00\x01\xfc\x00'\
+b'\x00\x01\xfc\x00\x00\x03\xfc\x00\x00\x07\xbc\x00\x00\x07\x3c\x00'\
+b'\x00\x0f\x3c\x00\x00\x1e\x3c\x00\x00\x1e\x3c\x00\x00\x3c\x3c\x00'\
+b'\x00\x78\x3c\x00\x00\x78\x3c\x00\x00\xf0\x3c\x00\x01\xe0\x3c\x00'\
+b'\x01\xe0\x3c\x00\x03\xc0\x3c\x00\x07\x80\x3c\x00\x07\x80\x3c\x00'\
+b'\x0f\x00\x3c\x00\x1f\x00\x3c\x00\x1e\x00\x3c\x00\x3c\x00\x3c\x00'\
+b'\x3f\xff\xff\xe0\x3f\xff\xff\xe0\x3f\xff\xff\xe0\x3f\xff\xff\xe0'\
+b'\x00\x00\x3c\x00\x00\x00\x3c\x00\x00\x00\x3c\x00\x00\x00\x3c\x00'\
+b'\x00\x00\x3c\x00\x00\x00\x3c\x00\x00\x00\x3c\x00\x00\x00\x3c\x00'\
+b'\x00\x00\x00\x00\x1e\x00\x00\x00\x00\x00\x07\xff\xfe\x00\x07\xff'\
+b'\xfe\x00\x07\xff\xfe\x00\x07\xff\xfe\x00\x07\x80\x00\x00\x07\x80'\
+b'\x00\x00\x07\x80\x00\x00\x07\x80\x00\x00\x07\x80\x00\x00\x07\x80'\
+b'\x00\x00\x07\x80\x00\x00\x07\xbf\x80\x00\x07\xff\xf0\x00\x07\xff'\
+b'\xfc\x00\x07\xff\xfe\x00\x07\x80\xff\x00\x04\x00\x1f\x00\x00\x00'\
+b'\x0f\x80\x00\x00\x07\x80\x00\x00\x07\xc0\x00\x00\x03\xc0\x00\x00'\
+b'\x03\xc0\x00\x00\x03\xc0\x00\x00\x03\xc0\x00\x00\x03\xc0\x00\x00'\
+b'\x03\xc0\x00\x00\x07\xc0\x00\x00\x07\x80\x00\x00\x0f\x80\x08\x00'\
+b'\x1f\x00\x0f\x00\x7f\x00\x0f\xff\xfe\x00\x0f\xff\xfc\x00\x0f\xff'\
+b'\xf0\x00\x01\xff\x80\x00\x1e\x00\x00\x03\xfe\x00\x00\x1f\xff\x80'\
+b'\x00\x7f\xff\x80\x00\xff\xff\x80\x01\xfc\x01\x80\x03\xf0\x00\x00'\
+b'\x03\xe0\x00\x00\x07\xc0\x00\x00\x07\x80\x00\x00\x0f\x00\x00\x00'\
+b'\x0f\x00\x00\x00\x0f\x00\x00\x00\x0f\x0f\xe0\x00\x1e\x3f\xfc\x00'\
+b'\x1e\x7f\xfe\x00\x1e\xff\xff\x00\x1f\xf8\x3f\x80\x1f\xe0\x0f\x80'\
+b'\x1f\xc0\x07\xc0\x1f\x80\x03\xc0\x1f\x80\x03\xe0\x1f\x00\x01\xe0'\
+b'\x1f\x00\x01\xe0\x1f\x00\x01\xe0\x0f\x00\x01\xe0\x0f\x00\x01\xe0'\
+b'\x0f\x00\x01\xe0\x0f\x80\x03\xe0\x07\x80\x03\xc0\x07\xc0\x07\xc0'\
+b'\x03\xe0\x0f\x80\x03\xf8\x3f\x80\x01\xff\xff\x00\x00\xff\xfe\x00'\
+b'\x00\x7f\xfc\x00\x00\x0f\xe0\x00\x1e\x00\x00\x00\x00\x00\x0f\xff'\
+b'\xff\xc0\x0f\xff\xff\xc0\x0f\xff\xff\xc0\x0f\xff\xff\x80\x00\x00'\
+b'\x07\x80\x00\x00\x0f\x80\x00\x00\x0f\x00\x00\x00\x1f\x00\x00\x00'\
+b'\x1e\x00\x00\x00\x1e\x00\x00\x00\x3e\x00\x00\x00\x3c\x00\x00\x00'\
+b'\x3c\x00\x00\x00\x78\x00\x00\x00\x78\x00\x00\x00\xf8\x00\x00\x00'\
+b'\xf0\x00\x00\x00\xf0\x00\x00\x01\xe0\x00\x00\x01\xe0\x00\x00\x03'\
+b'\xe0\x00\x00\x03\xc0\x00\x00\x03\xc0\x00\x00\x07\x80\x00\x00\x07'\
+b'\x80\x00\x00\x0f\x80\x00\x00\x0f\x00\x00\x00\x0f\x00\x00\x00\x1e'\
+b'\x00\x00\x00\x1e\x00\x00\x00\x3e\x00\x00\x00\x3c\x00\x00\x00\x3c'\
+b'\x00\x00\x00\x78\x00\x00\x00\x00\x00\x00\x1e\x00\x00\x1f\xe0\x00'\
+b'\x00\xff\xfc\x00\x01\xff\xfe\x00\x03\xff\xff\x00\x07\xf0\x3f\x80'\
+b'\x07\xc0\x0f\x80\x0f\x80\x07\xc0\x0f\x00\x03\xc0\x0f\x00\x03\xc0'\
+b'\x0f\x00\x03\xc0\x0f\x00\x03\xc0\x0f\x00\x03\xc0\x07\x80\x07\x80'\
+b'\x07\xc0\x0f\x80\x03\xf0\x3f\x00\x01\xff\xfe\x00\x00\x7f\xf8\x00'\
+b'\x00\xff\xfc\x00\x03\xff\xff\x00\x07\xe0\x1f\x80\x0f\x80\x07\xc0'\
+b'\x0f\x00\x03\xc0\x1f\x00\x03\xe0\x1e\x00\x01\xe0\x1e\x00\x01\xe0'\
+b'\x1e\x00\x01\xe0\x1e\x00\x01\xe0\x1e\x00\x01\xe0\x1f\x00\x03\xe0'\
+b'\x0f\x00\x03\xc0\x0f\x80\x07\xc0\x0f\xe0\x1f\x80\x07\xff\xff\x80'\
+b'\x03\xff\xff\x00\x00\xff\xfc\x00\x00\x1f\xe0\x00\x1e\x00\x00\x1f'\
+b'\xc0\x00\x00\xff\xf0\x00\x01\xff\xfc\x00\x03\xff\xfe\x00\x07\xf0'\
+b'\x7f\x00\x0f\xc0\x1f\x00\x0f\x80\x0f\x80\x0f\x00\x07\x80\x1f\x00'\
+b'\x07\xc0\x1e\x00\x03\xc0\x1e\x00\x03\xc0\x1e\x00\x03\xc0\x1e\x00'\
+b'\x03\xe0\x1e\x00\x03\xe0\x1e\x00\x03\xe0\x1f\x00\x07\xe0\x0f\x00'\
+b'\x07\xe0\x0f\x80\x0f\xe0\x0f\xc0\x1f\xe0\x07\xf0\x7f\xe0\x03\xff'\
+b'\xfd\xe0\x01\xff\xf9\xe0\x00\xff\xf1\xe0\x00\x1f\xc3\xc0\x00\x00'\
+b'\x03\xc0\x00\x00\x03\xc0\x00\x00\x07\xc0\x00\x00\x07\x80\x00\x00'\
+b'\x0f\x80\x00\x00\x1f\x00\x00\x00\x3f\x00\x06\x00\xfe\x00\x07\xff'\
+b'\xfc\x00\x07\xff\xf8\x00\x07\xff\xe0\x00\x01\xff\x00\x00\x10\x00'\
+b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\
+b'\x00\x00\x00\x00\x00\x00\x03\xe0\x03\xe0\x03\xe0\x03\xe0\x03\xe0'\
+b'\x03\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\
+b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\xe0\x03\xe0\x03\xe0'\
+b'\x03\xe0\x03\xe0\x03\xe0\x00\x00'
+
+_index =\
+b'\x00\x00\x4a\x00\xdc\x00\x6e\x01\x00\x02\x92\x02\x24\x03\xb6\x03'\
+b'\x48\x04\xda\x04\x6c\x05\xfe\x05\x48\x06'
+
+_mvfont = memoryview(_font)
+_mvi = memoryview(_index)
+ifb = lambda l : l[0] | (l[1] << 8)
+
+def get_ch(ch):
+ oc = ord(ch)
+ ioff = 2 * (oc - 48 + 1) if oc >= 48 and oc <= 58 else 0
+ doff = ifb(_mvi[ioff : ])
+ width = ifb(_mvfont[doff : ])
+
+ next_offs = doff + 2 + ((width - 1)//8 + 1) * 36
+ return _mvfont[doff + 2:next_offs], 36, width
+