Exemple #1
0
    def test_align_line2_h(self):
        """
        Test aligned at the line text position calculation, horizontal mode
        """
        extents = 10, 5
        p1 = 2.0, 2.0

        # align top
        p2 = 22.0, 7.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                                       (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2))
        self.assertAlmostEqual(x, 7)
        self.assertAlmostEqual(y, -4.75)

        p2 = 22.0, -3.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                                       (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2))
        self.assertAlmostEqual(x, 7)
        self.assertAlmostEqual(y, -9.75)

        p2 = -18.0, 7.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                                       (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2))
        self.assertAlmostEqual(x, -13)
        self.assertAlmostEqual(y, -4.75)

        p2 = -18.0, -3.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                                       (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2))
        self.assertAlmostEqual(x, -13)
        self.assertAlmostEqual(y, -9.75)

        # align bottom
        p2 = 22.0, 7.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                                       (ALIGN_CENTER, ALIGN_BOTTOM),
                                       (3, 2, 3, 2))
        self.assertAlmostEqual(x, 7)
        self.assertAlmostEqual(y, 8.75)

        p2 = 22.0, -3.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                                       (ALIGN_CENTER, ALIGN_BOTTOM),
                                       (3, 2, 3, 2))
        self.assertAlmostEqual(x, 7)
        self.assertAlmostEqual(y, 3.75)

        p2 = -18.0, 7.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                                       (ALIGN_CENTER, ALIGN_BOTTOM),
                                       (3, 2, 3, 2))
        self.assertAlmostEqual(x, -13)
        self.assertAlmostEqual(y, 8.75)

        p2 = -18.0, -3.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                                       (ALIGN_CENTER, ALIGN_BOTTOM),
                                       (3, 2, 3, 2))
        self.assertAlmostEqual(x, -13)
        self.assertAlmostEqual(y, 3.75)
Exemple #2
0
    def test_align_line2_v(self):
        """
        Test aligned at the line text position calculation, vertical mode
        """
        extents = 10, 5
        p1 = 2.0, 2.0

        # top align
        p2 = 7.0, 22.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                                       (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2))
        self.assertAlmostEqual(x, 7.125)
        self.assertAlmostEqual(y, 9.5)

        p2 = 7.0, -18.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                                       (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2))
        self.assertAlmostEqual(x, -8.125)
        self.assertAlmostEqual(y, -10.5)

        p2 = -3.0, 22.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                                       (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2))
        self.assertAlmostEqual(x, -13.125)
        self.assertAlmostEqual(y, 9.5)

        p2 = -3.0, -18.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                                       (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2))
        self.assertAlmostEqual(x, 2.125)
        self.assertAlmostEqual(y, -10.5)

        # bottom align
        p2 = 7.0, 22.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                                       (ALIGN_CENTER, ALIGN_BOTTOM),
                                       (3, 2, 3, 2))
        self.assertAlmostEqual(x, -8.125)
        self.assertAlmostEqual(y, 9.5)

        p2 = 7.0, -18.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                                       (ALIGN_CENTER, ALIGN_BOTTOM),
                                       (3, 2, 3, 2))
        self.assertAlmostEqual(x, 7.125)
        self.assertAlmostEqual(y, -10.5)

        p2 = -3.0, 22.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                                       (ALIGN_CENTER, ALIGN_BOTTOM),
                                       (3, 2, 3, 2))
        self.assertAlmostEqual(x, 2.125)
        self.assertAlmostEqual(y, 9.5)

        p2 = -3.0, -18.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                                       (ALIGN_CENTER, ALIGN_BOTTOM),
                                       (3, 2, 3, 2))
        self.assertAlmostEqual(x, -13.125)
        self.assertAlmostEqual(y, -10.5)
