diff options
author | jaseg <code@jaseg.net> | 2016-01-02 00:48:14 +0100 |
---|---|---|
committer | jaseg <code@jaseg.net> | 2016-01-02 01:29:02 +0100 |
commit | fefb33736af4afddf539a1eff6d2d5d257d57f36 (patch) | |
tree | 57cc374251cc54a6c3c06fc6ac654effb6eb9e22 /host/bdf.py | |
parent | 330e1eb20ec751256ea1cee7a6b100e1cb2d3a72 (diff) | |
download | matelight-fefb33736af4afddf539a1eff6d2d5d257d57f36.tar.gz matelight-fefb33736af4afddf539a1eff6d2d5d257d57f36.tar.bz2 matelight-fefb33736af4afddf539a1eff6d2d5d257d57f36.zip |
Host: Made rendering pipeline a bit more flexible
Diffstat (limited to 'host/bdf.py')
-rw-r--r-- | host/bdf.py | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/host/bdf.py b/host/bdf.py index b386426..a8fc8f3 100644 --- a/host/bdf.py +++ b/host/bdf.py @@ -27,7 +27,6 @@ def printframe(fb): numpy.copyto(dbuf[2::4], ip[2::3+rgba]) lib.console_render_buffer(dbuf.ctypes.data_as(POINTER(c_uint8)), config.display_width, config.display_height) - class Font: def __init__(self, fontfile='unifont.bdf'): self.font = lib.read_bdf_file(fontfile) @@ -36,16 +35,16 @@ class Font: self.cbuf = create_string_buffer(config.frame_size*sizeof(COLOR)) self.cbuflock = threading.Lock() - def compute_text_bounds(text): + def compute_text_bounds(self, text): textbytes = text.encode() textw, texth = c_size_t(0), c_size_t(0) - res = lib.framebuffer_get_text_bounds(textbytes, unifont, byref(textw), byref(texth)) + res = lib.framebuffer_get_text_bounds(textbytes, self.font, byref(textw), byref(texth)) if res: raise ValueError('Invalid text') return textw.value, texth.value - def render_text(text, offset): - with cbuflock: + def render_text(self, text, offset): + with self.cbuflock: textbytes = bytes(str(text), 'UTF-8') res = lib.framebuffer_render_text(textbytes, self.font, self.cbuf, config.display_width, config.display_height, offset) @@ -53,4 +52,4 @@ class Font: raise ValueError('Invalid text') return self.cbuf - +unifont = Font() |