Exemplo n.º 1
0
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}"')
Exemplo n.º 2
0
 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
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
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}"')