def render_cell(text=' ', bold=False, italic=False): num_cells = wcwidth(text[0]) if num_cells < 1: return render_cell() def safe_freetype(func): try: return func(text, bold, italic, num_cells) except FontNotFound as err: safe_print('ERROR:', err, file=sys.stderr) except FreeTypeError as err: safe_print('Failed to render text:', repr(text), 'with error:', err, file=sys.stderr) ret = safe_freetype(render_text) if ret is None: return missing_glyph(num_cells, cell_width, cell_height) if num_cells == 1: first, second = ret[0], None else: first, second = ret return first, second
def render_cell(text=' ', bold=False, italic=False, underline=0, strikethrough=False): # TODO: Handle non-normalizable combining chars. Probably need to use # harfbuzz for that text = unicodedata.normalize('NFC', text)[0] if is_renderable_box_char(text): return render_box_char(text, CharTexture(), cell_width, cell_height), None width = wcwidth(text) bitmap_char = render_char(text, bold, italic, width) second = None if width == 2: if bitmap_char.columns > cell_width: bitmap_char, second = split_char_bitmap(bitmap_char) second = place_char_in_cell(second) else: second = render_cell()[0] first = place_char_in_cell(bitmap_char) def dl(f, *a): f(first, *a) if second is not None: f(second, pos, underline_thickness) if underline: t = underline_thickness if underline == 2: t = max(1, min(cell_height - underline_position - 1, t)) dl(add_curl if underline == 2 else add_line, underline_position, t) if strikethrough: pos = int(0.65 * baseline) dl(add_line, pos, underline_thickness) return first, second
def render_cell(text=' ', bold=False, italic=False): ch = text[0] width = wcwidth(ch) face = symbol_map.get(ch) or main_font[(bold, italic)] if width == 2: buf, width = WideCellTexture(), cell_width * 2 else: buf, width = CellTexture(), cell_width face.render_char(text, width, cell_height, ctypes.addressof(buf)) if width == 2: first, second = split(buf, cell_width, cell_height) else: first, second = buf, None return first, second
def render_cell(text=' ', bold=False, italic=False): # TODO: Handle non-normalizable combining chars. Probably need to use # harfbuzz for that text = unicodedata.normalize('NFC', text)[0] width = wcwidth(text) try: bitmap_char = render_char(text, bold, italic, width) except FontNotFound as err: safe_print('ERROR:', err, file=sys.stderr) return missing_glyph(width) second = None if width == 2: if bitmap_char.columns > cell_width: bitmap_char, second = split_char_bitmap(bitmap_char) second = place_char_in_cell(second) else: second = render_cell()[0] first = place_char_in_cell(bitmap_char) return first, second