Exemplo n.º 1
0
    def text_align(self, extents, align, padding, outside):
        h1, h2 = self._handles
        w, _ = self.style.min_size
        h = h2.pos.y - h1.pos.y
        x, y = get_text_point(extents, w, h, align, padding, outside)

        return x, y
Exemplo n.º 2
0
    def text_align(self, extents, align, padding, outside):
        h1, h2 = self._handles
        w, _ = self.style.min_size
        h = h2.pos.y - h1.pos.y
        x, y = get_text_point(extents, w, h, align, padding, outside)

        return x, y
Exemplo n.º 3
0
    def test_align_box(self):
        """
        Test aligned text position calculation
        """
        extents = 80, 12
        padding = (1, 2, 3, 4)
        data = {
            (ALIGN_LEFT, ALIGN_TOP, False): (4, 1),
            (ALIGN_LEFT, ALIGN_MIDDLE, False): (4, 14),
            (ALIGN_LEFT, ALIGN_BOTTOM, False): (4, 25),
            (ALIGN_CENTER, ALIGN_TOP, False): (42, 1),
            (ALIGN_CENTER, ALIGN_MIDDLE, False): (42, 14),
            (ALIGN_CENTER, ALIGN_BOTTOM, False): (42, 25),
            (ALIGN_RIGHT, ALIGN_TOP, False): (78, 1),
            (ALIGN_RIGHT, ALIGN_MIDDLE, False): (78, 14),
            (ALIGN_RIGHT, ALIGN_BOTTOM, False): (78, 25),
            (ALIGN_LEFT, ALIGN_TOP, True): (-84, -13),
            (ALIGN_LEFT, ALIGN_MIDDLE, True): (-84, 14),
            (ALIGN_LEFT, ALIGN_BOTTOM, True): (-84, 43),
            (ALIGN_CENTER, ALIGN_TOP, True): (40, -13),
            (ALIGN_CENTER, ALIGN_MIDDLE, True): (40, 14),
            (ALIGN_CENTER, ALIGN_BOTTOM, True): (40, 43),
            (ALIGN_RIGHT, ALIGN_TOP, True): (162, -13),
            (ALIGN_RIGHT, ALIGN_MIDDLE, True): (162, 14),
            (ALIGN_RIGHT, ALIGN_BOTTOM, True): (162, 43),
        }

        for halign in range(-1, 2):
            for valign in range(-1, 2):
                for outside in (True, False):
                    align = (halign, valign)
                    point_expected = data[(halign, valign, outside)]
                    point = get_text_point(extents, 160, 40, align, padding,
                                           outside)

                    self.assertEqual(
                        point[0],
                        point_expected[0],
                        "%s, %s -> %s" % (align, outside, point[0]),
                    )
                    self.assertEqual(
                        point[1],
                        point_expected[1],
                        "%s, %s -> %s" % (align, outside, point[1]),
                    )
Exemplo n.º 4
0
    def test_align_box(self):
        """
        Test aligned text position calculation
        """
        extents = 80, 12
        padding = (1, 2, 3, 4)
        data = {
            (ALIGN_LEFT, ALIGN_TOP, False): (4, 1),
            (ALIGN_LEFT, ALIGN_MIDDLE, False): (4, 14),
            (ALIGN_LEFT, ALIGN_BOTTOM, False): (4, 25),
            (ALIGN_CENTER, ALIGN_TOP, False): (42, 1),
            (ALIGN_CENTER, ALIGN_MIDDLE, False): (42, 14),
            (ALIGN_CENTER, ALIGN_BOTTOM, False): (42, 25),
            (ALIGN_RIGHT, ALIGN_TOP, False): (78, 1),
            (ALIGN_RIGHT, ALIGN_MIDDLE, False): (78, 14),
            (ALIGN_RIGHT, ALIGN_BOTTOM, False): (78, 25),
            (ALIGN_LEFT, ALIGN_TOP, True): (-84, -13),
            (ALIGN_LEFT, ALIGN_MIDDLE, True): (-84, 14),
            (ALIGN_LEFT, ALIGN_BOTTOM, True): (-84, 43),
            (ALIGN_CENTER, ALIGN_TOP, True): (40, -13),
            (ALIGN_CENTER, ALIGN_MIDDLE, True): (40, 14),
            (ALIGN_CENTER, ALIGN_BOTTOM, True): (40, 43),
            (ALIGN_RIGHT, ALIGN_TOP, True): (162, -13),
            (ALIGN_RIGHT, ALIGN_MIDDLE, True): (162, 14),
            (ALIGN_RIGHT, ALIGN_BOTTOM, True): (162, 43),
        }

        for halign in range(-1, 2):
            for valign in range(-1, 2):
                for outside in (True, False):
                    align = (halign, valign)
                    point_expected = data[(halign, valign, outside)]
                    point = get_text_point(extents, 160, 40, align, padding, outside)

                    self.assertEqual(
                        point[0],
                        point_expected[0],
                        "%s, %s -> %s" % (align, outside, point[0]),
                    )
                    self.assertEqual(
                        point[1],
                        point_expected[1],
                        "%s, %s -> %s" % (align, outside, point[1]),
                    )
Exemplo n.º 5
0
    def text_align(self, extents, align, padding, outside):
        x, y = get_text_point(extents, self.width, self.height, align, padding,
                              outside)

        return x, y
Exemplo n.º 6
0
    def text_align(self, extents, align, padding, outside):
        x, y = get_text_point(extents, self.width, self.height,
                align, padding, outside)

        return x, y