for( k = startIndex ; (visible < (charnum+1)) ; k++ ){
for( int l = 0 ; l < list.size() && (visible < (charnum+1)) ; l++ ){
run = (StrokingTextPainter.TextRun)list.get(l);
TextSpanLayout layout = run.getLayout();
if ( layout.hasCharacterIndex(k) ){
if ( layout.isOnATextPath() ){
GVTGlyphVector vector = layout.getGlyphVector();
//alt glyph ?
if ( layout.isAltGlyph() ){
//get the number of glyph visible here
int glyphs = vector.getNumGlyphs();
int visibleGlyphs = 0;
for( int h=0 ; h < glyphs ; h++ ){
if ( vector.isGlyphVisible(h)){
visibleGlyphs++;
}
}
//get the number of character associated
//to this run
int charactersInRun = 1;
while ( layout.hasCharacterIndex( k+1 )){
charactersInRun++;
k++;
}
visible += (int)(charactersInRun*visibleGlyphs/glyphs);
if ( visible > charnum +1 ){
visible = charnum +1;
}
}
else{
int lastGlyphIndexFound = -1;
do{
int glyphIndex = layout.getGlyphIndex(k);
if( glyphIndex == -1 ){
//probable missing glyph
if ( layout.isLeftToRight() ){
glyphIndex = 1 + lastGlyphIndexFound;
}
else{
glyphIndex = ( lastGlyphIndexFound == -1)
? vector.getNumGlyphs()-1
: lastGlyphIndexFound -1;
}
}
lastGlyphIndexFound = glyphIndex;
if ( vector.isGlyphVisible( glyphIndex ) ){
visible++;
}
k++;
}while ((visible < (charnum+1)) && layout.hasCharacterIndex(k) );
//got one too far
k--;
}
}
else{
visible++;
while ( (visible < (charnum+1)) && layout.hasCharacterIndex(k+1) ){
k++;
visible++;
}
}
}