Esempio n. 1
0
    def test_should_draw_text(self, mock_obj):

        canvas = Canvas()

        canvas.font.family = FontFamily.SANS
        canvas.font.weight = FontWeight.BOLD
        canvas.font.style = FontStyle.ITALIC
        canvas.font.size_pts = 72
        canvas.font.render_mode = FontRenderMode.STROKE
        canvas.font.char_space_pts = 10.5
        canvas.font.word_space_pts = 5.75
        canvas.font.rise_pts = -5.0

        canvas.text('lorem ipsum\ndolor sit\namet', 10, 10)

        mock_obj.assert_called_once_with(28.34645669291339, 755.943307086614)
        mock_obj.return_value.setFont.assert_called_once_with(
            'FreeSansBoldItalic', 72.0, 86.39999999999999)
        mock_obj.return_value.setTextRenderMode.assert_called_once_with(1)
        mock_obj.return_value.setCharSpace.assert_called_once_with(10.5)
        mock_obj.return_value.setWordSpace.assert_called_once_with(5.75)
        mock_obj.return_value.setRise.assert_called_once_with(-5.0)
        mock_obj.return_value.textLine.assert_has_calls([
            mock.call('lorem ipsum'),
            mock.call('dolor sit'),
            mock.call('amet')
        ])
Esempio n. 2
0
 def test_should_return_cursor_position_after_drawing_line_of_text_with_char_space(
         self):
     canvas = Canvas()
     canvas.font.char_space_pts = 10
     self.assertAlmostEqual(66.36,
                            canvas.text('lorem ipsum', 10, 10),
                            places=2)
Esempio n. 3
0
    def test_should_return_cursor_position_of_a_line_of_text(self):

        text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod'

        canvas = Canvas()
        canvas.font.size_pts = 10
        canvas.font.char_space_pts = 10
        canvas.font.word_space_pts = 5
        self.assertAlmostEqual(379.66, canvas.text(text, 10, 10), places=2)
Esempio n. 4
0
 def test_should_return_cursor_position_of_longest_line_of_text_with_char_and_word_space(
         self):
     canvas = Canvas()
     canvas.font.size_pts = 10
     canvas.font.char_space_pts = 10
     canvas.font.word_space_pts = 5
     self.assertAlmostEqual(406.15,
                            canvas.text(self.TEXT, 10, 10),
                            places=2)
Esempio n. 5
0
    def test_should_align_single_line_of_text(self, mock_obj):

        canvas = Canvas()
        canvas.font.family = FontFamily.SERIF
        canvas.font.weight = FontWeight.NORMAL
        canvas.font.style = FontStyle.ITALIC
        canvas.font.size_pts = 10
        canvas.font.render_mode = FontRenderMode.FILL
        canvas.font.char_space_pts = 1.5
        canvas.font.word_space_pts = 2.5
        canvas.font.leading = 1.5

        x = canvas.text('lorem ipsum', 10, 10, 170, 40, HAlign.CENTER,
                        VAlign.MIDDLE)

        self.assertAlmostEqual(106.45, x, places=2)
        mock_obj.return_value.setTextOrigin.assert_called_with(
            236.8413385826772, mock.ANY)
Esempio n. 6
0
    def test_should_wrap_lines(self, mock_obj):

        canvas = Canvas()
        canvas.font.family = FontFamily.SERIF
        canvas.font.weight = FontWeight.NORMAL
        canvas.font.style = FontStyle.ITALIC
        canvas.font.size_pts = 10
        canvas.font.render_mode = FontRenderMode.FILL
        canvas.font.char_space_pts = 1.5
        canvas.font.word_space_pts = 2.5
        canvas.font.leading = 1.5

        x = canvas.text(self.TEXT, 10, 10, width=200, word_wrap=True)

        self.assertAlmostEqual(209.55, x, places=2)
        mock_obj.assert_called_once_with(28.34645669291339, 805.543307086614)

        mock_obj.return_value.setTextOrigin.assert_has_calls([
            mock.call(28.34645669291339, mock.ANY),
            mock.call(28.34645669291339, mock.ANY),
            mock.call(28.34645669291339, mock.ANY),
            mock.call(28.34645669291339, mock.ANY),
            mock.call(28.34645669291339, mock.ANY)
        ])

        mock_obj.return_value.textLine.assert_has_calls([
            mock.call(
                'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore'
            ),
            mock.call(
                'et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut'
            ),
            mock.call(
                'aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse'
            ),
            mock.call(
                'cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in'
            ),
            mock.call('culpa qui officia deserunt mollit anim id est laborum.')
        ])
