Ensure group_count is never zero in any ImageRef

Now group_count means the number of refs pointing to the same image from
that ref onwards. This is needed because we can index the list of refs
at any point when drawing not just at the start of a group.

Fixes #6594
This commit is contained in:
Kovid Goyal
2023-09-02 12:48:44 +05:30
parent 0be1295023
commit 951951776a
2 changed files with 25 additions and 6 deletions

View File

@@ -516,13 +516,30 @@ class TestGraphics(BaseTest):
rect_eq(l2[0]['dest_rect'], left, top, -1 + (1 + s.columns) * dx, top - dy * 5 / ch)
rect_eq(l2[1]['src_rect'], 0, 0, 1, 1)
rect_eq(l2[1]['dest_rect'], -1, 1, -1 + dx, 1 - dy)
self.ae(l2[0]['group_count'], 1), self.ae(l2[1]['group_count'], 1)
self.ae(l2[0]['group_count'], 2)
self.ae(l2[1]['group_count'], 1)
self.ae(s.cursor.x, 0), self.ae(s.cursor.y, 1)
self.ae(put_image(s, 10, 20, cursor_movement=1)[1], 'OK')
self.ae(s.cursor.x, 0), self.ae(s.cursor.y, 1)
s.reset()
self.assertEqual(s.grman.disk_cache.total_size, 0)
def test_image_layer_grouping(self):
cw, ch = 10, 20
s, dx, dy, put_image, put_ref, layers, rect_eq = put_helpers(self, cw, ch)
def group_counts():
return tuple(x['group_count'] for x in layers(s))
self.ae(put_image(s, 10, 20, id=1)[1], 'OK')
self.ae(group_counts(), (1,))
put_ref(s, id=1, num_cols=2, num_lines=1, placement_id=2)
put_ref(s, id=1, num_cols=2, num_lines=1, placement_id=3, z=-2)
put_ref(s, id=1, num_cols=2, num_lines=1, placement_id=4, z=-2)
self.ae(group_counts(), (4, 3, 2, 1))
self.ae(put_image(s, 8, 16, id=2, z=-1)[1], 'OK')
self.ae(group_counts(), (2, 1, 1, 2, 1))
def test_unicode_placeholders(self):
# This test tests basic image placement using using unicode placeholders
cw, ch = 10, 20