<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _do_layout(self, data):
 """ Lays the text out into separate lines and calculates their total height. """

        c = data['output']
        word_space = c.text_width(
            ' ',
            font_name=self.font_name,
            font_size=self.font_size)

        # Arrange the text as words on lines
        self._layout = [[]]
        x = self.font_size if self.paragraph_indent else 0
        for word in self.text.split():
            ww = c.text_width(
                word,
                font_name=self.font_name,
                font_size=self.font_size)
            if x + ww > self.width:
                # Newline
                x = 0
                self._layout.append([])
            self._layout[-1].append(word)
            x += ww + word_space

        # Work out the height we need
        num_lines = len(self._layout)
        self.height = (
            num_lines * self.font_size +
            (num_lines-1)*(self.font_size * (self.leading - 1.0))
            )