Exemple #1
0
    def test_apply_dash(self):
        drawable = Drawable()
        drawable.style().set_type('dashed')
        self.__backend.create_canvas()
        self.__backend.apply_dash(drawable)
        dash = self.__backend.ctx().get_dash()
        assert len(dash) == 2
        assert len(dash[0]) == 2
        assert dash[0][0] != 0
        assert dash[0][0] == 4 * dash[0][1]
        assert dash[1] == 0 or dash[1] == 0.5

        drawable.style().set_type('dotted')
        self.__backend.create_canvas()
        self.__backend.apply_dash(drawable)
        dash = self.__backend.ctx().get_dash()
        assert len(dash) == 2
        assert len(dash[0]) == 2
        assert dash[0][0] != 0
        assert dash[0][0] == dash[0][1]
        assert dash[1] == 0 or dash[1] == 0.5

        drawable.style().set_type('dash-dotted')
        self.__backend.create_canvas()
        self.__backend.apply_dash(drawable)
        dash = self.__backend.ctx().get_dash()
        assert len(dash) == 2
        assert len(dash[0]) == 4
        assert dash[0][0] != 0
        assert dash[0][0] == 4 * dash[0][1]
        assert dash[0][0] == 4 * dash[0][2]
        assert dash[0][0] == 4 * dash[0][3]
        assert dash[1] == 0 or dash[1] == 0.5

        drawable.style().set_type('solid')
        self.__backend.create_canvas()
        self.__backend.apply_dash(drawable)
        dash = self.__backend.ctx().get_dash()
        assert len(dash) == 2
        assert len(dash[0]) == 0
Exemple #2
0
    def test_apply_line(self):
        drawable = Drawable()
        self.__backend.create_canvas()
        drawable.style().set_width(4.5)  
        drawable.style().add_color((0.1, 0.2, 0.3)) 
        self.__backend.apply_line(drawable)
        assert self.__backend.ctx().get_line_cap() == cairo.LINE_CAP_BUTT 
        assert self.__backend.ctx().get_line_join() == cairo.LINE_JOIN_ROUND 
        assert math.fabs(self.__backend.ctx().get_line_width() - drawable.style().width() * self.__backend.scale()) < 1.1
        assert type(self.__backend.ctx().get_source()) == cairo.SolidPattern
        assert self.__backend.ctx().get_source().get_rgba() == (0.1, 0.2, 0.3, 1.0)
        
        drawable = Drawable()
        drawable.style().add_color((0.1, 0.2, 0.3, 0.4)) 
        self.__backend.apply_line(drawable)
        assert type(self.__backend.ctx().get_source()) == cairo.SolidPattern
        assert self.__backend.ctx().get_source().get_rgba() == (0.1, 0.2, 0.3, 0.4)

        dash = self.__backend.ctx().get_dash()
        assert len(dash) == 2
        assert len(dash[0]) == 0
Exemple #3
0
    def test_apply_dash(self):
        drawable = Drawable()
        drawable.style().set_type('dashed')  
        self.__backend.create_canvas()
        self.__backend.apply_dash(drawable)
        dash = self.__backend.ctx().get_dash()
        assert len(dash) == 2
        assert len(dash[0]) == 2
        assert dash[0][0] != 0
        assert dash[0][0] == 4 * dash[0][1]
        assert dash[1] == 0 or dash[1] == 0.5
        
        drawable.style().set_type('dotted')  
        self.__backend.create_canvas()
        self.__backend.apply_dash(drawable)
        dash = self.__backend.ctx().get_dash()
        assert len(dash) == 2
        assert len(dash[0]) == 2
        assert dash[0][0] != 0
        assert dash[0][0] == dash[0][1]
        assert dash[1] == 0 or dash[1] == 0.5

        drawable.style().set_type('dash-dotted')  
        self.__backend.create_canvas()
        self.__backend.apply_dash(drawable)
        dash = self.__backend.ctx().get_dash()
        assert len(dash) == 2
        assert len(dash[0]) == 4
        assert dash[0][0] != 0
        assert dash[0][0] == 4 * dash[0][1]
        assert dash[0][0] == 4 * dash[0][2]
        assert dash[0][0] == 4 * dash[0][3]
        assert dash[1] == 0 or dash[1] == 0.5

        drawable.style().set_type('solid')  
        self.__backend.create_canvas()
        self.__backend.apply_dash(drawable)
        dash = self.__backend.ctx().get_dash()
        assert len(dash) == 2
        assert len(dash[0]) == 0
Exemple #4
0
 def test_init(self):
     drawable = Drawable()
     assert type(drawable.style()) == Style
Exemple #5
0
 def test_style(self):
     drawable = Drawable()
     style = Style(['abc', 'def', 'geh'], 'line', ['dotted', 'shadow'])
     drawable.set_style(style)
     assert drawable.style().options() == style.options()
Exemple #6
0
 def test_init(self):
     drawable = Drawable()
     assert type(drawable.style()) == Style
Exemple #7
0
 def test_max(self):
     drawable = Drawable()
     assert_raises(NotImplementedError, drawable.max)
Exemple #8
0
 def test_style(self):
     drawable = Drawable()
     style = Style(['abc', 'def', 'geh'], 'line', ['dotted', 'shadow'])
     drawable.set_style(style)
     assert drawable.style().options() == style.options()
Exemple #9
0
    def test_apply_line(self):
        drawable = Drawable()
        self.__backend.create_canvas()
        drawable.style().set_width(4.5)
        drawable.style().add_color((0.1, 0.2, 0.3))
        self.__backend.apply_line(drawable)
        assert self.__backend.ctx().get_line_cap() == cairo.LINE_CAP_BUTT
        assert self.__backend.ctx().get_line_join() == cairo.LINE_JOIN_ROUND
        assert math.fabs(self.__backend.ctx().get_line_width() -
                         drawable.style().width() *
                         self.__backend.scale()) < 1.1
        assert type(self.__backend.ctx().get_source()) == cairo.SolidPattern
        assert self.__backend.ctx().get_source().get_rgba() == (0.1, 0.2, 0.3,
                                                                1.0)

        drawable = Drawable()
        drawable.style().add_color((0.1, 0.2, 0.3, 0.4))
        self.__backend.apply_line(drawable)
        assert type(self.__backend.ctx().get_source()) == cairo.SolidPattern
        assert self.__backend.ctx().get_source().get_rgba() == (0.1, 0.2, 0.3,
                                                                0.4)

        dash = self.__backend.ctx().get_dash()
        assert len(dash) == 2
        assert len(dash[0]) == 0