public int loadGlyphs ( List glyphs , int maxGlyphsToLoad ) throws SlickException { if ( rowHeight != 0 && maxGlyphsToLoad == - 1 ) { // If this page has glyphs and we are not loading incrementally, return zero if any of the glyphs don't fit. int testX = pageX ; int testY = pageY ; int testRowHeight = rowHeight ; for ( Iterator iter = getIterator ( glyphs ) ; iter . hasNext ( ) ; ) { Glyph glyph = ( Glyph ) iter . next ( ) ; int width = glyph . getWidth ( ) ; int height = glyph . getHeight ( ) ; if ( testX + width >= pageWidth ) { testX = 0 ; testY += testRowHeight ; testRowHeight = height ; } else if ( height > testRowHeight ) { testRowHeight = height ; } if ( testY + testRowHeight >= pageWidth ) return 0 ; testX += width ; } } Color . white . bind ( ) ; pageImage . bind ( ) ; int i = 0 ; for ( Iterator iter = getIterator ( glyphs ) ; iter . hasNext ( ) ; ) { Glyph glyph = ( Glyph ) iter . next ( ) ; int width = Math . min ( MAX_GLYPH_SIZE , glyph . getWidth ( ) ) ; int height = Math . min ( MAX_GLYPH_SIZE , glyph . getHeight ( ) ) ; if ( rowHeight == 0 ) { // The first glyph always fits. rowHeight = height ; } else { // Wrap to the next line if needed, or break if no more fit. if ( pageX + width >= pageWidth ) { if ( pageY + rowHeight + height >= pageHeight ) break ; pageX = 0 ; pageY += rowHeight ; rowHeight = height ; } else if ( height > rowHeight ) { if ( pageY + height >= pageHeight ) break ; rowHeight = height ; } } renderGlyph ( glyph , width , height ) ; pageGlyphs . add ( glyph ) ; pageX += width ; iter . remove ( ) ; i ++ ; if ( i == maxGlyphsToLoad ) { // If loading incrementally, flip orderAscending so it won't change, since we'll probably load the rest next time. orderAscending = ! orderAscending ; break ; } } TextureImpl . bindNone ( ) ; // Every other batch of glyphs added to a page are sorted the opposite way to attempt to keep same size glyps together. orderAscending = ! orderAscending ; return i ; }
Loads glyphs to the backing texture and sets the image on each loaded glyph . Loaded glyphs are removed from the list .