@@ -305,17 +305,26 @@ def scroll(self, delta_x, delta_y):
305305 x += dt_x
306306 y += dt_y
307307
308+ # pylint: disable=too-many-arguments
308309 def text (self , string , x , y , color , * ,
309- font_name = "font5x8.bin" ):
310- """text is not yet implemented"""
311- if not self ._font or self ._font .font_name != font_name :
312- # load the font!
313- self ._font = BitmapFont ()
314- w = self ._font .font_width
315- for i , char in enumerate (string ):
316- self ._font .draw_char (char ,
317- x + (i * (w + 1 )),
318- y , self , color )
310+ font_name = "font5x8.bin" , size = 1 ):
311+ """Place text on the screen in variables sizes. Breaks on \n to next line.
312+
313+ Does not break on line going off screen.
314+ """
315+ for chunk in string .split ('\n ' ):
316+ if not self ._font or self ._font .font_name != font_name :
317+ # load the font!
318+ self ._font = BitmapFont ()
319+ w = self ._font .font_width
320+ for i , char in enumerate (chunk ):
321+ self ._font .draw_char (char ,
322+ x + (i * (w + 1 ))* size ,
323+ y , self , color , size = size )
324+ y += self ._font .font_height * size
325+ # pylint: enable=too-many-arguments
326+
327+
319328
320329 def image (self , img ):
321330 """Set buffer to value of Python Imaging Library image. The image should
@@ -382,9 +391,9 @@ def __exit__(self, exception_type, exception_value, traceback):
382391 """cleanup on exit"""
383392 self .deinit ()
384393
385- def draw_char (self , char , x , y , framebuffer , color ):
386- # pylint: disable=too-many-arguments
394+ def draw_char (self , char , x , y , framebuffer , color , size = 1 ): # pylint: disable=too-many-arguments
387395 """Draw one character at position (x,y) to a framebuffer in a given color"""
396+ size = max (size , 1 )
388397 # Don't draw the character if it will be clipped off the visible area.
389398 #if x < -self.font_width or x >= framebuffer.width or \
390399 # y < -self.font_height or y >= framebuffer.height:
@@ -401,7 +410,7 @@ def draw_char(self, char, x, y, framebuffer, color):
401410 for char_y in range (self .font_height ):
402411 # Draw a pixel for each bit that's flipped on.
403412 if (line >> char_y ) & 0x1 :
404- framebuffer .pixel (x + char_x , y + char_y , color )
413+ framebuffer .fill_rect (x + char_x * size , y + char_y * size , size , size , color )
405414
406415 def width (self , text ):
407416 """Return the pixel width of the specified text message."""
0 commit comments