From c8e520653e550dc36246258642f1de6deca13c98 Mon Sep 17 00:00:00 2001 From: TG-Techie Date: Mon, 25 Feb 2019 18:44:24 -0500 Subject: [PATCH 1/7] adding text scaling --- adafruit_framebuf.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) mode change 100644 => 100755 adafruit_framebuf.py diff --git a/adafruit_framebuf.py b/adafruit_framebuf.py old mode 100644 new mode 100755 index 6a736bd..47dd539 --- a/adafruit_framebuf.py +++ b/adafruit_framebuf.py @@ -278,17 +278,24 @@ def scroll(self, delta_x, delta_y): x += dt_x y += dt_y - def text(self, string, x, y, color, *, + def _text(self, string, x, y, color, size, *, font_name="font5x8.bin"): """text is not yet implemented""" + if not self._font or self._font.font_name != font_name: # load the font! self._font = BitmapFont() w = self._font.font_width for i, char in enumerate(string): self._font.draw_char(char, - x + (i * (w + 1)), - y, self, color) + x + (i * (w + 1))*size, + y, self, color, size = size) + + def text(self, string, x, y, color, *, + font_name="font5x8.bin", size = 1): + for chunk in string.split('\n'): + self._text(chunk, x, y, color, size, font_name="font5x8.bin") + y += self._font.font_height*size def image(self, img): """Set buffer to value of Python Imaging Library image. The image should @@ -352,7 +359,8 @@ def __exit__(self, exception_type, exception_value, traceback): """cleanup on exit""" self.deinit() - def draw_char(self, char, x, y, framebuffer, color): + def draw_char(self, char, x, y, framebuffer, color, size = 1): + size = max(size, 1) # pylint: disable=too-many-arguments """Draw one character at position (x,y) to a framebuffer in a given color""" # Don't draw the character if it will be clipped off the visible area. @@ -368,7 +376,7 @@ def draw_char(self, char, x, y, framebuffer, color): for char_y in range(self.font_height): # Draw a pixel for each bit that's flipped on. if (line >> char_y) & 0x1: - framebuffer.pixel(x + char_x, y + char_y, color) + framebuffer.fill_rect(x + char_x*size, y + char_y*size, size, size, color) def width(self, text): """Return the pixel width of the specified text message.""" @@ -377,4 +385,4 @@ def width(self, text): class FrameBuffer1(FrameBuffer): # pylint: disable=abstract-method """FrameBuffer1 object. Inherits from FrameBuffer.""" - pass + pass \ No newline at end of file From 108a332ff8084384702a49e4a544b18b3e8178b2 Mon Sep 17 00:00:00 2001 From: TG-Techie <39284876+TG-Techie@users.noreply.github.com> Date: Mon, 25 Feb 2019 18:55:57 -0500 Subject: [PATCH 2/7] Update framebuf_simpletest.py --- examples/framebuf_simpletest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/framebuf_simpletest.py b/examples/framebuf_simpletest.py index 203ba08..6cd714f 100644 --- a/examples/framebuf_simpletest.py +++ b/examples/framebuf_simpletest.py @@ -34,4 +34,5 @@ def print_buffer(the_fb): fb.fill_rect(0, 0, WIDTH, HEIGHT, False) # write some text fb.text("hello", 0, 0, True) +fb.text("hello", 8, 0, True, size = 2) print_buffer(fb) From 54886c13d305ad0dee56d2c86aa4dba097d48577 Mon Sep 17 00:00:00 2001 From: TG-Techie Date: Mon, 25 Feb 2019 19:06:12 -0500 Subject: [PATCH 3/7] combine text into one func --- adafruit_framebuf.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/adafruit_framebuf.py b/adafruit_framebuf.py index 47dd539..1acf03a 100755 --- a/adafruit_framebuf.py +++ b/adafruit_framebuf.py @@ -282,21 +282,23 @@ def _text(self, string, x, y, color, size, *, font_name="font5x8.bin"): """text is not yet implemented""" - if not self._font or self._font.font_name != font_name: - # load the font! - self._font = BitmapFont() - w = self._font.font_width - for i, char in enumerate(string): - self._font.draw_char(char, - x + (i * (w + 1))*size, - y, self, color, size = size) + def text(self, string, x, y, color, *, font_name="font5x8.bin", size = 1): for chunk in string.split('\n'): - self._text(chunk, x, y, color, size, font_name="font5x8.bin") + if not self._font or self._font.font_name != font_name: + # load the font! + self._font = BitmapFont() + w = self._font.font_width + for i, char in enumerate(chunk): + self._font.draw_char(char, + x + (i * (w + 1))*size, + y, self, color, size = size) y += self._font.font_height*size + + def image(self, img): """Set buffer to value of Python Imaging Library image. The image should be in 1 bit mode and a size equal to the display size.""" From 9ac3fccfe8b71b56fd765012316075964ab1e111 Mon Sep 17 00:00:00 2001 From: TG-Techie Date: Mon, 25 Feb 2019 19:32:10 -0500 Subject: [PATCH 4/7] line ending for travis? maybe? --- adafruit_framebuf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_framebuf.py b/adafruit_framebuf.py index 1acf03a..b12e5f2 100755 --- a/adafruit_framebuf.py +++ b/adafruit_framebuf.py @@ -387,4 +387,4 @@ def width(self, text): class FrameBuffer1(FrameBuffer): # pylint: disable=abstract-method """FrameBuffer1 object. Inherits from FrameBuffer.""" - pass \ No newline at end of file + pass From 4d24cacdee42448088d42bda96d8a1fa368ad8fe Mon Sep 17 00:00:00 2001 From: TG-Techie Date: Mon, 25 Feb 2019 19:44:08 -0500 Subject: [PATCH 5/7] try index 1 --- adafruit_framebuf.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/adafruit_framebuf.py b/adafruit_framebuf.py index b12e5f2..d319bc9 100755 --- a/adafruit_framebuf.py +++ b/adafruit_framebuf.py @@ -278,14 +278,9 @@ def scroll(self, delta_x, delta_y): x += dt_x y += dt_y - def _text(self, string, x, y, color, size, *, - font_name="font5x8.bin"): - """text is not yet implemented""" - - - + # pylint: disable=too-many-arguments def text(self, string, x, y, color, *, - font_name="font5x8.bin", size = 1): + font_name="font5x8.bin", size=1): for chunk in string.split('\n'): if not self._font or self._font.font_name != font_name: # load the font! @@ -294,8 +289,9 @@ def text(self, string, x, y, color, *, for i, char in enumerate(chunk): self._font.draw_char(char, x + (i * (w + 1))*size, - y, self, color, size = size) + y, self, color, size=size) y += self._font.font_height*size + # pylint: enable=too-many-arguments @@ -361,7 +357,7 @@ def __exit__(self, exception_type, exception_value, traceback): """cleanup on exit""" self.deinit() - def draw_char(self, char, x, y, framebuffer, color, size = 1): + def draw_char(self, char, x, y, framebuffer, color, size=1): size = max(size, 1) # pylint: disable=too-many-arguments """Draw one character at position (x,y) to a framebuffer in a given color""" From 986816b4a77b3ba9b7cd98242ff1da38e05094d2 Mon Sep 17 00:00:00 2001 From: TG-Techie Date: Mon, 25 Feb 2019 20:01:23 -0500 Subject: [PATCH 6/7] travis, are you out there? --- adafruit_framebuf.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/adafruit_framebuf.py b/adafruit_framebuf.py index d319bc9..14f8837 100755 --- a/adafruit_framebuf.py +++ b/adafruit_framebuf.py @@ -281,6 +281,9 @@ def scroll(self, delta_x, delta_y): # pylint: disable=too-many-arguments def text(self, string, x, y, color, *, font_name="font5x8.bin", size=1): + """Place text on the screen in variables sizes. Breaks on \n to next line. + Does not break on line going off screen. + """ for chunk in string.split('\n'): if not self._font or self._font.font_name != font_name: # load the font! @@ -357,9 +360,9 @@ def __exit__(self, exception_type, exception_value, traceback): """cleanup on exit""" self.deinit() + # pylint: disable=too-many-arguments def draw_char(self, char, x, y, framebuffer, color, size=1): size = max(size, 1) - # pylint: disable=too-many-arguments """Draw one character at position (x,y) to a framebuffer in a given color""" # Don't draw the character if it will be clipped off the visible area. if x < -self.font_width or x >= framebuffer.width or \ From e7362323f35d1f760e9009391bfc40d581986831 Mon Sep 17 00:00:00 2001 From: TG-Techie Date: Mon, 25 Feb 2019 20:11:00 -0500 Subject: [PATCH 7/7] last one? (jinxes it) --- adafruit_framebuf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_framebuf.py b/adafruit_framebuf.py index 14f8837..5c4605c 100755 --- a/adafruit_framebuf.py +++ b/adafruit_framebuf.py @@ -362,8 +362,8 @@ def __exit__(self, exception_type, exception_value, traceback): # pylint: disable=too-many-arguments def draw_char(self, char, x, y, framebuffer, color, size=1): - size = max(size, 1) """Draw one character at position (x,y) to a framebuffer in a given color""" + size = max(size, 1) # Don't draw the character if it will be clipped off the visible area. if x < -self.font_width or x >= framebuffer.width or \ y < -self.font_height or y >= framebuffer.height: