def test_alias_width_two_outline_aa(self): """ When width>1, alias text is drawn using a couple of different paths through the underlying C++ code. This test the faster of the two which uses the agg::rasterizer_outline_aa C++ code. It is only used when 2<=width<=10, and cap is ROUND or BUTT, and join is MITER The C++ classes used in the underlying C++ code for this is agg::rasterizer_outline_aa and agg::renderer_outline_aa """ gc = GraphicsContextArray((3, 2), pix_format="rgb24") # clear background to white values (255, 255, 255) gc.clear((1.0, 1.0, 1.0)) # single horizontal line across bottom of buffer gc.move_to(0, 0) gc.line_to(3, 0) # Settings allow the 2nd fastest path. gc. set_stroke_color((0.0, 0.0, 0.0)) # black gc.set_antialias(False) gc.set_line_width(2) gc.set_line_cap(kiva.CAP_ROUND) gc.set_line_join(kiva.JOIN_MITER) gc.stroke_path() # test a single color channel. desired = array(((255, 255, 255), ( 0, 0, 0))) actual = gc.bmp_array[:,:,0] self.assertRavelEqual(actual, desired)
def test_alias_cap_square(self): """ Square caps should extend beyond the end of the line. by half the width of the line. """ gc = GraphicsContextArray((6,6), pix_format="rgb24") # clear background to white values (255, 255, 255) gc.clear((1.0, 1.0, 1.0)) # single horizontal line across bottom of buffer gc.move_to(2, 3) gc.line_to(4, 3) # Set up line gc. set_stroke_color((0.0, 0.0, 0.0)) # black gc.set_antialias(False) gc.set_line_width(2) gc.set_line_cap(kiva.CAP_SQUARE) gc.set_line_join(kiva.JOIN_MITER) gc.stroke_path() desired = array(((255, 255, 255, 255, 255, 255), (255, 255, 255, 255, 255, 255), (255, 0, 0, 0, 0, 255), (255, 0, 0, 0, 0, 255), (255, 255, 255, 255, 255, 255), (255, 255, 255, 255, 255, 255))) actual = gc.bmp_array[:,:,0] self.assertRavelEqual(desired, actual)
def test_alias_width_one(self): """ The fastest path through the stroke path code is for aliased path with width=1. It is reasonably safe here not to worry with testing all the CAP/JOIN combinations because they are all rendered the same for this case. It is handled by the agg::rasterizer_outline and the agg::renderer_primitives classes in C++. Energy for an aliased horizontal line of width=1 falls within a single line of pixels. With y=0 for this line, the engine should paint a single row of zeros along the bottom edge of the bmp array. """ gc = GraphicsContextArray((3, 2), pix_format="rgb24") # clear background to white values (255, 255, 255) gc.clear((1.0, 1.0, 1.0)) # single horizontal line across bottom of buffer gc.move_to(0, 0) gc.line_to(3, 0) # These settings allow the fastest path. gc. set_stroke_color((0.0, 0.0, 0.0)) # black gc.set_antialias(False) gc.set_line_width(1) gc.stroke_path() # test a single color channel. desired = array(((255,255,255), ( 0, 0, 0))) actual = gc.bmp_array[:,:,0] self.assertRavelEqual(actual, desired)
def test_antialias_width_slower_path(self): """ An anti-aliased horizontal line of width=1 has its energy centered between the bottom row of pixels and the next lower row of pixels (which is off the page). It dumps half its energy in each, so we end up with a single line of 127,127,127 pixel values in the last row of pixels. This particular set of flags is handled by the agg::rasterizer_scanline_aa path through the C++ code. """ gc = GraphicsContextArray((3, 2), pix_format="rgb24") # clear background to white values (255, 255, 255) gc.clear((1.0, 1.0, 1.0)) # single horizontal line across bottom of buffer gc.move_to(0, 0) gc.line_to(3, 0) # Set up stroke gc. set_stroke_color((0.0, 0.0, 0.0)) # black gc.set_antialias(True) gc.set_line_width(1) gc.set_line_cap(kiva.CAP_BUTT) gc.set_line_join(kiva.JOIN_BEVEL) gc.stroke_path() # test a single color channel. desired = array(((255, 255, 255), (127, 127, 127))) actual = gc.bmp_array[:,:,0] self.assertRavelEqual(desired, actual)
def test_alias_width_two_outline_aa(self): """ When width>1, alias text is drawn using a couple of different paths through the underlying C++ code. This test the faster of the two which uses the agg::rasterizer_outline_aa C++ code. It is only used when 2<=width<=10, and cap is ROUND or BUTT, and join is MITER The C++ classes used in the underlying C++ code for this is agg::rasterizer_outline_aa and agg::renderer_outline_aa """ gc = GraphicsContextArray((3, 2), pix_format="rgb24") # clear background to white values (255, 255, 255) gc.clear((1.0, 1.0, 1.0)) # single horizontal line across bottom of buffer gc.move_to(0, 0) gc.line_to(3, 0) # Settings allow the 2nd fastest path. gc.set_stroke_color((0.0, 0.0, 0.0)) # black gc.set_antialias(False) gc.set_line_width(2) gc.set_line_cap(kiva.CAP_ROUND) gc.set_line_join(kiva.JOIN_MITER) gc.stroke_path() # test a single color channel. desired = array(((255, 255, 255), (0, 0, 0))) actual = gc.bmp_array[:, :, 0] self.assertRavelEqual(actual, desired)
def test_alias_cap_round(self): """ Round caps should extend beyond the end of the line. We don't really test the shape here. To do this, a test of a wider line would be needed. fix me: This is rendering antialiased end points currently. """ gc = GraphicsContextArray((6,6), pix_format="rgb24") # clear background to white values (255, 255, 255) gc.clear((1.0, 1.0, 1.0)) # single horizontal line across bottom of buffer gc.move_to(2, 3) gc.line_to(4, 3) # Set up line gc. set_stroke_color((0.0, 0.0, 0.0)) # black gc.set_antialias(False) gc.set_line_width(2) gc.set_line_cap(kiva.CAP_ROUND) gc.set_line_join(kiva.JOIN_MITER) gc.stroke_path() desired = array(((255, 255, 255, 255, 255, 255), (255, 255, 255, 255, 255, 255), (255, 0, 0, 0, 0, 255), (255, 0, 0, 0, 0, 255), (255, 255, 255, 255, 255, 255), (255, 255, 255, 255, 255, 255))) actual = gc.bmp_array[:,:,0] self.assertRavelEqual(desired, actual)
def test_alias_width_two_scanline_aa(self): """ When width > 1, alias text is drawn using a couple of different paths through the underlying C++ code. This test the slower of the two which uses the agg::rasterizer_scanline_aa C++ code. We've set the line join to bevel to trigger this path. """ gc = GraphicsContextArray((3, 2), pix_format="rgb24") # clear background to white values (255, 255, 255) gc.clear((1.0, 1.0, 1.0)) # single horizontal line across bottom of buffer gc.move_to(0, 0) gc.line_to(3, 0) # Settings allow the 2nd fastest path. gc. set_stroke_color((0.0, 0.0, 0.0)) # black gc.set_antialias(False) gc.set_line_width(2) gc.set_line_cap(kiva.CAP_ROUND) gc.set_line_join(kiva.JOIN_BEVEL) gc.stroke_path() # test a single color channel. desired = array(((255, 255, 255), ( 0, 0, 0))) actual = gc.bmp_array[:,:,0] self.assertRavelEqual(actual, desired)
def test_antialias_width_slower_path(self): """ An anti-aliased horizontal line of width=1 has its energy centered between the bottom row of pixels and the next lower row of pixels (which is off the page). It dumps half its energy in each, so we end up with a single line of 127,127,127 pixel values in the last row of pixels. This particular set of flags is handled by the agg::rasterizer_scanline_aa path through the C++ code. """ gc = GraphicsContextArray((3, 2), pix_format="rgb24") # clear background to white values (255, 255, 255) gc.clear((1.0, 1.0, 1.0)) # single horizontal line across bottom of buffer gc.move_to(0, 0) gc.line_to(3, 0) # Set up stroke gc.set_stroke_color((0.0, 0.0, 0.0)) # black gc.set_antialias(True) gc.set_line_width(1) gc.set_line_cap(kiva.CAP_BUTT) gc.set_line_join(kiva.JOIN_BEVEL) gc.stroke_path() # test a single color channel. desired = array(((255, 255, 255), (127, 127, 127))) actual = gc.bmp_array[:, :, 0] self.assertRavelEqual(desired, actual)
def test_alias_width_one(self): """ The fastest path through the stroke path code is for aliased path with width=1. It is reasonably safe here not to worry with testing all the CAP/JOIN combinations because they are all rendered the same for this case. It is handled by the agg::rasterizer_outline and the agg::renderer_primitives classes in C++. Energy for an aliased horizontal line of width=1 falls within a single line of pixels. With y=0 for this line, the engine should paint a single row of zeros along the bottom edge of the bmp array. """ gc = GraphicsContextArray((3, 2), pix_format="rgb24") # clear background to white values (255, 255, 255) gc.clear((1.0, 1.0, 1.0)) # single horizontal line across bottom of buffer gc.move_to(0, 0) gc.line_to(3, 0) # These settings allow the fastest path. gc.set_stroke_color((0.0, 0.0, 0.0)) # black gc.set_antialias(False) gc.set_line_width(1) gc.stroke_path() # test a single color channel. desired = array(((255, 255, 255), (0, 0, 0))) actual = gc.bmp_array[:, :, 0] self.assertRavelEqual(actual, desired)
def test_alias_cap_square(self): """ Square caps should extend beyond the end of the line. by half the width of the line. """ gc = GraphicsContextArray((6, 6), pix_format="rgb24") # clear background to white values (255, 255, 255) gc.clear((1.0, 1.0, 1.0)) # single horizontal line across bottom of buffer gc.move_to(2, 3) gc.line_to(4, 3) # Set up line gc.set_stroke_color((0.0, 0.0, 0.0)) # black gc.set_antialias(False) gc.set_line_width(2) gc.set_line_cap(kiva.CAP_SQUARE) gc.set_line_join(kiva.JOIN_MITER) gc.stroke_path() desired = array( ((255, 255, 255, 255, 255, 255), (255, 255, 255, 255, 255, 255), (255, 0, 0, 0, 0, 255), (255, 0, 0, 0, 0, 255), (255, 255, 255, 255, 255, 255), (255, 255, 255, 255, 255, 255))) actual = gc.bmp_array[:, :, 0] self.assertRavelEqual(desired, actual)
def test_alias_cap_round(self): """ Round caps should extend beyond the end of the line. We don't really test the shape here. To do this, a test of a wider line would be needed. fix me: This is rendering antialiased end points currently. """ gc = GraphicsContextArray((6, 6), pix_format="rgb24") # clear background to white values (255, 255, 255) gc.clear((1.0, 1.0, 1.0)) # single horizontal line across bottom of buffer gc.move_to(2, 3) gc.line_to(4, 3) # Set up line gc.set_stroke_color((0.0, 0.0, 0.0)) # black gc.set_antialias(False) gc.set_line_width(2) gc.set_line_cap(kiva.CAP_ROUND) gc.set_line_join(kiva.JOIN_MITER) gc.stroke_path() desired = array( ((255, 255, 255, 255, 255, 255), (255, 255, 255, 255, 255, 255), (255, 0, 0, 0, 0, 255), (255, 0, 0, 0, 0, 255), (255, 255, 255, 255, 255, 255), (255, 255, 255, 255, 255, 255))) actual = gc.bmp_array[:, :, 0] self.assertRavelEqual(desired, actual)
def cap_equality_helper(self, antialias, width, line_cap, line_join, size=(6, 6)): gc = GraphicsContextArray(size, pix_format="rgb24") # clear background to white values (255, 255, 255) gc.clear((1.0, 1.0, 1.0)) # single horizontal line across bottom of buffer gc.move_to(2, 3) gc.line_to(4, 3) # Settings allow the faster outline path through C++ code gc.set_stroke_color((0.0, 0.0, 0.0)) # black gc.set_antialias(antialias) gc.set_line_width(width) gc.set_line_cap(line_cap) gc.set_line_join(line_join) gc.stroke_path() return gc
def test_alias_width_two_scanline_aa(self): """ When width > 1, alias text is drawn using a couple of different paths through the underlying C++ code. This test the slower of the two which uses the agg::rasterizer_scanline_aa C++ code. We've set the line join to bevel to trigger this path. """ gc = GraphicsContextArray((3, 2), pix_format="rgb24") # clear background to white values (255, 255, 255) gc.clear((1.0, 1.0, 1.0)) # single horizontal line across bottom of buffer gc.move_to(0, 0) gc.line_to(3, 0) # Settings allow the 2nd fastest path. gc.set_stroke_color((0.0, 0.0, 0.0)) # black gc.set_antialias(False) gc.set_line_width(2) gc.set_line_cap(kiva.CAP_ROUND) gc.set_line_join(kiva.JOIN_BEVEL) gc.stroke_path() # test a single color channel. desired = array(((255, 255, 255), (0, 0, 0))) actual = gc.bmp_array[:, :, 0] self.assertRavelEqual(actual, desired)
def test_curve_to(self): """ curve_to conv_curve happens early in the agg rendering pipeline, so it isn't neccessary to test every combination of antialias, line_cap, line_join, etc. If it works for one, we should be in good shape for the others (until the implementation is changed of course...) """ gc = GraphicsContextArray((10, 10), pix_format="rgb24") # clear background to white values (255, 255, 255) gc.clear((1.0, 1.0, 1.0)) # single horizontal line across bottom of buffer x0, y0 = 1.0, 5.0 x1, y1 = 4.0, 9.0 x2, y2 = 6.0, 1.0 x3, y3 = 9.0, 5.0 gc.move_to(x0, y0) gc.curve_to(x1, y1, x2, y2, x3, y3) # Set up stroke gc.set_stroke_color((0.0, 0.0, 0.0)) # black gc.set_antialias(True) gc.set_line_width(1) gc.set_line_cap(kiva.CAP_BUTT) gc.set_line_join(kiva.JOIN_MITER) gc.stroke_path() gc.set_stroke_color((0.0, 1.0, 1.0)) gc.move_to(x0, y0) gc.line_to(x1, y1) gc.move_to(x2, y2) gc.line_to(x3, y3) gc.stroke_path() # test a single color channel. # note: This is a "screen capture" from running this # test. It looks right, but hasn't been checked closely. desired = array([ [255, 255, 255, 230, 255, 255, 255, 255, 255, 255], [255, 255, 231, 25, 212, 255, 255, 255, 255, 255], [255, 252, 65, 128, 255, 255, 255, 255, 255, 255], [255, 103, 26, 143, 229, 255, 255, 255, 255, 255], [180, 2, 118, 96, 23, 189, 255, 255, 205, 255], [255, 206, 255, 255, 189, 23, 97, 119, 2, 180], [255, 255, 255, 255, 255, 229, 142, 25, 103, 255], [255, 255, 255, 255, 255, 255, 127, 66, 252, 255], [255, 255, 255, 255, 255, 212, 26, 231, 255, 255], [255, 255, 255, 255, 255, 255, 231, 255, 255, 255], ]) actual = gc.bmp_array[:, :, 0] self.assertRavelEqual(desired, actual)
def test_curve_to(self): """ curve_to conv_curve happens early in the agg rendering pipeline, so it isn't neccessary to test every combination of antialias, line_cap, line_join, etc. If it works for one, we should be in good shape for the others (until the implementation is changed of course...) """ gc = GraphicsContextArray((10, 10), pix_format="rgb24") # clear background to white values (255, 255, 255) gc.clear((1.0, 1.0, 1.0)) # single horizontal line across bottom of buffer x0, y0 = 1.0, 5.0 x1, y1 = 4.0, 9.0 x2, y2 = 6.0, 1.0 x3, y3 = 9.0, 5.0 gc.move_to(x0, y0) gc.curve_to(x1, y1, x2, y2, x3, y3); # Set up stroke gc. set_stroke_color((0.0, 0.0, 0.0)) # black gc.set_antialias(True) gc.set_line_width(1) gc.set_line_cap(kiva.CAP_BUTT) gc.set_line_join(kiva.JOIN_MITER) gc.stroke_path() gc. set_stroke_color((0.0, 1.0, 1.0)) gc.move_to(x0, y0) gc.line_to(x1, y1) gc.move_to(x2, y2) gc.line_to(x3, y3) gc.stroke_path() # test a single color channel. # note: This is a "screen capture" from running this # test. It looks right, but hasn't been check closely. desired = array([[255, 255, 255, 230, 255, 255, 255, 255, 255, 255], [255, 255, 231, 25, 212, 255, 255, 255, 255, 255], [255, 252, 65, 128, 255, 255, 255, 255, 255, 255], [255, 103, 26, 143, 229, 255, 255, 255, 255, 255], [179, 2, 115, 96, 23, 189, 255, 255, 204, 255], [255, 205, 255, 255, 189, 23, 97, 116, 2, 179], [255, 255, 255, 255, 255, 229, 142, 25, 103, 255], [255, 255, 255, 255, 255, 255, 127, 66, 252, 255], [255, 255, 255, 255, 255, 212, 26, 231, 255, 255], [255, 255, 255, 255, 255, 255, 231, 255, 255, 255]]) actual = gc.bmp_array[:,:,0] self.assertRavelEqual(desired, actual)
def cap_equality_helper(self, antialias, width, line_cap, line_join, size=(6,6)): gc = GraphicsContextArray(size, pix_format="rgb24") # clear background to white values (255, 255, 255) gc.clear((1.0, 1.0, 1.0)) # single horizontal line across bottom of buffer gc.move_to(2, 3) gc.line_to(4, 3) # Settings allow the faster outline path through C++ code gc. set_stroke_color((0.0, 0.0, 0.0)) # black gc.set_antialias(antialias) gc.set_line_width(width) gc.set_line_cap(line_cap) gc.set_line_join(line_join) gc.stroke_path() return gc