From 019a1584d02b0b8b942641ddc2bdb1ac5f1b3094 Mon Sep 17 00:00:00 2001 From: jfrickmann Date: Sat, 6 Nov 2021 16:39:18 -0400 Subject: [PATCH] Monospaced font for digits So timers etc. do not jump back and forth. Assumes that 4 is the widest digit. --- tools/build-font-bitmap.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/build-font-bitmap.py b/tools/build-font-bitmap.py index be9f6b236..c1aaafe9e 100755 --- a/tools/build-font-bitmap.py +++ b/tools/build-font-bitmap.py @@ -54,8 +54,15 @@ class FontBitmap: # default width for space width = 4 if c != ' ': - width = self.font.getmask(c).getbbox()[2] - _, (offset_x, offset_y) = self.font.font.getsize(c) + if "0123456789".find(c) >= 0 : + width = self.font.getmask("4").getbbox()[2] + _, (offset_x, offset_y) = self.font.font.getsize(c) + _, (offset_x2, offset_y2) = self.font.font.getsize("4") + offset_x = (offset_x + offset_x2) / 2 + else : + width = self.font.getmask(c).getbbox()[2] + _, (offset_x, offset_y) = self.font.font.getsize(c) + draw.text((x - offset_x, 0), c, fill=self.foreground, font=self.font) return width