private static void processFontDirectory ( File dir , ArrayList fonts ) { if ( ! dir . exists ( ) ) { return ; } if ( processed . contains ( dir ) ) { return ; } processed . add ( dir ) ; File [ ] sources = dir . listFiles ( ) ; if ( sources == null ) { return ; } for ( int j = 0 ; j < sources . length ; j ++ ) { File source = sources [ j ] ; if ( source . getName ( ) . equals ( "." ) ) { continue ; } if ( source . getName ( ) . equals ( ".." ) ) { continue ; } if ( source . isDirectory ( ) ) { processFontDirectory ( source , fonts ) ; continue ; } if ( source . getName ( ) . toLowerCase ( ) . endsWith ( ".ttf" ) ) { try { if ( statusListener != null ) { statusListener . updateStatus ( "Processing " + source . getName ( ) ) ; } FontData data = new FontData ( new FileInputStream ( source ) , 1 ) ; fonts . add ( data ) ; String famName = data . getFamilyName ( ) ; if ( ! families . contains ( famName ) ) { families . add ( famName ) ; } boolean bo = data . getJavaFont ( ) . isBold ( ) ; boolean it = data . getJavaFont ( ) . isItalic ( ) ; if ( ( bo ) && ( it ) ) { bolditalic . put ( famName , data ) ; } else if ( bo ) { bold . put ( famName , data ) ; } else if ( it ) { italic . put ( famName , data ) ; } else { plain . put ( famName , data ) ; } } catch ( Exception e ) { if ( DEBUG ) { System . err . println ( "Unable to process: " + source . getAbsolutePath ( ) + " (" + e . getClass ( ) + ": " + e . getMessage ( ) + ")" ) ; } if ( statusListener != null ) { statusListener . updateStatus ( "Unable to process: " + source . getName ( ) ) ; } } } } }
Process a directory potentially full of fonts