mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-02 20:53:37 +02:00
Fix render_box_cell test with odd block height
This commit is contained in:
@@ -764,11 +764,11 @@ calculate_regions_for_line(RunFont rf, unsigned cell_height, Region *src, Region
|
||||
}
|
||||
}
|
||||
Region dest_in_full_coords = {.top = rf.multicell_y * cell_height, .bottom = (rf.multicell_y + 1) * cell_height};
|
||||
unsigned intersetion_top = MAX(src_in_full_coords.top, dest_in_full_coords.top);
|
||||
unsigned intersetion_bottom = MIN(src_in_full_coords.bottom, dest_in_full_coords.bottom);
|
||||
unsigned src_top_delta = intersetion_top - src_in_full_coords.top, src_bottom_delta = src_in_full_coords.bottom - intersetion_bottom;
|
||||
unsigned intersection_top = MAX(src_in_full_coords.top, dest_in_full_coords.top);
|
||||
unsigned intersection_bottom = MIN(src_in_full_coords.bottom, dest_in_full_coords.bottom);
|
||||
unsigned src_top_delta = intersection_top - src_in_full_coords.top, src_bottom_delta = src_in_full_coords.bottom - intersection_bottom;
|
||||
src->top += src_top_delta; src->bottom = src->bottom > src_bottom_delta ? src->bottom - src_bottom_delta : 0;
|
||||
unsigned dest_top_delta = intersetion_top - dest_in_full_coords.top, dest_bottom_delta = dest_in_full_coords.bottom - intersetion_bottom;
|
||||
unsigned dest_top_delta = intersection_top - dest_in_full_coords.top, dest_bottom_delta = dest_in_full_coords.bottom - intersection_bottom;
|
||||
dest->top = dest_top_delta; dest->bottom = cell_height > dest_bottom_delta ? cell_height - dest_bottom_delta : 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import os
|
||||
import tempfile
|
||||
import unittest
|
||||
from functools import partial
|
||||
from math import ceil
|
||||
|
||||
from kitty.constants import is_macos, read_kitty_resource
|
||||
from kitty.fast_data_types import (
|
||||
@@ -208,10 +209,26 @@ class Rendering(BaseTest):
|
||||
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))
|
||||
block_size = self.cell_width * self.cell_height * 4
|
||||
|
||||
def full_block(subscale):
|
||||
return b'\xff' * block_size
|
||||
|
||||
def empty_block(subscale):
|
||||
return b'\0' * block_size
|
||||
|
||||
def half_block(subscale, first=b'\xff', second=b'\0'):
|
||||
frac = 1 / (subscale + 1)
|
||||
height = ceil(frac * self.cell_height)
|
||||
rest = self.cell_height - height
|
||||
return (first * (rest * self.cell_width * 4)) + (second * height * self.cell_width * 4)
|
||||
|
||||
def upper_half_block(subscale):
|
||||
return half_block(subscale)
|
||||
|
||||
def lower_half_block(subscale):
|
||||
return half_block(subscale, b'\0', b'\xff')
|
||||
|
||||
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):
|
||||
@@ -223,8 +240,8 @@ class Rendering(BaseTest):
|
||||
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)
|
||||
for i, (expected, actual) in enumerate(zip((a(subscale), b(subscale), c(subscale), d(subscale)), blocks)):
|
||||
self.ae(self.sprites[actual], expected, f'The {i} block differs')
|
||||
|
||||
block_test(full_block, full_block, full_block, full_block, subscale=0)
|
||||
block_test(a=full_block)
|
||||
|
||||
Reference in New Issue
Block a user