@@ -195,6 +195,7 @@ public LineRange(int start, int end, int endExcludingWhitespace, int endIncludin
195
195
float _alphabeticBaseline ;
196
196
float _ideographicBaseline ;
197
197
float [ ] _lineHeights ;
198
+ GlyphPosition [ ] glyphPositions ;
198
199
int _lineCount ;
199
200
List < PaintRecord > _paintRecords = new List < PaintRecord > ( ) ;
200
201
List < CodeUnitRun > _codeUnitRuns = new List < CodeUnitRun > ( ) ;
@@ -306,7 +307,10 @@ public void layout(ParagraphConstraints constraints) {
306
307
// All text blobs share a single position buffer, which is big enough taking ellipsis into consideration
307
308
builder . allocPos ( ellipsizedLength ) ;
308
309
// this._glyphLines and this._codeUnitRuns will refer to this array for glyph positions
309
- GlyphPosition [ ] glyphPositions = new GlyphPosition [ ellipsizedLength ] ;
310
+ if ( this . glyphPositions == null || this . glyphPositions . Length < ellipsizedLength ) {
311
+ this . glyphPositions = new GlyphPosition [ ellipsizedLength ] ;
312
+ }
313
+
310
314
// Pointer to the glyphPositions array, to keep track of where the next glyph is stored
311
315
int pGlyphPositions = 0 ;
312
316
@@ -423,7 +427,7 @@ public void layout(ParagraphConstraints constraints) {
423
427
float glyphXOffset = _positionsBuffer [ glyphIndex ] + justifyXOffset ;
424
428
float glyphAdvance = _advancesBuffer [ glyphIndex ] ;
425
429
builder . setPosition ( glyphIndex , glyphXOffset ) ;
426
- glyphPositions [ pGlyphPositions ++ ] = new GlyphPosition ( runXOffset + glyphXOffset ,
430
+ this . glyphPositions [ pGlyphPositions ++ ] = new GlyphPosition ( runXOffset + glyphXOffset ,
427
431
glyphAdvance , new Range < int > ( textStart + glyphIndex , textStart + glyphIndex + 1 ) ) ;
428
432
if ( wordIndex < wordCount ) {
429
433
Range < int > word = _wordsBuffer [ wordIndex ] ;
@@ -444,7 +448,7 @@ public void layout(ParagraphConstraints constraints) {
444
448
// width of this word, and update the entire word
445
449
if ( ! float . IsNaN ( wordStartPosition ) ) {
446
450
maxWordWidth = Mathf . Max ( maxWordWidth ,
447
- glyphPositions [ pGlyphPositions - 1 ] . xPos . end - wordStartPosition ) ;
451
+ this . glyphPositions [ pGlyphPositions - 1 ] . xPos . end - wordStartPosition ) ;
448
452
wordStartPosition = float . NaN ;
449
453
}
450
454
}
@@ -462,9 +466,9 @@ public void layout(ParagraphConstraints constraints) {
462
466
463
467
// Create code unit run
464
468
this . _codeUnitRuns . Add ( new CodeUnitRun (
465
- glyphPositions ,
469
+ this . glyphPositions ,
466
470
new Range < int > ( start , end ) ,
467
- new Range < float > ( glyphPositions [ 0 ] . xPos . start , glyphPositions . last ( ) . xPos . end ) ,
471
+ new Range < float > ( this . glyphPositions [ 0 ] . xPos . start , this . glyphPositions . last ( ) . xPos . end ) ,
468
472
lineNumber , TextDirection . ltr , glyphPositionStyleRunStart , textCount ) ) ;
469
473
470
474
lineStyleRunIndex ++ ;
@@ -521,9 +525,9 @@ void updateLineMetrics(FontMetrics metrics, float styleHeight) {
521
525
preMaxDescent = maxDescent ;
522
526
float lineXOffset = this . getLineXOffset ( runXOffset ) ;
523
527
int count = pGlyphPositions - glyphPositionLineStart ;
524
- if ( lineXOffset != 0 && glyphPositions != null ) {
528
+ if ( lineXOffset != 0 && this . glyphPositions != null ) {
525
529
for ( int i = 0 ; i < count ; ++ i ) {
526
- glyphPositions [ glyphPositions . Length - i - 1 ] . shiftSelf ( lineXOffset ) ;
530
+ this . glyphPositions [ this . glyphPositions . Length - i - 1 ] . shiftSelf ( lineXOffset ) ;
527
531
}
528
532
}
529
533
@@ -532,7 +536,7 @@ void updateLineMetrics(FontMetrics metrics, float styleHeight) {
532
536
? this . _lineRanges [ lineNumber + 1 ] . start
533
537
: this . _text . Length ;
534
538
this . _glyphLines [ lineNumber ] =
535
- new GlyphLine ( glyphPositions , glyphPositionLineStart , count , nextLineStart - lineStart ) ;
539
+ new GlyphLine ( this . glyphPositions , glyphPositionLineStart , count , nextLineStart - lineStart ) ;
536
540
for ( int i = 0 ; i < lineStyleRunCount ; i ++ ) {
537
541
var paintRecord = this . _paintRecords [ this . _paintRecords . Count - 1 - i ] ;
538
542
paintRecord . shift ( lineXOffset , yOffset ) ;
0 commit comments