private void createGlyf ( FontFileReader in , Map glyphs ) throws IOException { TTFDirTabEntry entry = ( TTFDirTabEntry ) dirTabs . get ( "glyf" ) ; int size = 0 ; int start = 0 ; int endOffset = 0 ; // Store this as the last loca if ( entry != null ) { pad4 ( ) ; start = currentPos ; /* Loca table must be in order by glyph index, so build * an array first and then write the glyph info and * location offset. */ int [ ] origIndexes = new int [ glyphs . size ( ) ] ; Iterator e = glyphs . keySet ( ) . iterator ( ) ; while ( e . hasNext ( ) ) { Integer origIndex = ( Integer ) e . next ( ) ; Integer subsetIndex = ( Integer ) glyphs . get ( origIndex ) ; origIndexes [ subsetIndex . intValue ( ) ] = origIndex . intValue ( ) ; } for ( int i = 0 ; i < origIndexes . length ; i ++ ) { int glyphLength = 0 ; int nextOffset = 0 ; int origGlyphIndex = origIndexes [ i ] ; if ( origGlyphIndex >= ( mtxTab . length - 1 ) ) { nextOffset = ( int ) lastLoca ; } else { nextOffset = ( int ) mtxTab [ origGlyphIndex + 1 ] . getOffset ( ) ; } glyphLength = nextOffset - ( int ) mtxTab [ origGlyphIndex ] . getOffset ( ) ; // Copy glyph System . arraycopy ( in . getBytes ( ( int ) entry . getOffset ( ) + ( int ) mtxTab [ origGlyphIndex ] . getOffset ( ) , glyphLength ) , 0 , output , currentPos , glyphLength ) ; // Update loca table writeULong ( locaOffset + i * 4 , currentPos - start ) ; if ( ( currentPos - start + glyphLength ) > endOffset ) { endOffset = ( currentPos - start + glyphLength ) ; } currentPos += glyphLength ; realSize += glyphLength ; } size = currentPos - start ; int checksum = getCheckSum ( start , size ) ; writeULong ( glyfDirOffset , checksum ) ; writeULong ( glyfDirOffset + 4 , start ) ; writeULong ( glyfDirOffset + 8 , size ) ; currentPos += 12 ; realSize += 12 ; // Update loca checksum and last loca index writeULong ( locaOffset + glyphs . size ( ) * 4 , endOffset ) ; checksum = getCheckSum ( locaOffset , glyphs . size ( ) * 4 + 4 ) ; writeULong ( locaDirOffset , checksum ) ; } else { throw new IOException ( "Can't find glyf table" ) ; } }
Create the glyf table and fill in loca table