@@ -155,7 +155,7 @@ else if (targetWidth <= font.data.spaceWidth) //
155155 break outer ;
156156 }
157157
158- int wrapIndex = fontData .getWrapIndex (run .glyphs , i - 1 );
158+ int wrapIndex = fontData .getWrapIndex (run .glyphs , i );
159159 if ((run .x == 0 && wrapIndex == 0 ) // Require at least one glyph per line.
160160 || wrapIndex >= run .glyphs .size ) { // Wrap at least the glyph that didn't fit.
161161 wrapIndex = i - 1 ;
@@ -272,39 +272,30 @@ private GlyphRun wrap (BitmapFontData fontData, GlyphRun first, Pool<GlyphRun> g
272272 second .color .set (first .color );
273273 int glyphCount = first .glyphs .size ;
274274
275- // Determine index where first run ends, ignoring whitespace before the wrap index.
276- int endIndex = wrapIndex ;
277- for (; endIndex > 0 ; endIndex --)
278- if (!fontData .isWhitespace ((char )first .glyphs .get (endIndex - 1 ).id )) break ;
279-
280- // Determine index where second run starts, ignoring whitespace after the wrap index.
281- int startIndex = wrapIndex ;
282- for (; startIndex < glyphCount ; startIndex ++)
283- if (!fontData .isWhitespace ((char )first .glyphs .get (startIndex ).id )) break ;
284-
285275 // Copy wrapped glyphs and xAdvances to second run.
286- if (startIndex < glyphCount ) {
287- second .glyphs .addAll (first .glyphs , startIndex , glyphCount - startIndex );
276+ if (wrapIndex < glyphCount ) {
277+ second .glyphs .addAll (first .glyphs , wrapIndex , glyphCount - wrapIndex );
278+ // second.xAdvances.add(-second.glyphs.first().xoffset * fontData.scaleX - fontData.padLeft);
288279 second .xAdvances .add (-second .glyphs .first ().xoffset * fontData .scaleX - fontData .padLeft );
289- second .xAdvances .addAll (first .xAdvances , startIndex + 1 , first .xAdvances .size - (startIndex + 1 ));
280+ second .xAdvances .addAll (first .xAdvances , wrapIndex + 1 , first .xAdvances .size - (wrapIndex + 1 ));
290281 }
291282
292283 // Increase first run width up to the end index.
293- while (widthIndex < endIndex )
284+ while (widthIndex < wrapIndex )
294285 first .width += first .xAdvances .get (widthIndex ++);
295286
296287 // Reduce first run width by the wrapped glyphs that have contributed to the width.
297- while (widthIndex > endIndex + 1 )
288+ while (widthIndex > wrapIndex + 1 )
298289 first .width -= first .xAdvances .get (--widthIndex );
299290
300- if (endIndex == 0 ) {
291+ if (wrapIndex == 0 ) {
301292 // If the first run is now empty, remove it.
302293 glyphRunPool .free (first );
303294 runs .pop ();
304295 } else {
305296 // Truncate wrapped glyphs from first run.
306- first .glyphs .truncate (endIndex );
307- first .xAdvances .truncate (endIndex + 1 );
297+ first .glyphs .truncate (wrapIndex );
298+ first .xAdvances .truncate (wrapIndex + 1 );
308299 adjustLastGlyph (fontData , first );
309300 }
310301 return second ;
0 commit comments