#NEWLINE# def draw_text( string , text , font , size , width , leading = None ) : #NEWLINE# #INDENT# if bits : #NEWLINE# #INDENT# text . setFont ( font , size , leading = leading ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# text . setFont ( font , size ) #NEWLINE# #UNINDENT# font = pdfmetrics . getFont ( font ) #NEWLINE# if ( font . stringWidth ( string , size ) > width ) : #NEWLINE# #INDENT# bits = string . split ( ' ' ) #NEWLINE# while bits : #NEWLINE# #INDENT# did_something = False #NEWLINE# for i in range ( 1 , ( len ( bits ) + 1 ) ) : #NEWLINE# #INDENT# if ( font . stringWidth ( ' ' . join ( bits [ : i ] ) , size ) > width ) : #NEWLINE# #INDENT# if ( i == 1 ) : #NEWLINE# #INDENT# i = 2 #NEWLINE# #UNINDENT# text . textLine ( ' ' . join ( bits [ : ( i - 1 ) ] ) ) #NEWLINE# bits = bits [ ( i - 1 ) : ] #NEWLINE# did_something = True #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# if ( not did_something ) : #NEWLINE# #INDENT# text . textLine ( ' ' . join ( bits ) ) #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# text . textLine ( string )