diff options
Diffstat (limited to 'deckit')
| -rw-r--r-- | deckit/server.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/deckit/server.py b/deckit/server.py index f644d24..bdaca9e 100644 --- a/deckit/server.py +++ b/deckit/server.py @@ -108,6 +108,18 @@ def art(): return None +_font = {} + + +def nerd_font(): + """The Nerd Font the canvas draws its icons with, for the tablet.""" + if "p" not in _font: + out = _run(["fc-match", "-f", "%{file}", "Inconsolata Nerd Font:style=Regular"]) + # fc-match falls back to any font; only a Nerd Font has the glyphs. + _font["p"] = Path(out) if "NerdFont" in out.replace(" ", "") and Path(out).is_file() else None + return _font["p"] + + def load_token() -> str: """A per-machine secret the tablet's browser holds as a cookie.""" path = token_path() @@ -167,6 +179,9 @@ class Handler(BaseHTTPRequestHandler): name = path[len("/icons/"):].removesuffix(".svg") icon = icon_path(name) return self._send(200, icon.read_bytes(), "image/svg+xml") if icon else self._send(404) + if path == "/fonts/nerd.ttf": + f = nerd_font() + return self._send(200, f.read_bytes(), "font/ttf", cache=True) if f else self._send(404) if path.startswith("/api/"): if not self._authed(): return self._send(401) |
