private void scanGlyphs ( FontFileReader in , Map glyphs ) throws IOException { TTFDirTabEntry entry = ( TTFDirTabEntry ) dirTabs . get ( "glyf" ) ; Map newComposites = null ; Map allComposites = new java . util . HashMap ( ) ; int newIndex = glyphs . size ( ) ; if ( entry != null ) { while ( newComposites == null || newComposites . size ( ) > 0 ) { // Inefficient to iterate through all glyphs newComposites = new java . util . HashMap ( ) ; Iterator e = glyphs . keySet ( ) . iterator ( ) ; while ( e . hasNext ( ) ) { Integer origIndex = ( Integer ) e . next ( ) ; if ( in . readTTFShort ( entry . getOffset ( ) + mtxTab [ origIndex . intValue ( ) ] . getOffset ( ) ) < 0 ) { // origIndex is a composite glyph allComposites . put ( origIndex , glyphs . get ( origIndex ) ) ; List composites = getIncludedGlyphs ( in , ( int ) entry . getOffset ( ) , origIndex ) ; // Iterate through all composites pointed to // by this composite and check if they exists // in the glyphs map, add them if not. Iterator cps = composites . iterator ( ) ; while ( cps . hasNext ( ) ) { Integer cIdx = ( Integer ) cps . next ( ) ; if ( glyphs . get ( cIdx ) == null && newComposites . get ( cIdx ) == null ) { newComposites . put ( cIdx , new Integer ( newIndex ) ) ; newIndex ++ ; } } } } // Add composites to glyphs Iterator m = newComposites . keySet ( ) . iterator ( ) ; while ( m . hasNext ( ) ) { Integer im = ( Integer ) m . next ( ) ; glyphs . put ( im , newComposites . get ( im ) ) ; } } // Iterate through all composites to remap their composite index Iterator ce = allComposites . keySet ( ) . iterator ( ) ; while ( ce . hasNext ( ) ) { remapComposite ( in , glyphs , ( int ) entry . getOffset ( ) , ( Integer ) ce . next ( ) ) ; } } else { throw new IOException ( "Can't find glyf table" ) ; } }
Scan all the original glyphs for composite glyphs and add those glyphs to the glyphmapping also rewrite the composite glyph pointers to the new mapping