Work on scaled rendering for box drawing chars

This commit is contained in:
Kovid Goyal
2024-11-22 12:36:11 +05:30
parent 47a1a9b83d
commit 383e1f8f57
10 changed files with 196 additions and 79 deletions

View File

@@ -19,7 +19,7 @@ from typing import Optional
from unittest import TestCase
from kitty.config import finalize_keys, finalize_mouse_mappings
from kitty.fast_data_types import Cursor, HistoryBuf, LineBuf, Screen, get_options, monotonic, set_options
from kitty.fast_data_types import TEXT_SIZE_CODE, Cursor, HistoryBuf, LineBuf, Screen, get_options, monotonic, set_options
from kitty.options.parse import merge_result_dicts
from kitty.options.types import Options, defaults
from kitty.rgb import to_color
@@ -37,6 +37,11 @@ def parse_bytes(screen, data, dump_callback=None):
screen.test_parse_written_data(dump_callback)
def draw_multicell(screen: Screen, text: str, width: int = 0, scale: int = 1, subscale: int = 0, vertical_align: int = 0) -> None:
cmd = f'\x1b]{TEXT_SIZE_CODE};w={width}:s={scale}:f={subscale}:v={vertical_align};{text}\a'
parse_bytes(screen, cmd.encode())
class Callbacks:
def __init__(self, pty=None) -> None:

View File

@@ -23,7 +23,7 @@ from kitty.fonts.common import FontSpec, all_fonts_map, face_from_descriptor, ge
from kitty.fonts.render import coalesce_symbol_maps, render_string, setup_for_testing, shape_string
from kitty.options.types import Options
from . import BaseTest
from . import BaseTest, draw_multicell
def parse_font_spec(spec):
@@ -207,6 +207,30 @@ class Rendering(BaseTest):
test_render_line(line)
self.assertEqual(len(self.sprites) - prerendered, len(box_chars))
def test_scaled_box_drawing(self):
full_block = b'\xff' * len(next(iter(self.sprites.values())))
empty_block = b'\0' * len(full_block)
upper_half_block = (b'\xff' * (len(full_block) // 2)) + (b'\0' * (len(full_block) // 2))
lower_half_block = (b'\0' * (len(full_block) // 2)) + (b'\xff' * (len(full_block) // 2))
s = self.create_screen(cols=8, lines=8, scrollback=0)
def block_test(a=empty_block, b=empty_block, c=empty_block, d=empty_block, scale=2, subscale=1, vertical_align=0):
s.reset()
before = len(self.sprites)
draw_multicell(s, '', scale=scale, subscale=subscale, vertical_align=vertical_align)
test_render_line(s.line(0))
self.ae(len(self.sprites), before + 2)
test_render_line(s.line(1))
self.ae(len(self.sprites), before + 4)
blocks = tuple(self.sprites)[before:]
for expected, actual in zip((a, b, c, d), blocks):
self.ae(self.sprites[actual], expected)
block_test(full_block, full_block, full_block, full_block, subscale=0)
block_test(a=full_block)
block_test(c=full_block, vertical_align=1)
block_test(a=lower_half_block, c=upper_half_block, vertical_align=2)
def test_font_rendering(self):
render_string('ab\u0347\u0305你好|\U0001F601|\U0001F64f|\U0001F63a|')
text = 'He\u0347\u0305llo\u0341, w\u0302or\u0306l\u0354d!'

View File

@@ -2,9 +2,10 @@
# License: GPLv3 Copyright: 2024, Kovid Goyal <kovid at kovidgoyal.net>
from kitty.fast_data_types import TEXT_SIZE_CODE, Screen
from kitty.fast_data_types import TEXT_SIZE_CODE
from . import BaseTest, parse_bytes
from . import BaseTest
from . import draw_multicell as multicell
class TestMulticell(BaseTest):
@@ -13,11 +14,6 @@ class TestMulticell(BaseTest):
test_multicell(self)
def multicell(screen: Screen, text: str, width: int = 0, scale: int = 1, subscale: int = 0) -> None:
cmd = f'\x1b]{TEXT_SIZE_CODE};w={width}:s={scale}:f={subscale};{text}\a'
parse_bytes(screen, cmd.encode())
def test_multicell(self: TestMulticell) -> None:
def ac(x_, y_, **assertions): # assert cell