Split text for gerty
This commit is contained in:
parent
d2b4d6c837
commit
454ae1bf95
1 changed files with 24 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
import math
|
import math
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
import json
|
import json
|
||||||
|
import textwrap
|
||||||
import httpx
|
import httpx
|
||||||
import random
|
import random
|
||||||
import os
|
import os
|
||||||
|
|
@ -267,8 +268,30 @@ async def get_exchange_rate(gerty):
|
||||||
|
|
||||||
# A helper function get a nicely formated dict for the text
|
# A helper function get a nicely formated dict for the text
|
||||||
def get_text_item_dict(text: str, font_size: int, x_pos: int = None, y_pos: int = None):
|
def get_text_item_dict(text: str, font_size: int, x_pos: int = None, y_pos: int = None):
|
||||||
|
# Get line size by font size
|
||||||
|
line_width = 60
|
||||||
|
if font_size <= 12:
|
||||||
|
line_width = 80
|
||||||
|
elif font_size <= 15:
|
||||||
|
line_width = 60
|
||||||
|
elif font_size <= 20:
|
||||||
|
line_width = 40
|
||||||
|
elif font_size <= 40:
|
||||||
|
line_width = 30
|
||||||
|
else:
|
||||||
|
line_width = 20
|
||||||
|
|
||||||
|
# wrap the text
|
||||||
|
wrapper = textwrap.TextWrapper(width=line_width)
|
||||||
|
word_list = wrapper.wrap(text=text)
|
||||||
|
|
||||||
|
multilineText = '\n'.join(word_list)
|
||||||
|
|
||||||
|
# logger.debug('multilineText')
|
||||||
|
# logger.debug(multilineText)
|
||||||
|
|
||||||
text = {
|
text = {
|
||||||
"value": text,
|
"value": multilineText,
|
||||||
"size": font_size
|
"size": font_size
|
||||||
}
|
}
|
||||||
if x_pos is None and y_pos is None:
|
if x_pos is None and y_pos is None:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue