#NEWLINE# def find_rendered_diffs( self , font_size = 256 , stats = None , render_path = None ) : #NEWLINE# #INDENT# 'Find diffs of glyphs as rendered by harfbuzz.' #NEWLINE# self . build_names ( ) #NEWLINE# self . build_reverse_cmap ( ) #NEWLINE# hb_input_generators = [ hb_input . HbInputGenerator ( p , self . reverse_cmap ) for p in self . paths ] #NEWLINE# ( path_a , path_b ) = self . paths #NEWLINE# ordered_names = list ( self . names ) #NEWLINE# a_png = self . _make_tmp_path ( ) #NEWLINE# b_png = self . _make_tmp_path ( ) #NEWLINE# cmp_png = self . _make_tmp_path ( ) #NEWLINE# diffs_filename = self . _make_tmp_path ( ) #NEWLINE# for name in ordered_names : #NEWLINE# #INDENT# ( hb_args , hb_args_b ) = [ input_generator . input_from_name ( name ) for input_generator in hb_input_generators ] #NEWLINE# assert ( hb_args == hb_args_b ) #NEWLINE# if ( not hb_args ) : #NEWLINE# #INDENT# self . report . append ( ( 'not tested (unreachable?): %s' % name ) ) #NEWLINE# continue #NEWLINE# #UNINDENT# ( features , text ) = hb_args #NEWLINE# if ( text == unichr ( 0 ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# with open ( diffs_filename , 'a' ) as ofile : #NEWLINE# #INDENT# ofile . write ( ( '%s\n' % name ) ) #NEWLINE# #UNINDENT# subprocess . call ( [ 'hb-view' , ( '--font-size=%d' % font_size ) , ( '--output-file=%s' % a_png ) , ( '--features=%s' % ',' . join ( features ) ) , path_a , text ] ) #NEWLINE# subprocess . call ( [ 'hb-view' , ( '--font-size=%d' % font_size ) , ( '--output-file=%s' % b_png ) , ( '--features=%s' % ',' . join ( features ) ) , path_b , text ] ) #NEWLINE# img_info = subprocess . check_output ( [ 'identify' , a_png ] ) . split ( ) #NEWLINE# assert ( ( img_info [ 0 ] == a_png ) and ( img_info [ 1 ] == 'PNG' ) ) #NEWLINE# subprocess . call ( [ 'convert' , '-gravity' , 'center' , '-background' , 'black' , '-extent' , img_info [ 2 ] , b_png , b_png ] ) #NEWLINE# if render_path : #NEWLINE# #INDENT# output_png = os . path . join ( render_path , ( name + '.png' ) ) #NEWLINE# subprocess . call ( [ 'convert' , '(' , a_png , '-colorspace' , 'gray' , ')' , '(' , b_png , '-colorspace' , 'gray' , ')' , '(' , '-clone' , '0-1' , '-compose' , 'darken' , '-composite' , ')' , '-channel' , 'RGB' , '-combine' , output_png ] ) #NEWLINE# #UNINDENT# with open ( a_png , 'a' ) as ofile : #NEWLINE# #INDENT# subprocess . call ( [ 'compare' , '-metric' , 'AE' , a_png , b_png , cmp_png ] , stderr = ofile ) #NEWLINE# #UNINDENT# #UNINDENT# with open ( diffs_filename ) as ifile : #NEWLINE# #INDENT# lines = ifile . readlines ( ) #NEWLINE# #UNINDENT# diffs = [ ( lines [ i ] . strip ( ) , lines [ ( i + 1 ) ] . strip ( ) ) for i in range ( 0 , len ( lines ) , 2 ) ] #NEWLINE# os . remove ( a_png ) #NEWLINE# os . remove ( b_png ) #NEWLINE# os . remove ( cmp_png ) #NEWLINE# os . remove ( diffs_filename ) #NEWLINE# mismatched = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# img_size_diffs = [ ] #NEWLINE# for ( name , diff ) in diffs : #NEWLINE# #INDENT# if ( int ( diff ) != 0 ) : #NEWLINE# #INDENT# mismatched [ name ] = int ( diff ) #NEWLINE# #UNINDENT# #UNINDENT# report = self . report #NEWLINE# report . append ( ( '%d differences in rendered glyphs' % len ( mismatched ) ) ) #NEWLINE# mismatched = self . _sorted_by ( mismatched . items ( ) , self . _pass_val ) #NEWLINE# for ( _ , name , diff ) in mismatched [ : self . out_lines ] : #NEWLINE# #INDENT# report . append ( ( '%s: %s' % ( name , diff ) ) ) #NEWLINE# if ( stats is not None ) : #NEWLINE# #INDENT# stats . append ( ( diff , name ) ) #NEWLINE# #UNINDENT# #UNINDENT# report . append ( '' ) #NEWLINE# report . append ( ( '%d differences in glyph img size' % len ( img_size_diffs ) ) ) #NEWLINE# img_size_diffs . sort ( ) #NEWLINE# for name in img_size_diffs [ : self . out_lines ] : #NEWLINE# #INDENT# report . append ( name ) #NEWLINE# #UNINDENT# report . append ( '' )