diff --git a/papertty/papertty.py b/papertty/papertty.py index f3f7696..9630293 100755 --- a/papertty/papertty.py +++ b/papertty/papertty.py @@ -151,7 +151,7 @@ def ttydev(vcsa): def vcsudev(self, vcsa): """Return character width and associated vcs(u) for vcsa device, - ie. for /dev/vcsa1, retunr (4, "/dev/vcsu1") if vcsu is available, or + ie. for /dev/vcsa1, return (4, "/dev/vcsu1") if vcsu is available, or (1, "/dev/vcs1") if not""" dev = vcsa.replace("vcsa", "vcsu") if os.path.exists(dev): @@ -228,7 +228,10 @@ def recalculate_font(self, font): """Load the PIL or TrueType font""" # get physical dimensions of font. Take the average width of # 1000 M's because oblique fonts a complicated. - self.font_width = font.getsize('M' * 1000)[0] // 1000 + ll, tt, rr, bb = font.getbbox('M') + #ww = (((rr * 1000) - (ll * 1000)) // 1000) + hh = bb - tt + self.font_height = hh if 'getmetrics' in dir(font): metrics_ascent, metrics_descent = font.getmetrics() self.spacing = int(self.spacing) if self.spacing != 'auto' else (metrics_descent - 2) @@ -242,7 +245,10 @@ def recalculate_font(self, font): self.spacing = int(self.spacing) if self.spacing != 'auto' else 0 # pil fonts don't seem to have metrics, but all # characters seem to have the same height - self.font_height = font.getsize('a')[1] + self.spacing + ll, tt, rr, bb = font.getbbox('A') + #ww = (((rr * 1000) - (ll * 1000)) // 1000) + hh = bb - tt + self.font_height = hh + self.spacing def init_display(self): """Initialize the display - call the driver's init method""" @@ -1202,7 +1208,11 @@ def stdin(settings, font, fontsize, width, portrait, nofold, spacing, ttyrows, t if width: text = ptty.fold(text, width) else: - font_width = ptty.font.getsize('M')[0] + ll, tt, rr, bb = ptty.font.getbbox('M') + ww = (((rr * 1000) - (ll * 1000)) // 1000) + hh = bb - tt + font_height = hh + font_width = ww max_width = int((ptty.driver.width - 8) / font_width) if portrait else int(ptty.driver.height / font_width) text = ptty.fold(text, width=max_width) if ttyrows: diff --git a/pyproject.toml b/pyproject.toml index d0bd108..9f8679a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,11 +9,13 @@ homepage = "https://github.com/joukos/PaperTTY" [tool.poetry.dependencies] click = "^7.1.2" -Pillow = "7.1.2" -python = "^3.5" -"RPi.GPIO" = "^0.7.0" -spidev = "^3.4" -vncdotool = "^1.0.0" +Pillow = "10.4.0" +python = "^3.9" +gpiozero = "^2.0.0" +lgpio = "^0.2.0.0" +"RPi.GPIO" = "^0.7.1" +spidev = "^3.6" +vncdotool = "^1.2.0" [tool.poetry.scripts] papertty = "papertty.papertty:cli"