Example #1
0
    def test_align_line(self):
        """
        Test aligned at the line text position calculation
        """
        p1 = 0, 0
        p2 = 20, 20

        extents = 10, 5

        x, y = get_text_point_at_line(extents, p1, p2, (ALIGN_LEFT, ALIGN_TOP),
                                      (2, 2, 2, 2))
        self.assertEqual(x, 5)
        self.assertEqual(y, -10)

        x, y = get_text_point_at_line(extents, p1, p2,
                                      (ALIGN_RIGHT, ALIGN_TOP), (2, 2, 2, 2))
        self.assertEqual(x, 5)
        self.assertEqual(y, -10)

        p2 = -20, 20
        x, y = get_text_point_at_line(extents, p1, p2, (ALIGN_LEFT, ALIGN_TOP),
                                      (2, 2, 2, 2))
        self.assertEqual(x, -15)
        self.assertEqual(y, -10)

        x, y = get_text_point_at_line(extents, p1, p2,
                                      (ALIGN_RIGHT, ALIGN_TOP), (2, 2, 2, 2))
        self.assertEqual(x, -15)
        self.assertEqual(y, -10)
Example #2
0
def test_align_line():
    """Test aligned at the line text position calculation."""
    p1 = 0, 0
    p2 = 20, 20

    extents = 10, 5

    x, y = get_text_point_at_line(
        extents, p1, p2, (ALIGN_LEFT, ALIGN_TOP), (2, 2, 2, 2)
    )
    assert x == 5
    assert y == (-10)

    x, y = get_text_point_at_line(
        extents, p1, p2, (ALIGN_RIGHT, ALIGN_TOP), (2, 2, 2, 2)
    )
    assert x == 5
    assert y == (-10)

    p2 = -20, 20
    x, y = get_text_point_at_line(
        extents, p1, p2, (ALIGN_LEFT, ALIGN_TOP), (2, 2, 2, 2)
    )
    assert x == (-15)
    assert y == (-10)

    x, y = get_text_point_at_line(
        extents, p1, p2, (ALIGN_RIGHT, ALIGN_TOP), (2, 2, 2, 2)
    )
    assert x == (-15)
    assert y == (-10)
Example #3
0
    def test_align_line(self):
        """
        Test aligned at the line text position calculation
        """
        p1 = 0, 0
        p2 = 20, 20

        extents = 10, 5

        x, y = get_text_point_at_line(extents, p1, p2,
                (ALIGN_LEFT, ALIGN_TOP), (2, 2, 2, 2))
        self.assertEqual(x, 5)
        self.assertEqual(y, -10)

        x, y = get_text_point_at_line(extents, p1, p2,
                (ALIGN_RIGHT, ALIGN_TOP), (2, 2, 2, 2))
        self.assertEqual(x, 5)
        self.assertEqual(y, -10)

        p2 = -20, 20
        x, y = get_text_point_at_line(extents, p1, p2,
                (ALIGN_LEFT, ALIGN_TOP), (2, 2, 2, 2))
        self.assertEqual(x, -15)
        self.assertEqual(y, -10)

        x, y = get_text_point_at_line(extents, p1, p2,
                (ALIGN_RIGHT, ALIGN_TOP), (2, 2, 2, 2))
        self.assertEqual(x, -15)
        self.assertEqual(y, -10)
Example #4
0
    def text_align(self, extents, align, padding, outside):
        handles = self._handles
        halign, valign = align

        if halign == ALIGN_LEFT:
            p1 = handles[0].pos
            p2 = handles[-1].pos
            x, y = get_text_point_at_line(extents, p1, p2, align, padding)

        elif halign == ALIGN_CENTER:
            h0, h1 = self._get_middle_segment()
            p1 = h0.pos
            p2 = h1.pos
            x, y = get_text_point_at_line2(extents, p1, p2, align, padding)
        elif halign == ALIGN_RIGHT:
            p1 = handles[-1].pos
            p2 = handles[-2].pos

            x, y = get_text_point_at_line(extents, p1, p2, align, padding)

        return x, y