def _generatePage(self): """Starting from all stored text inside the instance, this method return a structure as this: [ (line_text, position, color), (...) ] The returned object can be looped for write the text on the screen; too long lines are automatically splitted in more line to fit LevelText size area. """ outPage = [] line_maxlength = self.rect.w - BORDER_PADDING_H*2 y = BORDER_PADDING_V h = cblocals.leveltext_font.size("xxx")[1] for line in self._text: if type(line)!=dict: line_text = line line_color = COLOR_DEFAULT else: # dictionary line_text = line['text'] line_color = line['color'] w = cblocals.leveltext_font.size(line_text)[0] if w>line_maxlength: newtextlines = utils.normalizeTextLength(line_text, cblocals.leveltext_font, line_maxlength) else: newtextlines = [line_text,] newtextlines, y = self._preparePageLines(newtextlines, y, h, line_color) outPage.extend(newtextlines) return outPage
def _generateTextLines(cls, text): """Generate text to be displayed, but return it splitted in a list at every line break. Also, if a line is too long (longer than CLOUD_MAX_WIDTH constant) the line itself is splitted again. """ speech_font = cblocals.speech_font textlines = text.split("\n")[-MAX_TEXTLINES:] w = BORDER_PADDING + max([speech_font.size(x)[0] for x in textlines]) + BORDER_PADDING if w < CLOUD_MAX_WIDTH: return textlines # I've a problem, one or more lines are too long. newtextlines = [] for line in textlines: w = BORDER_PADDING + speech_font.size(line)[0] + BORDER_PADDING if w > CLOUD_MAX_WIDTH: newtextlines.extend(utils.normalizeTextLength(line, speech_font, CLOUD_MAX_WIDTH - BORDER_PADDING * 2)) else: newtextlines.append(line) return newtextlines[-MAX_TEXTLINES:]