示例#1
0
文件: render.py 项目: kosmaks/kitty
def test_render_string(text='Hello, world!', family='monospace', size=64.0, dpi=96.0):
    from kitty.fast_data_types import concat_cells, current_fonts

    cell_width, cell_height, cells = render_string(text, family, size, dpi)
    rgb_data = concat_cells(cell_width, cell_height, True, tuple(cells))
    cf = current_fonts()
    fonts = [cf['medium'].display_name()]
    fonts.extend(f.display_name() for f in cf['fallback'])
    msg = 'Rendered string {} below, with fonts: {}\n'.format(text, ', '.join(fonts))
    try:
        print(msg)
    except UnicodeEncodeError:
        sys.stdout.buffer.write(msg.encode('utf-8') + b'\n')
    display_bitmap(rgb_data, cell_width * len(cells), cell_height)
    print('\n')
示例#2
0
def test_render_string(text='Hello, world!', family='monospace', size=144.0, dpi=96.0):
    from tempfile import NamedTemporaryFile
    from kitty.fast_data_types import concat_cells, current_fonts
    from kitty.icat import detect_support, show
    if not hasattr(test_render_string, 'detected') and not detect_support():
        raise SystemExit('Your terminal does not support the graphics protocol')
    test_render_string.detected = True

    cell_width, cell_height, cells = render_string(text, family, size, dpi)
    rgb_data = concat_cells(cell_width, cell_height, tuple(cells))
    with NamedTemporaryFile(delete=False) as f:
        f.write(rgb_data)
    cf = current_fonts()
    fonts = [cf['medium'].display_name()]
    fonts.extend(f.display_name() for f in cf['fallback'])
    msg = 'Rendered string {} below, with fonts: {}\n'.format(text, ', '.join(fonts))
    try:
        print(msg)
    except UnicodeEncodeError:
        sys.stdout.buffer.write(msg.encode('utf-8') + b'\n')
    show(f.name, cell_width * len(cells), cell_height, 24)
    print('\n')
示例#3
0
 def join_cells(cells: Iterable[bytes]) -> bytes:
     cells = tuple(bytes(x) for x in cells)
     return concat_cells(width, height, False, cells)
示例#4
0
 def join_cells(*cells: bytes) -> bytes:
     cells = tuple(bytes(x) for x in cells)
     return concat_cells(width, height, False, cells)
示例#5
0
 def join_cells(cells):
     cells = tuple(bytes(x) for x in cells)
     return concat_cells(width, height, cells)