Esempio n. 7
0
    def test_should_align_multi_line_text(self, mock_obj):

        canvas = Canvas()
        canvas.font.family = FontFamily.SERIF
        canvas.font.weight = FontWeight.NORMAL
        canvas.font.style = FontStyle.ITALIC
        canvas.font.size_pts = 10
        canvas.font.render_mode = FontRenderMode.FILL
        canvas.font.char_space_pts = 1.5
        canvas.font.word_space_pts = 2.5
        canvas.font.leading = 1.5

        x = canvas.text(self.TEXT, 10, 10, 170, 40, HAlign.CENTER,
                        VAlign.MIDDLE)
        self.assertAlmostEqual(173.96, x, places=2)

        mock_obj.return_value.setTextOrigin.assert_has_calls([
            mock.call(66.05633858267717, mock.ANY),
            mock.call(45.46133858267717, mock.ANY),
            mock.call(67.33633858267717, mock.ANY),
            mock.call(66.97133858267719, mock.ANY),
            mock.call(52.79633858267718, mock.ANY),
            mock.call(66.47133858267719, mock.ANY)
        ])
Esempio n. 8
0
    def test_should_wrap_lines_and_words_if_width_too_tight(self, mock_obj):

        canvas = Canvas()
        canvas.font.family = FontFamily.SERIF
        canvas.font.weight = FontWeight.NORMAL
        canvas.font.style = FontStyle.ITALIC
        canvas.font.size_pts = 10
        canvas.font.render_mode = FontRenderMode.FILL
        canvas.font.char_space_pts = 1.5
        canvas.font.word_space_pts = 2.5
        canvas.font.leading = 1.5

        x = canvas.text(self.TEXT, 10, 10, width=20, word_wrap=True)

        self.assertAlmostEqual(34.58, x, places=2)
        mock_obj.assert_called_once_with(28.34645669291339, 805.543307086614)

        mock_obj.return_value.textLine.assert_has_calls([
            mock.call('Lorem'),
            mock.call('ipsum'),
            mock.call('dolor sit'),
            mock.call('amet,'),
            mock.call('consectetur'),
            mock.call('adipisicing'),
            mock.call('elit, sed'),
            mock.call('do'),
            mock.call('eiusmod'),
            mock.call('tempor'),
            mock.call('incididunt'),
            mock.call('ut labore'),
            mock.call('et dolore'),
            mock.call('magna'),
            mock.call('aliqua. Ut'),
            mock.call('enim ad'),
            mock.call('minim'),
            mock.call('veniam,'),
            mock.call('quis'),
            mock.call('nostrud'),
            mock.call('exercitation'),
            mock.call('ullamco'),
            mock.call('laboris'),
            mock.call('nisi ut'),
            mock.call('aliquip ex'),
            mock.call('ea'),
            mock.call('commodo'),
            mock.call('consequat.'),
            mock.call('Duis aute'),
            mock.call('irure'),
            mock.call('dolor in'),
            mock.call('reprehenderit'),
            mock.call('in'),
            mock.call('voluptate'),
            mock.call('velit esse'),
            mock.call('cillum'),
            mock.call('dolore eu'),
            mock.call('fugiat'),
            mock.call('nulla'),
            mock.call('pariatur.'),
            mock.call('Excepteur'),
            mock.call('sint'),
            mock.call('occaecat'),
            mock.call('cupidatat'),
            mock.call('non'),
            mock.call('proident,'),
            mock.call('sunt in'),
            mock.call('culpa qui'),
            mock.call('officia'),
            mock.call('deserunt'),
            mock.call('mollit'),
            mock.call('anim id'),
            mock.call('est'),
            mock.call('laborum.')
        ])
Esempio n. 9
0
 def test_should_return_cursor_position_of_longest_line_of_text(self):
     canvas = Canvas()
     canvas.font.size_pts = 6
     self.assertAlmostEqual(76.24, canvas.text(self.TEXT, 10, 10), places=2)