(self, width)
Iterates over the label line by line and returns a tuple containing
        the folloing for each line: the line itself, the width of the line and
        the X-bearing of the line.

        The difference between this method and `_iterlines()` is that this
        method is allowed to re-wrap the line if necessary.

        @param width: The width of the box in which the text will be fitted.
            Lines will be wrapped if they are wider than this width.
Iterates over the label line by line and returns a tuple containing
        the folloing for each line: the line itself, the width of the line and
        the X-bearing of the line.
Iterates over the label line by line and returns a tuple containing the folloing for each line : the line itself the width of the line and the X - bearing of the line .
def _iterlines_wrapped(self, width):
        """Iterates over the label line by line and returns a tuple containing
        the folloing for each line: the line itself, the width of the line and
        the X-bearing of the line.

        The difference between this method and `_iterlines()` is that this
        method is allowed to re-wrap the line if necessary.

        @param width: The width of the box in which the text will be fitted.
            Lines will be wrapped if they are wider than this width.
        """
        ctx = self.context
        for line in self._text.split("\n"):
            xb, _, line_width, _, _, _ = ctx.text_extents(line)
            if line_width <= width:
                yield (line, line_width, xb)
                continue

            # We have to wrap the line
            current_line, current_width, last_sep_width = [], 0, 0
            for match in re.finditer(r"(\S+)(\s+)?", line):
                word, sep = match.groups()
                word_width = ctx.text_extents(word)[4]
                if sep:
                    sep_width = ctx.text_extents(sep)[4]
                else:
                    sep_width = 0
                current_width += word_width
                if current_width >= width and current_line:
                    yield ("".join(current_line), current_width - word_width, 0)
                    # Starting a new line
                    current_line, current_width = [word], word_width
                    if sep is not None:
                        current_line.append(sep)
                else:
                    current_width += last_sep_width
                    current_line.append(word)
                    if sep is not None:
                        current_line.append(sep)
                last_sep_width = sep_width
            if current_line:
                yield ("".join(current_line), current_width, 0)
def _iterlines_wrapped ( self , width ) : ctx = self . context for line in self . _text . split ( "\n" ) : xb , _ , line_width , _ , _ , _ = ctx . text_extents ( line ) if line_width <= width : yield ( line , line_width , xb ) continue # We have to wrap the line current_line , current_width , last_sep_width = [ ] , 0 , 0 for match in re . finditer ( r"(\S+)(\s+)?" , line ) : word , sep = match . groups ( ) word_width = ctx . text_extents ( word ) [ 4 ] if sep : sep_width = ctx . text_extents ( sep ) [ 4 ] else : sep_width = 0 current_width += word_width if current_width >= width and current_line : yield ( "" . join ( current_line ) , current_width - word_width , 0 ) # Starting a new line current_line , current_width = [ word ] , word_width if sep is not None : current_line . append ( sep ) else : current_width += last_sep_width current_line . append ( word ) if sep is not None : current_line . append ( sep ) last_sep_width = sep_width if current_line : yield ( "" . join ( current_line ) , current_width , 0 )