public int registerDirectory ( String dir , boolean scanSubdirectories ) { int count = 0 ; try { File file = new File ( dir ) ; if ( ! file . exists ( ) || ! file . isDirectory ( ) ) return 0 ; String files [ ] = file . list ( ) ; if ( files == null ) return 0 ; for ( int k = 0 ; k < files . length ; ++ k ) { try { file = new File ( dir , files [ k ] ) ; if ( file . isDirectory ( ) ) { if ( scanSubdirectories ) { count += registerDirectory ( file . getAbsolutePath ( ) , true ) ; } } else { String name = file . getPath ( ) ; String suffix = name . length ( ) < 4 ? null : name . substring ( name . length ( ) - 4 ) . toLowerCase ( ) ; if ( ".afm" . equals ( suffix ) || ".pfm" . equals ( suffix ) ) { /* Only register Type 1 fonts with matching .pfb files */ File pfb = new File ( name . substring ( 0 , name . length ( ) - 4 ) + ".pfb" ) ; if ( pfb . exists ( ) ) { register ( name , null ) ; ++ count ; } } else if ( ".ttf" . equals ( suffix ) || ".otf" . equals ( suffix ) || ".ttc" . equals ( suffix ) ) { register ( name , null ) ; ++ count ; } } } catch ( Exception e ) { //empty on purpose } } } catch ( Exception e ) { //empty on purpose } return count ; }
Register all the fonts in a directory and possibly its subdirectories .