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 test_continue_stroke_across_multiple_spaces(self): result = [] word = self.make_text(tl.Stroke.UNDERLINE + tl.Stroke.CONTINUE, result) space = tl.Space(width=0.5) nbsp = tl.NonBreakingSpace(width=0.5) tl.render_text_strokes([word, space, nbsp, space, word]) assert len(result) == 2 assert result[ 0] == "STROKE(UNDERLINE, 4.5)", "3 spaces should be included" assert result[1] == "STROKE(UNDERLINE, 3.0)", "no following spaces"
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}"')
def test_non_breaking_space_to_space(self): space = tl.NonBreakingSpace(1).to_space() assert type(space) == tl.Space
def non_breaking_space(self, ctx: MTextContext): return tl.NonBreakingSpace(width=self.space_width(ctx))
def super_glue(): return tl.NonBreakingSpace(width=0, min_width=0, max_width=0)
def super_glue(): return text_layout.NonBreakingSpace(width=0, min_width=0, max_width=0)