#NEWLINE# def parse( self , f ) : #NEWLINE# #INDENT# 'Parse a .fnt file stream.' #NEWLINE# line = f . readline ( ) #NEWLINE# line = line . strip ( ) #NEWLINE# if line . startswith ( 'info ' ) : #NEWLINE# #INDENT# found = self . bold_re . search ( line ) #NEWLINE# if found : #NEWLINE# #INDENT# self . bold = int ( found . group ( 1 ) ) #NEWLINE# #UNINDENT# found = self . italic_re . search ( line ) #NEWLINE# if found : #NEWLINE# #INDENT# self . italic = int ( found . group ( 1 ) ) #NEWLINE# #UNINDENT# LOG . info ( 'bold: %d' , self . bold ) #NEWLINE# LOG . info ( 'italic: %d' , self . italic ) #NEWLINE# line = f . readline ( ) #NEWLINE# line = line . strip ( ) #NEWLINE# #UNINDENT# if ( not line . startswith ( 'common ' ) ) : #NEWLINE# #INDENT# raise Exception ( ( 'Common information espected, found: ' + line ) ) #NEWLINE# #UNINDENT# found = self . page_width_re . search ( line ) #NEWLINE# if ( not found ) : #NEWLINE# #INDENT# raise Exception ( ( 'ScaleW espected, found: ' + line ) ) #NEWLINE# #UNINDENT# self . page_width = int ( found . group ( 1 ) ) #NEWLINE# LOG . info ( 'page width: %d' , self . page_width ) #NEWLINE# found = self . page_height_re . search ( line ) #NEWLINE# if ( not found ) : #NEWLINE# #INDENT# raise Exception ( ( 'ScaleH espected, found: ' + line ) ) #NEWLINE# #UNINDENT# self . page_height = int ( found . group ( 1 ) ) #NEWLINE# LOG . info ( 'page height: %d' , self . page_height ) #NEWLINE# found = self . line_height_re . search ( line ) #NEWLINE# if ( not found ) : #NEWLINE# #INDENT# raise Exception ( ( 'Line Height espected, found: ' + line ) ) #NEWLINE# #UNINDENT# self . line_height = int ( found . group ( 1 ) ) #NEWLINE# LOG . info ( 'line height: %d' , self . line_height ) #NEWLINE# found = self . base_re . search ( line ) #NEWLINE# if ( not found ) : #NEWLINE# #INDENT# raise Exception ( ( 'Base espected, found: ' + line ) ) #NEWLINE# #UNINDENT# self . baseline = int ( found . group ( 1 ) ) #NEWLINE# LOG . info ( 'baseline: %d' , self . baseline ) #NEWLINE# found = self . num_pages_re . search ( line ) #NEWLINE# if ( not found ) : #NEWLINE# #INDENT# raise Exception ( ( 'Num pages espected, found: ' + line ) ) #NEWLINE# #UNINDENT# num_pages = int ( found . group ( 1 ) ) #NEWLINE# self . texture_pages = ( [ None ] * num_pages ) #NEWLINE# LOG . info ( 'num texture pages: %d' , num_pages ) #NEWLINE# line = f . readline ( ) #NEWLINE# line = line . strip ( ) #NEWLINE# while line . startswith ( 'page' ) : #NEWLINE# #INDENT# self . __read_page ( line ) #NEWLINE# line = f . readline ( ) #NEWLINE# line = line . strip ( ) #NEWLINE# #UNINDENT# found = self . num_chars_re . search ( line ) #NEWLINE# if ( not found ) : #NEWLINE# #INDENT# raise Exception ( ( 'Chars count espected, found: ' + line ) ) #NEWLINE# #UNINDENT# self . num_glyphs = int ( found . group ( 1 ) ) #NEWLINE# if ( self . num_glyphs <= 0 ) : #NEWLINE# #INDENT# raise Exception ( 'No glyphs found!' ) #NEWLINE# #UNINDENT# LOG . info ( 'num glyphs: %d' , self . num_glyphs ) #NEWLINE# line = f . readline ( ) #NEWLINE# line = line . strip ( ) #NEWLINE# while line . startswith ( 'char' ) : #NEWLINE# #INDENT# self . __read_char ( line ) #NEWLINE# line = f . readline ( ) #NEWLINE# line = line . strip ( ) #NEWLINE# #UNINDENT# found = self . num_kernings_re . search ( line ) #NEWLINE# if found : #NEWLINE# #INDENT# num_kernings = int ( found . group ( 1 ) ) #NEWLINE# if ( num_kernings > 0 ) : #NEWLINE# #INDENT# line = f . readline ( ) #NEWLINE# line = line . strip ( ) #NEWLINE# while line . startswith ( 'kerning' ) : #NEWLINE# #INDENT# self . __read_kerning ( line ) #NEWLINE# line = f . readline ( ) #NEWLINE# line = line . strip ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# num_kernings = 0 #NEWLINE# #UNINDENT# LOG . info ( 'num kernings: %d' , num_kernings )