aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <jaseg@jaseg.net>2013-12-26 17:11:39 +0100
committerjaseg <jaseg@jaseg.net>2013-12-26 17:11:39 +0100
commit5453ec53e99d56171a2059f2e9705d1f1ae9ce83 (patch)
treed3e6886015e2bc45c088320e6b2307435b6a0b49
parent93592ee43978005a86e0d83486c7b866e2c1b61f (diff)
downloadmatelight-5453ec53e99d56171a2059f2e9705d1f1ae9ce83.tar.gz
matelight-5453ec53e99d56171a2059f2e9705d1f1ae9ce83.tar.bz2
matelight-5453ec53e99d56171a2059f2e9705d1f1ae9ce83.zip
Uhm, foo.
-rw-r--r--host/matelight/config.py17
-rw-r--r--host/matelight/renderers.py6
2 files changed, 17 insertions, 6 deletions
diff --git a/host/matelight/config.py b/host/matelight/config.py
index d8cdde1..2177292 100644
--- a/host/matelight/config.py
+++ b/host/matelight/config.py
@@ -1,3 +1,4 @@
+import bdflib # Used to read the bitmap font
# Hard timeout in seconds after which (approximately) the rendering of a single item will be cut off
RENDERER_TIMEOUT = 20.0
@@ -8,12 +9,18 @@ DEFAULT_SCROLL_SPEED = 4
# Pixels to leave blank between two letters
LETTER_SPACING = 1
+FONT = bdflib.reader.read_bdf(open('fonts/5x8.bdf').readlines())
+FONT_WIDTH = 5
+
+# Computed value
+FONT_PADDED_BINARY = ('{:0'+str(FONT_WIDTH+'b}').format
+
# Display geometry
-# ┌─────────┐ ┌──┬──┬──┬ ⋯ ┬──┬──┬──┐
-# │1 o o o 5│ │ 1│ │ │ │ │ │16│
-# │6 o o o o│ ├──┼──┼──┼ ⋯ ┼──┼──┼──┤
-# │o o o o o│ │17│ │ │ │ │ │32│
-# │o o o o20│ └──┴──┴──┴ ⋯ ┴──┴──┴──┘
+# ┌─────────┐ ┌───┬───┬ ⋯ ┬───┬───┐
+# │1 o o o 5│ │ 1 │ │ │ │16 │
+# │6 o o o o│ ├───┼───┼ ⋯ ┼───┼───┤
+# │o o o o o│ │17 │ │ │ │32 │
+# │o o o o20│ └───┴───┴ ⋯ ┴───┴───┘
# └─────────┘
CRATE_WIDTH = 5
CRATE_HEIGHT = 4
diff --git a/host/matelight/renderers.py b/host/matelight/renderers.py
index 4508063..0e223a2 100644
--- a/host/matelight/renderers.py
+++ b/host/matelight/renderers.py
@@ -5,6 +5,7 @@ except ImportError:
import re
from PIL import Image
from pixelterm import xtermcolors
+from config import *
default_palette = [
(0x00, 0x00, 0x00), # 0 normal colors
@@ -72,7 +73,10 @@ class CharGenerator:
def generate_char(self, c, now):
fg, bg = self.bg, self.bg if self.blink and now%1.0 < 0.3 else self.fg, self.bg
- ...
+ glyph = font.glyphs_by_codepoint[c]
+ # Please forgive the string manipulation below.
+ lookup = {'0': bg, '1': fg}
+ return [ list(map(lookup.get, FONT_PADDED_BINARY(int(row, 16)))) for row in glyph.get_data() ]
def generate(self, now):
chars = [self.generate_char(c, now) for c in self.text]