Skip to content

Commit

Permalink
Use variable font size based on length of narrative string
Browse files Browse the repository at this point in the history
  • Loading branch information
Solarmax64 committed Jun 14, 2021
1 parent 5f2dfa3 commit 86fa410
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,25 @@
draw.text((5, 5), nowTemp, inky_display.WHITE, font)
draw.text((5, 30), "Today: "+rangeMessage, inky_display.WHITE, font2)
draw.text((5, 46), dayOfWeek +": " + futureMessage, inky_display.WHITE, font2)
draw.text((5, 75), narrative[0], inky_display.WHITE, font2)
#draw.text((5, 75), narrative[0], inky_display.WHITE, font2)
# Start Variable Font Size and wrapping for Narrative
y_top = 60 # Top of the narrative area
y_bottom = 100 # Bottom of the narrative area
fontSize = 9 # Starting Font Size
fontMaxSize = 30 # Maximum font size

fontNAR = ImageFont.truetype(FredokaOne,fontSize)
while (fontNAR.getsize(narrative[0])[0] <= int(inky_display.width * .95)) and (fontSize < fontMaxSize):
# iterate until the text size is just larger than the criteria
fontSize += 1
fontNAR = ImageFont.truetype(FredokaOne, fontSize)
fontSize -= 1
fontNAR = ImageFont.truetype(FredokaOne,fontSize)
narrative_w, narrative_h = fontNAR.getsize(narrative[0])
narrative_x = int((inky_display.width - narrative_w) / 2)
narrative_y = int(y_top + ((y_bottom - y_top - narrative_h) / 2))
draw.text((narrative_x, narrative_y), narrative[0], inky_display.WHITE, fontNAR)
# End Variable Font Size for Narrative

#date
w, h = font.getsize(currentDate)
Expand Down

0 comments on commit 86fa410

Please sign in to comment.