Exemple #3
0
    def test_align_line2_o(self):
        """
        Test aligned at the line text position calculation, orthogonal
        lines
        """
        extents = 10, 5
        p1 = 2.0, 2.0

        # top align
        p2 = 22.0, 2.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2))
        self.assertAlmostEqual(x, 7)
        self.assertAlmostEqual(y, -6)

        p2 = -18.0, 2.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2))
        self.assertAlmostEqual(x, -13)
        self.assertAlmostEqual(y, -6)

        p2 = 2.0, 22.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2))
        self.assertAlmostEqual(x, -10.0)
        self.assertAlmostEqual(y, 9.5)

        p2 = 2.0, -18.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2))
        self.assertAlmostEqual(x, -10.0)
        self.assertAlmostEqual(y, -10.5)

        # bottom align
        p2 = 22.0, 2.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_BOTTOM), (3, 2, 3, 2))
        self.assertAlmostEqual(x, 7)
        self.assertAlmostEqual(y, 5)

        p2 = -18.0, 2.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_BOTTOM), (3, 2, 3, 2))
        self.assertAlmostEqual(x, -13.0)
        self.assertAlmostEqual(y, 5.0)

        p2 = 2.0, 22.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_BOTTOM), (3, 2, 3, 2))
        self.assertAlmostEqual(x, 4.0)
        self.assertAlmostEqual(y, 9.5)

        p2 = 2.0, -18.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_BOTTOM), (3, 2, 3, 2))
        self.assertAlmostEqual(x, 4.0)
        self.assertAlmostEqual(y, -10.5)
Exemple #4
0
    def test_align_line2_o(self):
        """
        Test aligned at the line text position calculation, orthogonal
        lines
        """
        extents = 10, 5
        p1 = 2.0, 2.0

        # top align
        p2 = 22.0, 2.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2))
        self.assertAlmostEqual(x, 7)
        self.assertAlmostEqual(y, -6)

        p2 = -18.0, 2.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2))
        self.assertAlmostEqual(x, -13)
        self.assertAlmostEqual(y, -6)

        p2 = 2.0, 22.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2))
        self.assertAlmostEqual(x, -10.0)
        self.assertAlmostEqual(y, 9.5)

        p2 = 2.0, -18.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2))
        self.assertAlmostEqual(x, -10.0)
        self.assertAlmostEqual(y, -10.5)

        # bottom align
        p2 = 22.0, 2.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_BOTTOM), (3, 2, 3, 2))
        self.assertAlmostEqual(x, 7)
        self.assertAlmostEqual(y, 5)

        p2 = -18.0, 2.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_BOTTOM), (3, 2, 3, 2))
        self.assertAlmostEqual(x, -13.0)
        self.assertAlmostEqual(y, 5.0)

        p2 = 2.0, 22.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_BOTTOM), (3, 2, 3, 2))
        self.assertAlmostEqual(x, 4.0)
        self.assertAlmostEqual(y, 9.5)

        p2 = 2.0, -18.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_BOTTOM), (3, 2, 3, 2))
        self.assertAlmostEqual(x, 4.0)
        self.assertAlmostEqual(y, -10.5)
Exemple #5
0
    def test_align_line2_h(self):
        """
        Test aligned at the line text position calculation, horizontal mode
        """
        extents = 10, 5
        p1 = 2.0, 2.0

        # align top
        p2 = 22.0, 7.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2))
        self.assertAlmostEqual(x, 7)
        self.assertAlmostEqual(y, -4.75)

        p2 = 22.0, -3.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2))
        self.assertAlmostEqual(x, 7)
        self.assertAlmostEqual(y, -9.75)

        p2 = -18.0, 7.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2))
        self.assertAlmostEqual(x, -13)
        self.assertAlmostEqual(y, -4.75)

        p2 = -18.0, -3.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2))
        self.assertAlmostEqual(x, -13)
        self.assertAlmostEqual(y, -9.75)

        # align bottom
        p2 = 22.0, 7.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_BOTTOM), (3, 2, 3, 2))
        self.assertAlmostEqual(x, 7)
        self.assertAlmostEqual(y, 8.75)

        p2 = 22.0, -3.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_BOTTOM), (3, 2, 3, 2))
        self.assertAlmostEqual(x, 7)
        self.assertAlmostEqual(y, 3.75)

        p2 = -18.0, 7.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_BOTTOM), (3, 2, 3, 2))
        self.assertAlmostEqual(x, -13)
        self.assertAlmostEqual(y, 8.75)

        p2 = -18.0, -3.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_BOTTOM), (3, 2, 3, 2))
        self.assertAlmostEqual(x, -13)
        self.assertAlmostEqual(y, 3.75)
