def test_save_restore_clip_state(self): desired1 = array([[255, 255, 255, 255], [255, 0, 0, 255], [255, 0, 0, 255], [255, 255, 255, 255]]) desired2 = array([[255, 0, 0, 0], [255, 0, 0, 0], [255, 0, 0, 0], [255, 255, 255, 255]]) gc = GraphicsContextArray((4,4), pix_format="rgb24") gc.clear((1.0, 1.0, 1.0)) gc.set_fill_color((0.0, 0.0, 0.0)) gc.clip_to_rect(1, 1, 3, 3) gc.save_state() gc.clip_to_rect(1, 1, 2, 2) gc.rect(0, 0, 4, 4) gc.fill_path() actual1 = gc.bmp_array[:,:,0] self.assertRavelEqual(desired1, actual1) gc.restore_state() gc.rect(0, 0, 4, 4) gc.fill_path() actual2 = gc.bmp_array[:,:,0] self.assertRavelEqual(desired2, actual2)
def test_save_restore_clip_path(self): desired = array([[255, 255, 255, 255], [255, 0, 0, 255], [255, 0, 0, 255], [255, 255, 255, 255]]) # this is the clipping path we hope to see. clip_rect1 = (1, 1, 2, 2) # this will be a second path that will push/pop that should # never be seen. clip_rect2 = (1, 1, 1, 1) shp = tuple(transpose(desired.shape)) gc = GraphicsContextArray(shp, pix_format="rgb24") # clear background to white values (255, 255, 255) gc.clear((1.0, 1.0, 1.0)) gc.clip_to_rect(*clip_rect1) # push and then pop a path that shouldn't affect the drawing gc.save_state() gc.clip_to_rect(*clip_rect2) gc.restore_state() gc.rect(0, 0, 4, 4) # These settings allow the fastest path. gc.set_fill_color((0.0, 0.0, 0.0)) # black gc.fill_path() # test a single color channel actual = gc.bmp_array[:, :, 0] self.assertRavelEqual(desired, actual)
def test_save_restore_clip_state(self): desired1 = array([[255, 255, 255, 255], [255, 0, 0, 255], [255, 0, 0, 255], [255, 255, 255, 255]]) desired2 = array([[255, 0, 0, 0], [255, 0, 0, 0], [255, 0, 0, 0], [255, 255, 255, 255]]) gc = GraphicsContextArray((4, 4), pix_format="rgb24") gc.clear((1.0, 1.0, 1.0)) gc.set_fill_color((0.0, 0.0, 0.0)) gc.clip_to_rect(1, 1, 3, 3) gc.save_state() gc.clip_to_rect(1, 1, 2, 2) gc.rect(0, 0, 4, 4) gc.fill_path() actual1 = gc.bmp_array[:, :, 0] self.assertRavelEqual(desired1, actual1) gc.restore_state() gc.rect(0, 0, 4, 4) gc.fill_path() actual2 = gc.bmp_array[:, :, 0] self.assertRavelEqual(desired2, actual2)
def test_save_restore_clip_path(self): desired = array([[255, 255, 255, 255], [255, 0, 0, 255], [255, 0, 0, 255], [255, 255, 255, 255]]) # this is the clipping path we hope to see. clip_rect1 = (1, 1, 2, 2) # this will be a second path that will push/pop that should # never be seen. clip_rect2 = (1, 1, 1, 1) shp = tuple(transpose(desired.shape)) gc = GraphicsContextArray(shp, pix_format="rgb24") # clear background to white values (255, 255, 255) gc.clear((1.0, 1.0, 1.0)) gc.clip_to_rect(*clip_rect1) # push and then pop a path that shouldn't affect the drawing gc.save_state() gc.clip_to_rect(*clip_rect2) gc.restore_state() gc.rect(0, 0, 4, 4) # These settings allow the fastest path. gc. set_fill_color((0.0, 0.0, 0.0)) # black gc.fill_path() # test a single color channel actual = gc.bmp_array[:,:,0] self.assertRavelEqual(desired, actual)