parameters: (drawer, text, font, containerWidth)
return_statement: return lines
docstring: Based on http://mail.python.org/pipermail/image-sig/2004-December/003064.html
docstring_summary: Based on http://mail.python.org/pipermail/image-sig/2004-December/003064.html
docstring_tokens: Based on http : // mail . python . org / pipermail / image - sig / 2004 - December / 003064 . html
function: def intelliDraw(drawer, text, font, containerWidth):
      """Based on http://mail.python.org/pipermail/image-sig/2004-December/003064.html"""
      #Args:
      #  drawer: Instance of "ImageDraw.Draw()"
      #  text: string of long text to be wrapped
      #  font: instance of ImageFont (I use .truetype)
      #  containerWidth: number of pixels text lines have to fit into.
  
      #write("containerWidth: %s" % containerWidth)
      words = text.split()
      lines = [] # prepare a return argument
      lines.append(words)
      finished = False
      line = 0
      while not finished:
          thistext = lines[line]
          newline = []
          innerFinished = False
          while not innerFinished:
              #write( 'thistext: '+str(thistext))
              #write("textWidth: %s" % drawer.textsize(' '.join(thistext),font)[0])
  
              if drawer.textsize(' '.join(thistext),font.getFont())[0] > containerWidth:
                  # this is the heart of the algorithm: we pop words off the current
                  # sentence until the width is ok, then in the next outer loop
                  # we move on to the next sentence.
                  if str(thistext).find(' ') != -1:
                      newline.insert(0,thistext.pop(-1))
                  else:
                      # FIXME should truncate the string here
                      innerFinished = True
              else:
                  innerFinished = True
          if len(newline) > 0:
              lines.append(newline)
              line = line + 1
          else:
              finished = True
      tmp = []
      for i in lines:
          tmp.append( fix_rtl( ' '.join(i) ) )
      lines = tmp
      return lines
function_tokens: def intelliDraw ( drawer , text , font , containerWidth ) : #Args: #  drawer: Instance of "ImageDraw.Draw()" #  text: string of long text to be wrapped #  font: instance of ImageFont (I use .truetype) #  containerWidth: number of pixels text lines have to fit into. #write("containerWidth: %s" % containerWidth) words = text . split ( ) lines = [ ] # prepare a return argument lines . append ( words ) finished = False line = 0 while not finished : thistext = lines [ line ] newline = [ ] innerFinished = False while not innerFinished : #write( 'thistext: '+str(thistext)) #write("textWidth: %s" % drawer.textsize(' '.join(thistext),font)[0]) if drawer . textsize ( ' ' . join ( thistext ) , font . getFont ( ) ) [ 0 ] > containerWidth : # this is the heart of the algorithm: we pop words off the current # sentence until the width is ok, then in the next outer loop # we move on to the next sentence. if str ( thistext ) . find ( ' ' ) != - 1 : newline . insert ( 0 , thistext . pop ( - 1 ) ) else : # FIXME should truncate the string here innerFinished = True else : innerFinished = True if len ( newline ) > 0 : lines . append ( newline ) line = line + 1 else : finished = True tmp = [ ] for i in lines : tmp . append ( fix_rtl ( ' ' . join ( i ) ) ) lines = tmp return lines