Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit 0ee21d6

Browse files
author
Yuncong Zhang
committed
Make glyphPosition a member.
1 parent 0abf5c5 commit 0ee21d6

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

Runtime/ui/txt/paragraph.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ public LineRange(int start, int end, int endExcludingWhitespace, int endIncludin
195195
float _alphabeticBaseline;
196196
float _ideographicBaseline;
197197
float[] _lineHeights;
198+
GlyphPosition[] glyphPositions;
198199
int _lineCount;
199200
List<PaintRecord> _paintRecords = new List<PaintRecord>();
200201
List<CodeUnitRun> _codeUnitRuns = new List<CodeUnitRun>();
@@ -306,7 +307,10 @@ public void layout(ParagraphConstraints constraints) {
306307
// All text blobs share a single position buffer, which is big enough taking ellipsis into consideration
307308
builder.allocPos(ellipsizedLength);
308309
// 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+
310314
// Pointer to the glyphPositions array, to keep track of where the next glyph is stored
311315
int pGlyphPositions = 0;
312316

@@ -423,7 +427,7 @@ public void layout(ParagraphConstraints constraints) {
423427
float glyphXOffset = _positionsBuffer[glyphIndex] + justifyXOffset;
424428
float glyphAdvance = _advancesBuffer[glyphIndex];
425429
builder.setPosition(glyphIndex, glyphXOffset);
426-
glyphPositions[pGlyphPositions++] = new GlyphPosition(runXOffset + glyphXOffset,
430+
this.glyphPositions[pGlyphPositions++] = new GlyphPosition(runXOffset + glyphXOffset,
427431
glyphAdvance, new Range<int>(textStart + glyphIndex, textStart + glyphIndex + 1));
428432
if (wordIndex < wordCount) {
429433
Range<int> word = _wordsBuffer[wordIndex];
@@ -444,7 +448,7 @@ public void layout(ParagraphConstraints constraints) {
444448
// width of this word, and update the entire word
445449
if (!float.IsNaN(wordStartPosition)) {
446450
maxWordWidth = Mathf.Max(maxWordWidth,
447-
glyphPositions[pGlyphPositions - 1].xPos.end - wordStartPosition);
451+
this.glyphPositions[pGlyphPositions - 1].xPos.end - wordStartPosition);
448452
wordStartPosition = float.NaN;
449453
}
450454
}
@@ -462,9 +466,9 @@ public void layout(ParagraphConstraints constraints) {
462466

463467
// Create code unit run
464468
this._codeUnitRuns.Add(new CodeUnitRun(
465-
glyphPositions,
469+
this.glyphPositions,
466470
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),
468472
lineNumber, TextDirection.ltr, glyphPositionStyleRunStart, textCount));
469473

470474
lineStyleRunIndex++;
@@ -521,9 +525,9 @@ void updateLineMetrics(FontMetrics metrics, float styleHeight) {
521525
preMaxDescent = maxDescent;
522526
float lineXOffset = this.getLineXOffset(runXOffset);
523527
int count = pGlyphPositions - glyphPositionLineStart;
524-
if (lineXOffset != 0 && glyphPositions != null) {
528+
if (lineXOffset != 0 && this.glyphPositions != null) {
525529
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);
527531
}
528532
}
529533

@@ -532,7 +536,7 @@ void updateLineMetrics(FontMetrics metrics, float styleHeight) {
532536
? this._lineRanges[lineNumber + 1].start
533537
: this._text.Length;
534538
this._glyphLines[lineNumber] =
535-
new GlyphLine(glyphPositions, glyphPositionLineStart, count, nextLineStart - lineStart);
539+
new GlyphLine(this.glyphPositions, glyphPositionLineStart, count, nextLineStart - lineStart);
536540
for (int i = 0; i < lineStyleRunCount; i++) {
537541
var paintRecord = this._paintRecords[this._paintRecords.Count - 1 - i];
538542
paintRecord.shift(lineXOffset, yOffset);

0 commit comments

Comments
 (0)