def add_dialog(self, layer=0, start=0, end=5000, style=None, actor="", effect="", text="", tag="", comment=False): if not isinstance(start, Time): start = Time(start) if not isinstance(end, Time): end = Time(end) if not style: style = self.get_style("Default").as_dict() else: style = style.as_dict() dialog_item = { "layer": layer, "start": start.strtime, "end": end.strtime, "style": style, "actor": actor, "effect": effect, "text": text, "comment": comment } d = Dialog(dialog_item, self.resolution) d.tag = tag self.add(d)
def _chars(self): charas = [] for i, s in enumerate(self.syls): cleft = s.left line_start = s.start line_end = s.end char_n = len(s.text) # For syls of one char if char_n == 1 or char_n == 0: duration = s.dur else: duration = Time(int(round(s.dur.ms / char_n, 0))) for ci, char in enumerate(s.text): start = line_start line_start += duration width = Text(s.style, char).width + self.style._fix_width if ci == char_n - 1: # Ensure that the end time and the width of the last char # is the same that the end time and width of the syl end = line_end else: end = line_start char_item = { "layer": s.layer, "start": start.strtime, "end": end.strtime, "style": s.style.as_dict(), "actor": s.actor, "inline": s.inline, "effect": s.effect, "text": char.strip(), "comment": False, "sylstart": s.start, "sylend": s.end, } charas.append(Char(char_item, self.resolution, cleft)) cleft += width return charas