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

Commit c164d2e

Browse files
author
Yuncong Zhang
committed
Allocate text blob positions in paragraph.
1 parent aa25531 commit c164d2e

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

Runtime/ui/txt/paragraph.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,16 @@ public LineRange(int start, int end, int endExcludingWhitespace, int endIncludin
190190
List<float> _lineWidths = new List<float>();
191191
// float[] _lineBaseLines;
192192
GlyphLine[] _glyphLines;
193+
GlyphPosition[] glyphPositions;
194+
PaintRecord[] _paintRecords;
195+
CodeUnitRun[] _codeUnitRuns;
196+
float[] _lineHeights;
197+
float[] _textBlobPositions;
193198
float _maxIntrinsicWidth;
194199
float _minIntrinsicWidth;
195200
float _alphabeticBaseline;
196201
float _ideographicBaseline;
197-
float[] _lineHeights;
198-
GlyphPosition[] glyphPositions;
199202
int _lineCount;
200-
PaintRecord[] _paintRecords;
201-
CodeUnitRun[] _codeUnitRuns;
202203
int _paintRecordsCount;
203204
int _codeUnitRunsCount;
204205
bool _didExceedMaxLines;
@@ -320,7 +321,10 @@ public void layout(ParagraphConstraints constraints) {
320321
int ellipsizedLength = this._text.Length + (this._paragraphStyle.ellipsis?.Length ?? 0);
321322

322323
// All text blobs share a single position buffer, which is big enough taking ellipsis into consideration
323-
builder.allocPos(ellipsizedLength);
324+
if (this._textBlobPositions == null || this._textBlobPositions.Length < ellipsizedLength) {
325+
this._textBlobPositions = new float[ellipsizedLength];
326+
}
327+
builder.setPositions(this._textBlobPositions);
324328
// this._glyphLines and this._codeUnitRuns will refer to this array for glyph positions
325329
if (this.glyphPositions == null || this.glyphPositions.Length < ellipsizedLength) {
326330
this.glyphPositions = new GlyphPosition[ellipsizedLength];
@@ -480,12 +484,11 @@ public void layout(ParagraphConstraints constraints) {
480484
runXOffset += advance;
481485

482486
// Create code unit run
483-
CodeUnitRun codeUnitRun = new CodeUnitRun(
487+
this._codeUnitRuns[this._codeUnitRunsCount++] = new CodeUnitRun(
484488
this.glyphPositions,
485489
new Range<int>(start, end),
486490
new Range<float>(this.glyphPositions[0].xPos.start, this.glyphPositions.last().xPos.end),
487491
lineNumber, TextDirection.ltr, glyphPositionStyleRunStart, textCount);
488-
this._codeUnitRuns[this._codeUnitRunsCount++] = codeUnitRun;
489492

490493
lineStyleRunIndex++;
491494
}

0 commit comments

Comments
 (0)