Add rendering tests
This commit is contained in:
parent
ce0e5a893f
commit
da8bf5adc7
@ -313,6 +313,7 @@ display_name(Face *self) {
|
||||
#define R(x) if (self->x) { Py_INCREF(self->x); return self->x; }
|
||||
R(full_name); R(postscript_name); R(family_name); R(path);
|
||||
#undef R
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
// Boilerplate {{{
|
||||
@ -336,6 +337,7 @@ static PyMemberDef members[] = {
|
||||
|
||||
static PyMethodDef methods[] = {
|
||||
METHODB(face_for_text, METH_VARARGS),
|
||||
METHODB(display_name, METH_NOARGS),
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
@ -178,12 +178,8 @@ def render_box_drawing(codepoint):
|
||||
return ctypes.addressof(buf), buf
|
||||
|
||||
|
||||
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, set_send_sprite_to_gpu, Screen, sprite_map_set_limits, test_render_line, current_fonts
|
||||
from kitty.icat import detect_support, show
|
||||
if not detect_support():
|
||||
raise SystemExit('Your terminal does not support the graphics protocol')
|
||||
def render_string(text, family='monospace', size=11.0, dpi=96.0):
|
||||
from kitty.fast_data_types import set_send_sprite_to_gpu, Screen, sprite_map_set_limits, test_render_line
|
||||
sprites = {}
|
||||
|
||||
def send_to_gpu(x, y, z, data):
|
||||
@ -205,6 +201,17 @@ def test_render_string(text='Hello, world!', family='monospace', size=144.0, dpi
|
||||
sp = line.sprite_at(i)
|
||||
if sp != (0, 0, 0):
|
||||
cells.append(sprites[sp])
|
||||
return cell_width, cell_height, cells
|
||||
|
||||
|
||||
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 detect_support():
|
||||
raise SystemExit('Your terminal does not support the graphics protocol')
|
||||
|
||||
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)
|
||||
|
||||
@ -5,11 +5,11 @@
|
||||
from collections import OrderedDict
|
||||
|
||||
from kitty.fast_data_types import (
|
||||
set_send_sprite_to_gpu, sprite_map_set_layout, sprite_map_set_limits,
|
||||
test_render_line, test_sprite_position_for
|
||||
set_send_sprite_to_gpu, sprite_map_set_layout,
|
||||
sprite_map_set_limits, test_render_line, test_sprite_position_for
|
||||
)
|
||||
from kitty.fonts.box_drawing import box_chars
|
||||
from kitty.fonts.render import set_font_family
|
||||
from kitty.fonts.render import render_string, set_font_family
|
||||
|
||||
from . import BaseTest
|
||||
|
||||
@ -51,3 +51,11 @@ class Rendering(BaseTest):
|
||||
line = s.line(0)
|
||||
test_render_line(line)
|
||||
self.assertEqual(len(self.sprites), prerendered + len(box_chars))
|
||||
|
||||
def test_rendering(self):
|
||||
text = 'He\u0347\u0305llo\u0341, w\u0302or\u0306l\u0354d!'
|
||||
cells = render_string(text)[-1]
|
||||
self.ae(len(cells), len(text.encode('ascii', 'ignore')))
|
||||
text = '你好,世界'
|
||||
cells = render_string(text)[-1]
|
||||
self.ae(len(cells), 9)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user