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

Commit 0b560a6

Browse files
author
Yuncong Zhang
committed
Remove totalUnitCounts from glyphline.
1 parent c4a0647 commit 0b560a6

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

Runtime/ui/txt/layout.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ public static float doLayout(float offset, string text, int start, int count, Te
145145
}
146146
}
147147

148+
// bounds relative to first character
149+
bounds.x -= positions[0];
148150
return advance;
149151
}
150152

Runtime/ui/txt/paragraph.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,10 @@ public override int GetHashCode() {
137137
struct GlyphLine {
138138
public readonly int start;
139139
public readonly int count;
140-
public readonly int totalCountUnits;
141140

142-
public GlyphLine(int start, int count, int totalCountUnits) {
141+
public GlyphLine(int start, int count) {
143142
this.start = start;
144143
this.count = count;
145-
this.totalCountUnits = totalCountUnits;
146144
}
147145

148146
public GlyphPosition get(int i, GlyphPosition[] glyphPositions) {
@@ -185,7 +183,6 @@ public LineRange(int start, int end, int endExcludingWhitespace, int endIncludin
185183

186184
List<float> _lineWidths = new List<float>();
187185

188-
// float[] _lineBaseLines;
189186
GlyphLine[] _glyphLines;
190187
GlyphPosition[] _glyphPositions;
191188
PaintRecord[] _paintRecords;
@@ -306,10 +303,6 @@ public void layout(ParagraphConstraints constraints) {
306303
this._glyphLines = new GlyphLine[LayoutUtils.minPowerOfTwo(this._lineRangeCount)];
307304
}
308305

309-
// if (this._lineBaseLines == null || this._lineBaseLines.Length < this._lineRangeCount) {
310-
// this._lineBaseLines = new float[this._lineRangeCount];
311-
// }
312-
313306
if (this._lineHeights == null || this._lineHeights.Length < this._lineRangeCount) {
314307
this._lineHeights = new float[LayoutUtils.minPowerOfTwo(this._lineRangeCount)];
315308
}
@@ -442,6 +435,8 @@ public void layout(ParagraphConstraints constraints) {
442435
int truncateCount = Layout.computeTruncateCount(runXOffset, text, textStart,
443436
textCount, style, this._width - ellipsisWidth, this._tabStops);
444437

438+
// If all the positions have not changed, use the cached ellipsized text
439+
// else update the cache
445440
if (!(this._ellipsizedLength == textStart + textCount - truncateCount &&
446441
this._ellipsizedText.Length == this._ellipsizedLength + ellipsis.Length &&
447442
this._ellipsizedText.EndsWith(ellipsis))) {
@@ -463,8 +458,6 @@ public void layout(ParagraphConstraints constraints) {
463458
_advancesBuffer, _positionsBuffer, this._tabStops, out var bounds);
464459

465460
builder.allocRunPos(style, text, textStart, textCount);
466-
// bounds relative to first character
467-
bounds.x -= _positionsBuffer[0];
468461
builder.setBounds(bounds);
469462

470463
// Update the max width of the words
@@ -567,7 +560,6 @@ void updateLineMetrics(FontMetrics metrics, float styleHeight) {
567560

568561
this._lineHeights[lineNumber] = ((lineNumber == 0 ? 0 : this._lineHeights[lineNumber - 1])
569562
+ Mathf.Round(maxLineSpacing + maxDescent));
570-
// this._lineBaseLines[lineNumber] = this._lineHeights[lineNumber] - maxDescent;
571563
yOffset += Mathf.Round(maxLineSpacing + preMaxDescent);
572564
preMaxDescent = maxDescent;
573565
float lineXOffset = this.getLineXOffset(runXOffset);
@@ -578,12 +570,7 @@ void updateLineMetrics(FontMetrics metrics, float styleHeight) {
578570
}
579571
}
580572

581-
int lineStart = lineRange.start;
582-
int nextLineStart = lineNumber < this._lineRangeCount - 1
583-
? this._lineRanges[lineNumber + 1].start
584-
: this._text.Length;
585-
this._glyphLines[lineNumber] =
586-
new GlyphLine(glyphPositionLineStart, count, nextLineStart - lineStart);
573+
this._glyphLines[lineNumber] = new GlyphLine(glyphPositionLineStart, count);
587574
for (int i = 0; i < lineStyleRunCount; i++) {
588575
var paintRecord = this._paintRecords[this._paintRecordsCount - 1 - i];
589576
paintRecord.shift(lineXOffset, yOffset);
@@ -592,6 +579,10 @@ void updateLineMetrics(FontMetrics metrics, float styleHeight) {
592579
}
593580

594581
this._lineCount = lineLimit;
582+
583+
// Compute max intrinsic width and min intrinsic width
584+
// max intrinsic width := maximum width this paragraph could possibly expand, without any constraints,
585+
// which equals the length of the maximum hard-break line
595586
this._maxIntrinsicWidth = 0;
596587
float lineBlockWidth = 0;
597588
for (int i = 0; i < this._lineWidthCount; ++i) {
@@ -602,6 +593,7 @@ void updateLineMetrics(FontMetrics metrics, float styleHeight) {
602593
}
603594
}
604595

596+
// min intrinsic width := minimum width this paragraph has to take, which equals the maximum word width
605597
this._maxIntrinsicWidth = Mathf.Max(lineBlockWidth, this._maxIntrinsicWidth);
606598

607599
if (this._paragraphStyle.maxLines == 1 || (this._paragraphStyle.maxLines == null &&
@@ -641,6 +633,14 @@ int _countLineStyleRuns(LineRange lineRange, int styleRunIndex, out int maxTextC
641633
return lineStyleRunCount;
642634
}
643635

636+
internal int totalCodeUnitsInLine(int lineNumber) {
637+
int lineStart = this._lineRanges[lineNumber].start;
638+
int nextLineStart = lineNumber < this._lineRangeCount - 1
639+
? this._lineRanges[lineNumber + 1].start
640+
: this._text.Length;
641+
return nextLineStart - lineStart;
642+
}
643+
644644
internal void setText(string text, StyledRuns runs) {
645645
this._text = text;
646646
this._runs = runs;
@@ -753,7 +753,7 @@ internal PositionWithAffinity getGlyphPositionAtCoordinate(float dx, float dy) {
753753
if (glyphLine.count == 0) {
754754
int lineStartIndex = 0;
755755
for (int i = 0; i < yIndex; i++) {
756-
lineStartIndex += this._glyphLines[i].totalCountUnits;
756+
lineStartIndex += this.totalCodeUnitsInLine(i);
757757
}
758758

759759
return new PositionWithAffinity(lineStartIndex, TextAffinity.downstream);

0 commit comments

Comments
 (0)