Exemple #6
0
    def test_align_line2_v(self):
        """
        Test aligned at the line text position calculation, vertical mode
        """
        extents = 10, 5
        p1 = 2.0, 2.0

        # top align
        p2 = 7.0, 22.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2))
        self.assertAlmostEqual(x, 7.125)
        self.assertAlmostEqual(y, 9.5)

        p2 = 7.0, -18.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2))
        self.assertAlmostEqual(x, -8.125)
        self.assertAlmostEqual(y, -10.5)

        p2 = -3.0, 22.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2))
        self.assertAlmostEqual(x, -13.125)
        self.assertAlmostEqual(y, 9.5)

        p2 = -3.0, -18.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2))
        self.assertAlmostEqual(x, 2.125)
        self.assertAlmostEqual(y, -10.5)

        # bottom align
        p2 = 7.0, 22.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_BOTTOM), (3, 2, 3, 2))
        self.assertAlmostEqual(x, -8.125)
        self.assertAlmostEqual(y, 9.5)

        p2 = 7.0, -18.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_BOTTOM), (3, 2, 3, 2))
        self.assertAlmostEqual(x, 7.125)
        self.assertAlmostEqual(y, -10.5)

        p2 = -3.0, 22.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_BOTTOM), (3, 2, 3, 2))
        self.assertAlmostEqual(x, 2.125)
        self.assertAlmostEqual(y, 9.5)

        p2 = -3.0, -18.0
        x, y = get_text_point_at_line2(extents, p1, p2,
                (ALIGN_CENTER, ALIGN_BOTTOM), (3, 2, 3, 2))
        self.assertAlmostEqual(x, -13.125)
        self.assertAlmostEqual(y, -10.5)
Exemple #7
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
Exemple #8
0
def test_align_line2_o():
    """Test aligned at the line text position calculation, orthogonal lines."""
    extents = 10, 5
    p1 = 2.0, 2.0

    # top align
    p2 = 22.0, 2.0
    x, y = get_text_point_at_line2(
        extents, p1, p2, (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2)
    )
    assert x == pytest.approx(7)
    assert y == pytest.approx(-6)

    p2 = -18.0, 2.0
    x, y = get_text_point_at_line2(
        extents, p1, p2, (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2)
    )
    assert x == pytest.approx(-13)
    assert y == pytest.approx(-6)

    p2 = 2.0, 22.0
    x, y = get_text_point_at_line2(
        extents, p1, p2, (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2)
    )
    assert x == pytest.approx(-10.0)
    assert y == pytest.approx(9.5)

    p2 = 2.0, -18.0
    x, y = get_text_point_at_line2(
        extents, p1, p2, (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2)
    )
    assert x == pytest.approx(-10.0)
    assert y == pytest.approx(-10.5)

    # bottom align
    p2 = 22.0, 2.0
    x, y = get_text_point_at_line2(
        extents, p1, p2, (ALIGN_CENTER, ALIGN_BOTTOM), (3, 2, 3, 2)
    )
    assert x == pytest.approx(7)
    assert y == pytest.approx(5)

    p2 = -18.0, 2.0
    x, y = get_text_point_at_line2(
        extents, p1, p2, (ALIGN_CENTER, ALIGN_BOTTOM), (3, 2, 3, 2)
    )
    assert x == pytest.approx(-13.0)
    assert y == pytest.approx(5.0)

    p2 = 2.0, 22.0
    x, y = get_text_point_at_line2(
        extents, p1, p2, (ALIGN_CENTER, ALIGN_BOTTOM), (3, 2, 3, 2)
    )
    assert x == pytest.approx(4.0)
    assert y == pytest.approx(9.5)

    p2 = 2.0, -18.0
    x, y = get_text_point_at_line2(
        extents, p1, p2, (ALIGN_CENTER, ALIGN_BOTTOM), (3, 2, 3, 2)
    )
    assert x == pytest.approx(4.0)
    assert y == pytest.approx(-10.5)
