Esempio n. 1
0
    def clip_to_rect_helper(self, desired, scale, clip_rects):
        """ desired -- 2D array with a single channels expected byte pattern.
            scale -- used in scale_ctm() to change the ctm.
            clip_args -- passed in as *clip_args to clip_to_rect.
        """
        shp = tuple(transpose(desired.shape))
        gc = GraphicsContextArray(shp, pix_format="rgb24")
        gc.scale_ctm(scale, scale)

        # clear background to white values (255, 255, 255)
        gc.clear((1.0, 1.0, 1.0))

        if isinstance(clip_rects, tuple):
            gc.clip_to_rect(*clip_rects)
        else:
            for rect in clip_rects:
                gc.clip_to_rect(*rect)

        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)
Esempio n. 2
0
    def successive_clip_helper(self, desired, scale, clip_rect1, clip_rect2):
        """ desired -- 2D array with a single channels expected byte pattern.
            scale -- used in scale_ctm() to change the ctm.
            clip_rect1 -- 1st clipping path.
            clip_rect2 -- 2nd clipping path.
        """
        shp = tuple(transpose(desired.shape))
        gc = GraphicsContextArray(shp, pix_format="rgb24")
        gc.scale_ctm(scale, scale)

        # clear background to white values (255, 255, 255)
        gc.clear((1.0, 1.0, 1.0))

        gc.clip_to_rect(*clip_rect1)
        gc.clip_to_rect(*clip_rect2)

        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)
Esempio n. 3
0
    def test_reset_path(self):
        """ clip_to_rect() should clear the current path.

            This is to maintain compatibility with the version
            of kiva that sits on top of Apple's Quartz engine.
        """
        desired = array([
            [255, 255, 0, 0],
            [255, 255, 0, 0],
            [255, 255, 0, 0],
            [255, 255, 0, 0],
        ])

        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.rect(0, 0, 2, 4)

        gc.clip_to_rect(0, 0, 4, 4)
        gc.rect(2, 0, 2, 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)
Esempio n. 4
0
def dash(sz=(1000, 1000)):
    gc = GraphicsContextArray(sz)
    gc.set_fill_color((1.0, 0.0, 0.0, 0.1))
    gc.set_stroke_color((0.0, 1.0, 0.0, 0.6))

    width = 10
    gc.set_line_width(10)

    phase = width * 2.5
    pattern = width * numpy.array((5, 5))
    gc.set_line_dash(pattern, phase)
    gc.set_line_cap(constants.CAP_BUTT)
    t1 = perf_counter()
    gc.move_to(10, 10)
    gc.line_to(sz[0] - 10, sz[1] - 10)
    gc.line_to(10, sz[1] - 10)
    gc.close_path()
    gc.draw_path()
    t2 = perf_counter()
    with tempfile.NamedTemporaryFile(suffix=".bmp") as fid:
        gc.save(fid.name)
        image = Image.from_file(fid.name,
                                resist_width="weak",
                                resist_height="weak")
    tot_time = t2 - t1
    print("time:", tot_time)
    return image
Esempio n. 5
0
    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)
Esempio n. 6
0
    def clip_to_rect_helper(self, desired, scale, clip_rects):
        """ desired -- 2D array with a single channels expected byte pattern.
            scale -- used in scale_ctm() to change the ctm.
            clip_args -- passed in as *clip_args to clip_to_rect.
        """
        shp = tuple(transpose(desired.shape))
        gc = GraphicsContextArray(shp, pix_format="rgb24")
        gc.scale_ctm(scale, scale)

        # clear background to white values (255, 255, 255)
        gc.clear((1.0, 1.0, 1.0))

        if isinstance(clip_rects, tuple):
            gc.clip_to_rect(*clip_rects)
        else:
            for rect in clip_rects:
                gc.clip_to_rect(*rect)

        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)
Esempio n. 7
0
    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)
Esempio n. 9
0
def dash(sz=(1000,1000)):
    gc = GraphicsContextArray(sz)
    gc.set_fill_color((1.0,0.0,0.0,0.1))
    gc.set_stroke_color((0.0,1.0,0.0,0.6))

    width = 10
    gc.set_line_width(10)

    phase = width * 2.5;
    pattern = width * numpy.array((5,5))
    gc.set_line_dash(pattern,phase)
    gc.set_line_cap(constants.CAP_BUTT)
    t1 = time.clock()
    gc.move_to(10,10)
    gc.line_to(sz[0]-10,sz[1]-10)
    gc.line_to(10,sz[1]-10)
    gc.close_path()
    gc.draw_path()
    t2 = time.clock()
    gc.save("dash.bmp")
    tot_time = t2 - t1
    print 'time:', tot_time
def dash(sz=(1000, 1000)):
    gc = GraphicsContextArray(sz)
    gc.set_fill_color((1.0, 0.0, 0.0, 0.1))
    gc.set_stroke_color((0.0, 1.0, 0.0, 0.6))

    width = 10
    gc.set_line_width(10)

    phase = width * 2.5
    pattern = width * numpy.array((5, 5))
    gc.set_line_dash(pattern, phase)
    gc.set_line_cap(constants.CAP_BUTT)
    t1 = time.clock()
    gc.move_to(10, 10)
    gc.line_to(sz[0] - 10, sz[1] - 10)
    gc.line_to(10, sz[1] - 10)
    gc.close_path()
    gc.draw_path()
    t2 = time.clock()
    gc.save("dash.bmp")
    tot_time = t2 - t1
    print('time:', tot_time)
Esempio n. 11
0
from kiva.agg import AffineMatrix, GraphicsContextArray

gc = GraphicsContextArray((200,200))

font = Font(family=MODERN)
#print font.size
font.size=8
gc.set_font(font)


t1 = time.clock()

# consecutive printing of text.
with gc:
    gc.set_antialias(False)
    gc.set_fill_color((0,1,0))
    gc.translate_ctm(50,50)
    gc.rotate_ctm(3.1416/4)
    gc.show_text("hello")
    gc.translate_ctm(-50,-50)
    gc.set_text_matrix(AffineMatrix())
    gc.set_fill_color((0,1,1))
    gc.show_text("hello")

t2 = time.clock()
print('aliased:', t2 - t1)
gc.save("text_aliased.bmp")

gc = GraphicsContextArray((200,200))

font = Font(family=MODERN)