public Phrase process ( String text ) { int fsize = fonts . size ( ) ; if ( fsize == 0 ) throw new IndexOutOfBoundsException ( "No font is defined." ) ; char cc [ ] = text . toCharArray ( ) ; int len = cc . length ; StringBuffer sb = new StringBuffer ( ) ; Font font = null ; int lastidx = - 1 ; Phrase ret = new Phrase ( ) ; for ( int k = 0 ; k < len ; ++ k ) { char c = cc [ k ] ; if ( c == ' ' || c == ' ' ) { sb . append ( c ) ; continue ; } if ( Utilities . isSurrogatePair ( cc , k ) ) { int u = Utilities . convertToUtf32 ( cc , k ) ; for ( int f = 0 ; f < fsize ; ++ f ) { font = ( Font ) fonts . get ( f ) ; if ( font . getBaseFont ( ) . charExists ( u ) ) { if ( lastidx != f ) { if ( sb . length ( ) > 0 && lastidx != - 1 ) { Chunk ck = new Chunk ( sb . toString ( ) , ( Font ) fonts . get ( lastidx ) ) ; ret . add ( ck ) ; sb . setLength ( 0 ) ; } lastidx = f ; } sb . append ( c ) ; sb . append ( cc [ ++ k ] ) ; break ; } } } else { for ( int f = 0 ; f < fsize ; ++ f ) { font = ( Font ) fonts . get ( f ) ; if ( font . getBaseFont ( ) . charExists ( c ) ) { if ( lastidx != f ) { if ( sb . length ( ) > 0 && lastidx != - 1 ) { Chunk ck = new Chunk ( sb . toString ( ) , ( Font ) fonts . get ( lastidx ) ) ; ret . add ( ck ) ; sb . setLength ( 0 ) ; } lastidx = f ; } sb . append ( c ) ; break ; } } } } if ( sb . length ( ) > 0 ) { Chunk ck = new Chunk ( sb . toString ( ) , ( Font ) fonts . get ( lastidx == - 1 ? 0 : lastidx ) ) ; ret . add ( ck ) ; } return ret ; }
Process the text so that it will render with a combination of fonts if needed .