@@ -172,7 +172,7 @@ public void setText (BitmapFont font, CharSequence str, int start, int end, Colo
172
172
runEnded :
173
173
{
174
174
// Store the run that has ended.
175
- GlyphRun run = glyphRunPool . obtain ();
175
+ GlyphRun run = obtainRun ();
176
176
run .x = 0 ;
177
177
run .y = y ;
178
178
fontData .getGlyphs (run , str , runStart , runEnd , lastGlyph );
@@ -190,14 +190,14 @@ public void setText (BitmapFont font, CharSequence str, int start, int end, Colo
190
190
}
191
191
192
192
if (run .glyphs .size == 0 ) {
193
- glyphRunPool . free (run );
193
+ freeRun (run );
194
194
if (lineRun == null ) break runEnded ; // Otherwise wrap and truncate must still be processed for lineRun.
195
195
} else if (lineRun == null ) {
196
196
lineRun = run ;
197
197
runs .add (lineRun );
198
198
} else {
199
199
lineRun .appendRun (run );
200
- glyphRunPool . free (run );
200
+ freeRun (run );
201
201
}
202
202
203
203
if (newline || isLastRun ) {
@@ -310,7 +310,7 @@ private void truncate (BitmapFontData fontData, GlyphRun run, float targetWidth,
310
310
int glyphCount = run .glyphs .size ;
311
311
312
312
// Determine truncate string size.
313
- GlyphRun truncateRun = glyphRunPool . obtain ();
313
+ GlyphRun truncateRun = obtainRun ();
314
314
fontData .getGlyphs (truncateRun , truncate , 0 , truncate .length (), null );
315
315
float truncateWidth = 0 ;
316
316
if (truncateRun .xAdvances .size > 0 ) {
@@ -357,7 +357,7 @@ private void truncate (BitmapFontData fontData, GlyphRun run, float targetWidth,
357
357
run .glyphs .addAll (truncateRun .glyphs );
358
358
this .glyphCount += truncate .length ();
359
359
360
- glyphRunPool . free (truncateRun );
360
+ freeRun (truncateRun );
361
361
}
362
362
363
363
/** Breaks a run into two runs at the specified wrapIndex.
@@ -381,7 +381,7 @@ private GlyphRun wrap (BitmapFontData fontData, GlyphRun first, int wrapIndex) {
381
381
// The second run will contain the remaining glyph data, so swap instances rather than copying.
382
382
GlyphRun second = null ;
383
383
if (secondStart < glyphCount ) {
384
- second = glyphRunPool . obtain ();
384
+ second = obtainRun ();
385
385
386
386
Array <Glyph > glyphs1 = second .glyphs ; // Starts empty.
387
387
glyphs1 .addAll (glyphs2 , 0 , firstEnd );
@@ -430,7 +430,7 @@ private GlyphRun wrap (BitmapFontData fontData, GlyphRun first, int wrapIndex) {
430
430
431
431
if (firstEnd == 0 ) {
432
432
// If the first run is now empty, remove it.
433
- glyphRunPool . free (first );
433
+ freeRun (first );
434
434
runs .pop ();
435
435
} else
436
436
setLastGlyphXAdvance (fontData , first );
@@ -499,14 +499,29 @@ else if (ch >= 'a' && ch <= 'f')
499
499
}
500
500
501
501
public void reset () {
502
- glyphRunPool . freeAll (runs );
502
+ freeAllRuns (runs );
503
503
runs .clear ();
504
504
colors .clear ();
505
505
glyphCount = 0 ;
506
506
width = 0 ;
507
507
height = 0 ;
508
508
}
509
509
510
+ /** Obtains a GlyphRun */
511
+ protected GlyphRun obtainRun () {
512
+ return glyphRunPool .obtain ();
513
+ }
514
+
515
+ /** Releases a previously obtained GlyphRun */
516
+ protected void freeRun (GlyphRun run ) {
517
+ glyphRunPool .free (run );
518
+ }
519
+
520
+ /** Releases an array of previously obtained GlyphRuns */
521
+ protected void freeAllRuns (Array <GlyphRun > runs ) {
522
+ glyphRunPool .freeAll (runs );
523
+ }
524
+
510
525
public String toString () {
511
526
if (runs .size == 0 ) return "" ;
512
527
StringBuilder buffer = new StringBuilder (128 );
@@ -535,7 +550,7 @@ static public class GlyphRun implements Poolable {
535
550
536
551
public float x , y , width ;
537
552
538
- void appendRun (GlyphRun run ) {
553
+ public void appendRun (GlyphRun run ) {
539
554
glyphs .addAll (run .glyphs );
540
555
// Remove the width of the last glyph. The first xadvance of the appended run has kerning for the last glyph of this run.
541
556
if (xAdvances .notEmpty ()) xAdvances .size --;
0 commit comments