def create_body(lines): """ Create a surface representing the body of a tweet (the actual words in the tweet). Takes a matrix of Words (each row is a line) as input. """ MAX_LENGTH = config2.config['max_text_length'] words = [] for line in lines: for word in line: word.text = word.text.rstrip() words.append(word) while True: bigWord = None for word in words: if len(word.text) > MAX_LENGTH: bigWord = word break if bigWord == None: break index = words.index(bigWord) beginChunk = bigWord.text[:MAX_LENGTH] newWord = Word(beginChunk) newWord.color = bigWord.color bigWord.text = bigWord.text[MAX_LENGTH:] words = words[:index] + [newWord] + words[index:] surfs = [] word_surfs = [] line_len = 0 for word in words: word_len = len(word.text) if word_len + line_len > MAX_LENGTH: line_surf = make_row(word_surfs, WHITE) surfs.append(line_surf) word_surfs = [] line_len = 0 try: line_len += len(word.text) word_surf = Tweet.font.render(word.text + ' ', 1, word.color) word_surfs.append(word_surf) except: logging.exception("Error when rendering Word") if len(word_surfs) != 0: line_surf = make_row(word_surfs, WHITE) surfs.append(line_surf) return make_column(surfs, WHITE)
def create_body(lines): """ Create a surface representing the body of a tweet (the actual words in the tweet). Takes a matrix of Words (each row is a line) as input. """ surfs = [] for line in lines: word_surfs = [] for word in line: try: surf = Tweet.font.render(word.text + ' ', 1, word.color) word_surfs.append(surf) except: logging.exception("Error when rendering Word") if len(word_surfs) == 0: continue line = make_row(word_surfs, WHITE) surfs.append(line) return make_column(surfs, WHITE)