@@ -225,7 +225,7 @@ def DisplayText(
225225 y : int = 0 ,
226226 width : int = 0 ,
227227 height : int = 0 ,
228- font : str = "roboto-mono/RobotoMono-Regular.ttf" ,
228+ font : str = "./res/fonts/ roboto-mono/RobotoMono-Regular.ttf" ,
229229 font_size : int = 20 ,
230230 font_color : Color = (0 , 0 , 0 ),
231231 background_color : Color = (255 , 255 , 255 ),
@@ -262,11 +262,11 @@ def DisplayText(
262262 text_image = self .open_image (background_image )
263263
264264 # Get text bounding box
265- fontdata = self .open_font (font , font_size )
265+ ttfont = self .open_font (font , font_size )
266266 d = ImageDraw .Draw (text_image )
267267
268268 if width == 0 or height == 0 :
269- left , top , right , bottom = d .textbbox ((x , y ), text , font = fontdata , align = align , anchor = anchor )
269+ left , top , right , bottom = d .textbbox ((x , y ), text , font = ttfont , align = align , anchor = anchor )
270270
271271 # textbbox may return float values, which is not good for the bitmap operations below.
272272 # Let's extend the bounding box to the next whole pixel in all directions
@@ -290,7 +290,7 @@ def DisplayText(
290290 y = top
291291
292292 # Draw text onto the background image with specified color & font
293- d .text ((x , y ), text , font = fontdata , fill = font_color , align = align , anchor = anchor )
293+ d .text ((x , y ), text , font = ttfont , fill = font_color , align = align , anchor = anchor )
294294
295295 # Restrict the dimensions if they overflow the display size
296296 left = max (left , 0 )
@@ -360,6 +360,8 @@ def DisplayLineGraph(self, x: int, y: int, width: int, height: int,
360360 line_width : int = 2 ,
361361 graph_axis : bool = True ,
362362 axis_color : Color = (0 , 0 , 0 ),
363+ axis_font : str = "./res/fonts/roboto/Roboto-Black.ttf" ,
364+ axis_font_size : int = 10 ,
363365 background_color : Color = (255 , 255 , 255 ),
364366 background_image : Optional [str ] = None ):
365367 # Generate a plot graph and display it
@@ -433,15 +435,15 @@ def DisplayLineGraph(self, x: int, y: int, width: int, height: int,
433435 # Draw Legend
434436 draw .line ([0 , 0 , 1 , 0 ], fill = axis_color )
435437 text = f"{ int (max_value )} "
436- fontdata = self .open_font ("roboto/Roboto-Black.ttf" , 10 )
437- _ , top , right , bottom = fontdata .getbbox (text )
438+ ttfont = self .open_font (axis_font , axis_font_size )
439+ _ , top , right , bottom = ttfont .getbbox (text )
438440 draw .text ((2 , 0 - top ), text ,
439- font = fontdata , fill = axis_color )
441+ font = ttfont , fill = axis_color )
440442
441443 text = f"{ int (min_value )} "
442- _ , top , right , bottom = fontdata .getbbox (text )
444+ _ , top , right , bottom = ttfont .getbbox (text )
443445 draw .text ((width - 1 - right , height - 2 - bottom ), text ,
444- font = fontdata , fill = axis_color )
446+ font = ttfont , fill = axis_color )
445447
446448 self .DisplayPILImage (graph_image , x , y )
447449
@@ -479,7 +481,7 @@ def DisplayRadialProgressBar(self, xc: int, yc: int, radius: int, bar_width: int
479481 value : int = 50 ,
480482 text : Optional [str ] = None ,
481483 with_text : bool = True ,
482- font : str = "roboto/Roboto-Black.ttf" ,
484+ font : str = "./res/fonts/ roboto/Roboto-Black.ttf" ,
483485 font_size : int = 20 ,
484486 font_color : Color = (0 , 0 , 0 ),
485487 bar_color : Color = (0 , 0 , 0 ),
@@ -650,11 +652,11 @@ def DisplayRadialProgressBar(self, xc: int, yc: int, radius: int, bar_width: int
650652 if with_text :
651653 if text is None :
652654 text = f"{ int (pct * 100 + .5 )} %"
653- fontdata = self .open_font (font , font_size )
654- left , top , right , bottom = fontdata .getbbox (text )
655+ ttfont = self .open_font (font , font_size )
656+ left , top , right , bottom = ttfont .getbbox (text )
655657 w , h = right - left , bottom - top
656658 draw .text ((radius - w / 2 + text_offset [0 ], radius - top - h / 2 + text_offset [1 ]), text ,
657- font = fontdata , fill = font_color )
659+ font = ttfont , fill = font_color )
658660
659661 if custom_bbox [0 ] != 0 or custom_bbox [1 ] != 0 or custom_bbox [2 ] != 0 or custom_bbox [3 ] != 0 :
660662 bar_image = bar_image .crop (box = custom_bbox )
@@ -671,5 +673,5 @@ def open_image(self, bitmap_path: str) -> Image.Image:
671673
672674 def open_font (self , name : str , size : int ) -> ImageFont .FreeTypeFont :
673675 if (name , size ) not in self .font_cache :
674- self .font_cache [(name , size )] = ImageFont .truetype ("./res/fonts/" + name , size )
676+ self .font_cache [(name , size )] = ImageFont .truetype (name , size )
675677 return self .font_cache [(name , size )]
0 commit comments