Form the pages

def _form_pages(self, message_no, content, out, height, width):
        """ Form the pages """
        self.pages[message_no] = []
        page_height = height - 4  # 2-3 for menu, 1 for cursor
        outline = u''
        no_lines_page = 0
        for original, formatted in zip(content.split('\n'), out.split('\n')):
            no_lines_original = int(math.ceil(len(original) / float(width)))

            # Blank line
            if len(original) == 0:
                if no_lines_page + 1 <= page_height:
                    outline += u'\n'
                    no_lines_page += 1
                else:
                    self.pages[message_no].append(outline)
                    outline = u'\n'
                    no_lines_page = 1
                original = formatted = u'\n'
            # Too large line
            elif no_lines_original > page_height:
                if len(outline) > 0:
                    self.pages[message_no].append(outline)
                    outline = u''
                    no_lines_page = 0
                self.pages[message_no].append(formatted)
            # The line(s) can be added to the current page
            elif no_lines_page + no_lines_original <= page_height:
                if len(outline) > 0:
                    outline += u'\n'
                outline += formatted
                no_lines_page += no_lines_original
            # End the page and start a new
            else:
                self.pages[message_no].append(outline)
                outline = formatted
                no_lines_page = no_lines_original
        # Add the remainder
        if len(outline) > 0:
            self.pages[message_no].append(outline)
        if len(self.pages[message_no]) == 0:
            self.pages[message_no].append(u'')