Exemple #9
0
def test_align_line2_v():
    """Test aligned at the line text position calculation, vertical mode."""
    extents = 10, 5
    p1 = 2.0, 2.0

    # top align
    p2 = 7.0, 22.0
    x, y = get_text_point_at_line2(
        extents, p1, p2, (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2)
    )
    assert x == pytest.approx(7.125)
    assert y == pytest.approx(9.5)

    p2 = 7.0, -18.0
    x, y = get_text_point_at_line2(
        extents, p1, p2, (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2)
    )
    assert x == pytest.approx(-8.125)
    assert y == pytest.approx(-10.5)

    p2 = -3.0, 22.0
    x, y = get_text_point_at_line2(
        extents, p1, p2, (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2)
    )
    assert x == pytest.approx(-13.125)
    assert y == pytest.approx(9.5)

    p2 = -3.0, -18.0
    x, y = get_text_point_at_line2(
        extents, p1, p2, (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2)
    )
    assert x == pytest.approx(2.125)
    assert y == pytest.approx(-10.5)

    # bottom align
    p2 = 7.0, 22.0
    x, y = get_text_point_at_line2(
        extents, p1, p2, (ALIGN_CENTER, ALIGN_BOTTOM), (3, 2, 3, 2)
    )
    assert x == pytest.approx(-8.125)
    assert y == pytest.approx(9.5)

    p2 = 7.0, -18.0
    x, y = get_text_point_at_line2(
        extents, p1, p2, (ALIGN_CENTER, ALIGN_BOTTOM), (3, 2, 3, 2)
    )
    assert x == pytest.approx(7.125)
    assert y == pytest.approx(-10.5)

    p2 = -3.0, 22.0
    x, y = get_text_point_at_line2(
        extents, p1, p2, (ALIGN_CENTER, ALIGN_BOTTOM), (3, 2, 3, 2)
    )
    assert x == pytest.approx(2.125)
    assert y == pytest.approx(9.5)

    p2 = -3.0, -18.0
    x, y = get_text_point_at_line2(
        extents, p1, p2, (ALIGN_CENTER, ALIGN_BOTTOM), (3, 2, 3, 2)
    )
    assert x == pytest.approx(-13.125)
    assert y == pytest.approx(-10.5)
Exemple #10
0
def test_align_line2_h():
    """Test aligned at the line text position calculation, horizontal mode."""
    extents = 10, 5
    p1 = 2.0, 2.0

    # align top
    p2 = 22.0, 7.0
    x, y = get_text_point_at_line2(
        extents, p1, p2, (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2)
    )
    assert x == pytest.approx(7)
    assert y == pytest.approx(-4.75)

    p2 = 22.0, -3.0
    x, y = get_text_point_at_line2(
        extents, p1, p2, (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2)
    )
    assert x == pytest.approx(7)
    assert y == pytest.approx(-9.75)

    p2 = -18.0, 7.0
    x, y = get_text_point_at_line2(
        extents, p1, p2, (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2)
    )
    assert x == pytest.approx(-13)
    assert y == pytest.approx(-4.75)

    p2 = -18.0, -3.0
    x, y = get_text_point_at_line2(
        extents, p1, p2, (ALIGN_CENTER, ALIGN_TOP), (3, 2, 3, 2)
    )
    assert x == pytest.approx(-13)
    assert y == pytest.approx(-9.75)

    # align bottom
    p2 = 22.0, 7.0
    x, y = get_text_point_at_line2(
        extents, p1, p2, (ALIGN_CENTER, ALIGN_BOTTOM), (3, 2, 3, 2)
    )
    assert x == pytest.approx(7)
    assert y == pytest.approx(8.75)

    p2 = 22.0, -3.0
    x, y = get_text_point_at_line2(
        extents, p1, p2, (ALIGN_CENTER, ALIGN_BOTTOM), (3, 2, 3, 2)
    )
    assert x == pytest.approx(7)
    assert y == pytest.approx(3.75)

    p2 = -18.0, 7.0
    x, y = get_text_point_at_line2(
        extents, p1, p2, (ALIGN_CENTER, ALIGN_BOTTOM), (3, 2, 3, 2)
    )
    assert x == pytest.approx(-13)
    assert y == pytest.approx(8.75)

    p2 = -18.0, -3.0
    x, y = get_text_point_at_line2(
        extents, p1, p2, (ALIGN_CENTER, ALIGN_BOTTOM), (3, 2, 3, 2)
    )
    assert x == pytest.approx(-13)
    assert y == pytest.approx(3.75)