get_height.py 403 B

12345678910111213141516
  1. async def get_y_and_heights(
  2. text_wrapped,
  3. dimensions,
  4. margin,
  5. font
  6. ):
  7. _, descent = font.getmetrics()
  8. line_heights = [
  9. font.getmask(
  10. text_line,
  11. ).getbbox()[3] + descent + margin for text_line in text_wrapped
  12. ]
  13. line_heights[-1] -= margin
  14. height_text = sum(line_heights)
  15. y = (dimensions[1] - height_text) // 2
  16. return y, line_heights