#NEWLINE# def _clean( self ) : #NEWLINE# #INDENT# 'Resolve changed layout' #NEWLINE# "\n        # Each 'line' in 'glyph_lines' is a list of Glyph objects.  Do\n        # line wrapping now.\n        glyph_lines = []\n        if self._layout_width is None:\n            for line in self.text.split('\n'):\n                glyph_lines.append((line, self.font.get_glyphs(self.text)))\n        else:\n            text = self.text + ' ' # Need the ' ' to always flush line.\n            while text and text != ' ':\n                line = self.font.get_glyphs_for_width(text, self._layout_width)\n                glyph_lines.append((text[:len(line)], line))\n                text = text[len(line):]\n                if text and text[0] == '\n':\n                    text = text[1:]\n\n        # Create interleaved array and figure out state changes.\n        line_height = self.font.ascent - self.font.descent + self.leading\n        y = 0\n        self._text_width = 0\n        self.strings = []\n        for text, glyphs in glyph_lines:\n            string = GlyphString(text, glyphs, 0, y)\n            self._text_width = max(self._text_width, string.width)\n            y -= line_height\n            self.strings.append(string)\n\n        self._text_height = -y\n        " #NEWLINE# text = ( self . _text + ' ' ) #NEWLINE# glyphs = self . font . get_glyphs ( text ) #NEWLINE# self . _glyph_string = GlyphString ( text , glyphs ) #NEWLINE# self . lines = [ ] #NEWLINE# i = 0 #NEWLINE# if ( self . _layout_width is None ) : #NEWLINE# #INDENT# self . _text_width = 0 #NEWLINE# while ( '\n' in text [ i : ] ) : #NEWLINE# #INDENT# end = text . index ( '\n' , i ) #NEWLINE# self . lines . append ( ( i , end ) ) #NEWLINE# self . _text_width = max ( self . _text_width , self . _glyph_string . get_subwidth ( i , end ) ) #NEWLINE# i = ( end + 1 ) #NEWLINE# #UNINDENT# end = len ( text ) #NEWLINE# if ( end != i ) : #NEWLINE# #INDENT# self . lines . append ( ( i , end ) ) #NEWLINE# self . _text_width = max ( self . _text_width , self . _glyph_string . get_subwidth ( i , end ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# bp = self . _glyph_string . get_break_index ( i , self . _layout_width ) #NEWLINE# while ( ( i < len ( text ) ) and ( bp > i ) ) : #NEWLINE# #INDENT# if ( text [ ( bp - 1 ) ] == '\n' ) : #NEWLINE# #INDENT# self . lines . append ( ( i , ( bp - 1 ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . lines . append ( ( i , bp ) ) #NEWLINE# #UNINDENT# i = bp #NEWLINE# bp = self . _glyph_string . get_break_index ( i , self . _layout_width ) #NEWLINE# #UNINDENT# if ( i < ( len ( text ) - 1 ) ) : #NEWLINE# #INDENT# self . lines . append ( ( i , len ( text ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# self . line_height = ( ( self . font . ascent - self . font . descent ) + self . leading ) #NEWLINE# self . _text_height = ( self . line_height * len ( self . lines ) ) #NEWLINE# self . _dirty = False