예제 #1
0
    def draw_character(self, mode, **kwargs):
        side_ending = self.side_ending_class(
            self,
            self.side_flipped,
        )

        paper = Paper()

        pen = Pen()
        pen.set_mode(mode)
        pen.move_to((0, TOP - mode.width / 2))
        pen.turn_to(0)
        pen.line_forward(2.0)
        pen.last_segment().start_cap = stub_cap

        side_ending.draw(pen)
        paper.merge(pen.paper)

        bounds = paper.bounds()
        bounds.top = OVER
        bounds.bottom = MIDDLE
        bounds.left = 0
        paper.override_bounds(bounds)

        return paper
예제 #2
0
    def draw_character(self, mode, **kwargs):
        side_ending = self.side_ending_class(
            self,
            self.side_flipped,
        )

        paper = Paper()

        pen = Pen()
        pen.set_mode(mode)
        pen.move_to((0, TOP - mode.width / 2))
        pen.turn_to(0)
        pen.line_forward(2.0)
        pen.last_segment().start_cap = stub_cap

        side_ending.draw(pen)
        paper.merge(pen.paper)

        bounds = paper.bounds()
        bounds.top = OVER
        bounds.bottom = MIDDLE
        bounds.left = 0
        paper.override_bounds(bounds)

        return paper
예제 #3
0
def test_line_segment_bounds():
    # Fill mode segment.
    p = Pen()
    p.fill_mode()
    p.move_to((1, 0))
    p.line_to((2, 3))

    line = p.last_segment()
    assert_equal(
        line.bounds(),
        Bounds(1, 0, 2, 3)
    )

    # Stroke mode segment.
    p = Pen()
    p.stroke_mode(sqrt2)
    p.move_to((0, 0))
    p.line_to((5, 5))

    line = p.last_segment()
    assert_equal(
        line.bounds(),
        Bounds(-0.5, -0.5, 5.5, 5.5)
    )
예제 #4
0
def test_copy_custom_cap():
    # Regression test for a bug where doing pen.copy() in a cap function would
    # break outline drawing.
    p = Pen()
    p.stroke_mode(2.0)

    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(5)
    p.turn_left(90)
    p.line_forward(5)

    def copy_cap(pen, end):
        pen.copy()
        pen.line_to(end)

    p.last_segment().end_cap = copy_cap

    assert_path_data(p, 0, 'M0,-1 L0,1 L6,1 L6,-5 L4,-5 L4,-1 L0,-1 z')
예제 #5
0
def test_copy_custom_cap():
    # Regression test for a bug where doing pen.copy() in a cap function would
    # break outline drawing.
    p = Pen()
    p.stroke_mode(2.0)

    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(5)
    p.turn_left(90)
    p.line_forward(5)

    def copy_cap(pen, end):
        pen.copy()
        pen.line_to(end)

    p.last_segment().end_cap = copy_cap

    assert_path_data(
        p, 0,
        'M0,-1 L0,1 L6,1 L6,-5 L4,-5 L4,-1 L0,-1 z'
    )
예제 #6
0
def test_arc_segment_bounds():
    # Arc which occupies its entire circle.
    p = Pen()
    p.fill_mode()
    p.move_to((1, 0))
    p.turn_to(90)
    p.arc_left(359, 1)

    arc = p.last_segment()
    assert_equal(
        arc.bounds(),
        Bounds(-1, -1, 1, 1)
    )

    # Arc which pushes the boundary only with the endpoints.
    p = Pen()
    p.fill_mode()
    p.move_to((0, 0))
    p.turn_to(30)
    p.move_forward(1)
    p.turn_left(90)
    p.arc_left(30, center=(0, 0))

    arc = p.last_segment()
    assert_equal(
        arc.bounds(),
        Bounds(0.5, 0.5, sqrt3 / 2, sqrt3 / 2)
    )

    # Arc which pushes the boundary with the middle in one spot.
    p = Pen()
    p.fill_mode()
    p.move_to((0, 0))
    p.turn_to(-45)
    p.move_forward(1)
    p.turn_left(90)
    p.arc_left(90, center=(0, 0))

    arc = p.last_segment()
    assert_equal(
        arc.bounds(),
        Bounds(sqrt2 / 2, -sqrt2 / 2, 1, sqrt2 / 2)
    )

    # Arc which goes right.
    p = Pen()
    p.fill_mode()
    p.move_to((0, 0))
    p.turn_to(45)
    p.arc_right(90, 3)

    arc = p.last_segment()
    assert_equal(
        arc.bounds(),
        Bounds(0, 0, 3 * sqrt2, 3 - 1.5 * sqrt2)
    )

    # Arc which pushes the boundary with the middle in two spots.
    p = Pen()
    p.fill_mode()
    p.move_to((0, 0))
    p.turn_to(-45)
    p.move_forward(1)
    p.turn_left(90)
    p.arc_left(180, center=(0, 0))

    arc = p.last_segment()
    assert_equal(
        arc.bounds(),
        Bounds(-sqrt2 / 2, -sqrt2 / 2, 1, 1)
    )

    # Half circle, right side
    p = Pen()
    p.fill_mode()
    p.move_to((0, 0))
    p.turn_to(0)
    p.arc_right(180, 5)

    arc = p.last_segment()
    assert_equal(
        arc.bounds(),
        Bounds(0, -10, 5, 0)
    )

    # Thick circle,
    p = Pen()
    p.stroke_mode(1.0)
    p.move_to((0, 0))
    p.turn_to(0)
    p.move_forward(5)
    p.turn_left(90)
    p.arc_left(180, 5, start_slant=45)

    arc = p.last_segment()
    assert_equal(
        arc.bounds(),
        Bounds(-5.5, -0.5314980314970469, 5.5, 5.5)
    )