@@ -137,12 +137,10 @@ public override int GetHashCode() {
137
137
struct GlyphLine {
138
138
public readonly int start ;
139
139
public readonly int count ;
140
- public readonly int totalCountUnits ;
141
140
142
- public GlyphLine ( int start , int count , int totalCountUnits ) {
141
+ public GlyphLine ( int start , int count ) {
143
142
this . start = start ;
144
143
this . count = count ;
145
- this . totalCountUnits = totalCountUnits ;
146
144
}
147
145
148
146
public GlyphPosition get ( int i , GlyphPosition [ ] glyphPositions ) {
@@ -185,7 +183,6 @@ public LineRange(int start, int end, int endExcludingWhitespace, int endIncludin
185
183
186
184
List < float > _lineWidths = new List < float > ( ) ;
187
185
188
- // float[] _lineBaseLines;
189
186
GlyphLine [ ] _glyphLines ;
190
187
GlyphPosition [ ] _glyphPositions ;
191
188
PaintRecord [ ] _paintRecords ;
@@ -306,10 +303,6 @@ public void layout(ParagraphConstraints constraints) {
306
303
this . _glyphLines = new GlyphLine [ LayoutUtils . minPowerOfTwo ( this . _lineRangeCount ) ] ;
307
304
}
308
305
309
- // if (this._lineBaseLines == null || this._lineBaseLines.Length < this._lineRangeCount) {
310
- // this._lineBaseLines = new float[this._lineRangeCount];
311
- // }
312
-
313
306
if ( this . _lineHeights == null || this . _lineHeights . Length < this . _lineRangeCount ) {
314
307
this . _lineHeights = new float [ LayoutUtils . minPowerOfTwo ( this . _lineRangeCount ) ] ;
315
308
}
@@ -442,6 +435,8 @@ public void layout(ParagraphConstraints constraints) {
442
435
int truncateCount = Layout . computeTruncateCount ( runXOffset , text , textStart ,
443
436
textCount , style , this . _width - ellipsisWidth , this . _tabStops ) ;
444
437
438
+ // If all the positions have not changed, use the cached ellipsized text
439
+ // else update the cache
445
440
if ( ! ( this . _ellipsizedLength == textStart + textCount - truncateCount &&
446
441
this . _ellipsizedText . Length == this . _ellipsizedLength + ellipsis . Length &&
447
442
this . _ellipsizedText . EndsWith ( ellipsis ) ) ) {
@@ -463,8 +458,6 @@ public void layout(ParagraphConstraints constraints) {
463
458
_advancesBuffer , _positionsBuffer , this . _tabStops , out var bounds ) ;
464
459
465
460
builder . allocRunPos ( style , text , textStart , textCount ) ;
466
- // bounds relative to first character
467
- bounds . x -= _positionsBuffer [ 0 ] ;
468
461
builder . setBounds ( bounds ) ;
469
462
470
463
// Update the max width of the words
@@ -567,7 +560,6 @@ void updateLineMetrics(FontMetrics metrics, float styleHeight) {
567
560
568
561
this . _lineHeights [ lineNumber ] = ( ( lineNumber == 0 ? 0 : this . _lineHeights [ lineNumber - 1 ] )
569
562
+ Mathf . Round ( maxLineSpacing + maxDescent ) ) ;
570
- // this._lineBaseLines[lineNumber] = this._lineHeights[lineNumber] - maxDescent;
571
563
yOffset += Mathf . Round ( maxLineSpacing + preMaxDescent ) ;
572
564
preMaxDescent = maxDescent ;
573
565
float lineXOffset = this . getLineXOffset ( runXOffset ) ;
@@ -578,12 +570,7 @@ void updateLineMetrics(FontMetrics metrics, float styleHeight) {
578
570
}
579
571
}
580
572
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 ) ;
587
574
for ( int i = 0 ; i < lineStyleRunCount ; i ++ ) {
588
575
var paintRecord = this . _paintRecords [ this . _paintRecordsCount - 1 - i ] ;
589
576
paintRecord . shift ( lineXOffset , yOffset ) ;
@@ -592,6 +579,10 @@ void updateLineMetrics(FontMetrics metrics, float styleHeight) {
592
579
}
593
580
594
581
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
595
586
this . _maxIntrinsicWidth = 0 ;
596
587
float lineBlockWidth = 0 ;
597
588
for ( int i = 0 ; i < this . _lineWidthCount ; ++ i ) {
@@ -602,6 +593,7 @@ void updateLineMetrics(FontMetrics metrics, float styleHeight) {
602
593
}
603
594
}
604
595
596
+ // min intrinsic width := minimum width this paragraph has to take, which equals the maximum word width
605
597
this . _maxIntrinsicWidth = Mathf . Max ( lineBlockWidth , this . _maxIntrinsicWidth ) ;
606
598
607
599
if ( this . _paragraphStyle . maxLines == 1 || ( this . _paragraphStyle . maxLines == null &&
@@ -641,6 +633,14 @@ int _countLineStyleRuns(LineRange lineRange, int styleRunIndex, out int maxTextC
641
633
return lineStyleRunCount ;
642
634
}
643
635
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
+
644
644
internal void setText ( string text , StyledRuns runs ) {
645
645
this . _text = text ;
646
646
this . _runs = runs ;
@@ -753,7 +753,7 @@ internal PositionWithAffinity getGlyphPositionAtCoordinate(float dx, float dy) {
753
753
if ( glyphLine . count == 0 ) {
754
754
int lineStartIndex = 0 ;
755
755
for ( int i = 0 ; i < yIndex ; i ++ ) {
756
- lineStartIndex += this . _glyphLines [ i ] . totalCountUnits ;
756
+ lineStartIndex += this . totalCodeUnitsInLine ( i ) ;
757
757
}
758
758
759
759
return new PositionWithAffinity ( lineStartIndex , TextAffinity . downstream ) ;
0 commit comments