From e82108646010cf078c53aa498452217912416f99 Mon Sep 17 00:00:00 2001 From: mdroberts1243 Date: Fri, 18 Sep 2020 20:23:08 -0400 Subject: [PATCH] Add logic to text() method The text() method did not account for rotations when checking if a character could be rendered to the framebuf. This change adjusts frame_width and frame_height checks taking rotation setting into account. Tested working with SH1107 128 x 64 OLED Featherwing. --- adafruit_framebuf.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/adafruit_framebuf.py b/adafruit_framebuf.py index 76f8dd0..37134cb 100755 --- a/adafruit_framebuf.py +++ b/adafruit_framebuf.py @@ -403,6 +403,12 @@ def text(self, string, x, y, color, *, font_name="font5x8.bin", size=1): Does not break on line going off screen. """ + # determine our effective width/height, taking rotation into account + frame_width = self.width + frame_height = self.height + if self.rotation == 1 or self.rotation == 3: + frame_width, frame_height = frame_height, frame_width + for chunk in string.split("\n"): if not self._font or self._font.font_name != font_name: # load the font! @@ -413,9 +419,9 @@ def text(self, string, x, y, color, *, font_name="font5x8.bin", size=1): char_x = x + (i * (width + 1)) * size if ( char_x + (width * size) > 0 - and char_x < self.width + and char_x < frame_width and y + (height * size) > 0 - and y < self.height + and y < frame_height ): self._font.draw_char(char, char_x, y, self, color, size=size) y += height * size