def str2cells(s: str, content=3, space=0.5): # t ... text cell # f ... fraction cell # space is space # ~ ... non breaking space (nbsp) # # ... tabulator for c in s.lower(): if c == "t": yield tl.Text(width=content, height=1, renderer=Rect("Text")) elif c == "f": cell = tl.Text(content / 2, 1) yield tl.Fraction( top=cell, bottom=cell, stacking=tl.Stacking.SLANTED, renderer=Rect("Fraction"), ) elif c == " ": yield tl.Space(width=space) elif c == "~": yield tl.NonBreakingSpace(width=space) elif c == "#": yield tl.Tabulator(width=0) # Tabulators do not need a width else: raise ValueError(f'unknown cell type "{c}"')
def fraction(stacking, x, y): result = [] a = tl.Text(1, 1, renderer=Rect("A", result)) b = tl.Text(1, 1, renderer=Rect("B", result)) fr = tl.Fraction(a, b, stacking, renderer=Rect("Fraction", result)) fr.place(x, y) fr.render() return result
def fraction(self, data: Tuple, ctx: MTextContext) -> tl.ContentCell: upr, lwr, type_ = data if type_: return tl.Fraction( top=self.word(upr, ctx), bottom=self.word(lwr, ctx), stacking=self.get_stacking(type_), renderer=self.renderer, ) else: return self.word(upr, ctx)
def fraction(self, data: Tuple, ctx: MTextContext) -> tl.ContentCell: upr, lwr, type_ = data if type_: return tl.Fraction( top=self.word(upr, ctx), bottom=self.word(lwr, ctx), stacking=self.get_stacking(type_), # renders just the divider line: renderer=FrameRenderer(self.current_base_attribs, self.layout), ) else: return self.word(upr, ctx)
def fraction(self, data: Tuple[str, str, str], ctx: MTextContext) -> tl.ContentCell: upr, lwr, type_ = data if type_: return tl.Fraction( top=self.word(upr, ctx), bottom=self.word(lwr, ctx), stacking=self.get_stacking(type_), # renders just the divider line: renderer=FrameRenderer(self._properties, self._backend), ) else: return self.word(upr, ctx)
def str2cells(s: str, content=3, space=0.5): # t ... text cell # f ... fraction cell # space is space # ~ ... non breaking space (nbsp) for c in s.lower(): if c == 't': yield tl.Text(width=content, height=1, renderer=Rect('Text')) elif c == 'f': cell = tl.Text(content / 2, 1) yield tl.Fraction(top=cell, bottom=cell, stacking=tl.Stacking.SLANTED, renderer=Rect('Fraction')) elif c == ' ': yield tl.Space(width=space) elif c == '~': yield tl.NonBreakingSpace(width=space) else: raise ValueError(f'unknown cell type "{c}"')