#NEWLINE# def format( self , tokensource , outfile ) : #NEWLINE# #INDENT# '\n        Format ``tokensource``, an iterable of ``(tokentype, tokenstring)``\n        tuples and write it into ``outfile``.\n\n        This implementation calculates where it should draw each token on the\n        pixmap, then calculates the required pixmap size and draws the items.\n        ' #NEWLINE# self . _create_drawables ( tokensource ) #NEWLINE# self . _draw_line_numbers ( ) #NEWLINE# im = Image . new ( 'RGB' , self . _get_image_size ( self . maxcharno , self . maxlineno ) , self . background_color ) #NEWLINE# self . _paint_line_number_bg ( im ) #NEWLINE# draw = ImageDraw . Draw ( im ) #NEWLINE# if self . hl_lines : #NEWLINE# #INDENT# x = ( ( ( self . image_pad + self . line_number_width ) - self . line_number_pad ) + 1 ) #NEWLINE# recth = self . _get_line_height ( ) #NEWLINE# rectw = ( im . size [ 0 ] - x ) #NEWLINE# for linenumber in self . hl_lines : #NEWLINE# #INDENT# y = self . _get_line_y ( ( linenumber - 1 ) ) #NEWLINE# draw . rectangle ( [ ( x , y ) , ( ( x + rectw ) , ( y + recth ) ) ] , fill = self . hl_color ) #NEWLINE# #UNINDENT# #UNINDENT# for ( pos , value , font , kw ) in self . drawables : #NEWLINE# #INDENT# draw . text ( pos , value , font = font , ** kw ) #NEWLINE# #UNINDENT# im . save ( outfile , self . image_format . upper ( ) )