class_docstr: Class that draws text on a Cairo context.
  
  This class supports multi-line text unlike the original Cairo text
  drawing methods.
class_docstr_tok: ["Class","that","draws","text","on","a","Cairo","context",".","This","class","supports","multi-line","text","unlike","the","original","Cairo","text","drawing","methods","."]
docstr: 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 L{_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.
docstr_tok: ["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","L","{","_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","."]
code: 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 L{_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)
  
file_path: python-igraph/src/igraph/drawing/cairo/text.py
imports: import re
  from warnings import warn
  from igraph.drawing.cairo.base import AbstractCairoDrawer
label_desc: Use image node_id 6 for calling the CairoTextDrawer obj's underlying member method code with example usage: obj._iterlines_wrapped(width) without return types