1
1
using System ;
2
2
using System . Collections ;
3
3
using System . Collections . Generic ;
4
- using System . Linq ;
5
4
using Unity . UIWidgets . foundation ;
6
5
using UnityEngine ;
7
6
@@ -183,7 +182,9 @@ public LineRange(int start, int end, int endExcludingWhitespace, int endIncludin
183
182
184
183
ParagraphStyle _paragraphStyle ;
185
184
List < LineRange > _lineRanges = new List < LineRange > ( ) ;
185
+
186
186
List < float > _lineWidths = new List < float > ( ) ;
187
+
187
188
// float[] _lineBaseLines;
188
189
GlyphLine [ ] _glyphLines ;
189
190
GlyphPosition [ ] _glyphPositions ;
@@ -247,7 +248,7 @@ public float ideographicBaseline {
247
248
public bool didExceedMaxLines {
248
249
get { return this . _didExceedMaxLines ; }
249
250
}
250
-
251
+
251
252
static List < Paragraph > _paragraphs = new List < Paragraph > ( ) ;
252
253
253
254
public static Paragraph create ( ) {
@@ -256,7 +257,7 @@ public static Paragraph create() {
256
257
}
257
258
258
259
Paragraph ret = _paragraphs . last ( ) ;
259
- _paragraphs . RemoveAt ( _paragraphs . Count - 1 ) ;
260
+ _paragraphs . RemoveAt ( _paragraphs . Count - 1 ) ;
260
261
return ret ;
261
262
}
262
263
@@ -300,7 +301,7 @@ public void layout(ParagraphConstraints constraints) {
300
301
this . _width = Mathf . Floor ( constraints . width ) ;
301
302
302
303
int lineStyleRunsCount = this . _computeLineBreak ( ) ;
303
-
304
+
304
305
if ( this . _glyphLines == null || this . _glyphLines . Length < this . _lineRangeCount ) {
305
306
this . _glyphLines = new GlyphLine [ LayoutUtils . minPowerOfTwo ( this . _lineRangeCount ) ] ;
306
307
}
@@ -316,7 +317,7 @@ public void layout(ParagraphConstraints constraints) {
316
317
if ( this . _paintRecords == null || this . _paintRecords . Length < lineStyleRunsCount ) {
317
318
this . _paintRecords = new PaintRecord [ LayoutUtils . minPowerOfTwo ( lineStyleRunsCount ) ] ;
318
319
}
319
-
320
+
320
321
this . _paintRecordsCount = 0 ;
321
322
322
323
if ( this . _codeUnitRuns == null || this . _codeUnitRuns . Length < lineStyleRunsCount ) {
@@ -336,11 +337,12 @@ public void layout(ParagraphConstraints constraints) {
336
337
337
338
TextBlobBuilder builder = new TextBlobBuilder ( ) ;
338
339
int ellipsizedLength = this . _text . Length + ( this . _paragraphStyle . ellipsis ? . Length ?? 0 ) ;
339
-
340
+
340
341
// All text blobs share a single position buffer, which is big enough taking ellipsis into consideration
341
342
if ( this . _textBlobPositions == null || this . _textBlobPositions . Length < ellipsizedLength ) {
342
343
this . _textBlobPositions = new float [ LayoutUtils . minPowerOfTwo ( ellipsizedLength ) ] ;
343
344
}
345
+
344
346
builder . setPositions ( this . _textBlobPositions ) ;
345
347
// this._glyphLines and this._codeUnitRuns will refer to this array for glyph positions
346
348
if ( this . _glyphPositions == null || this . _glyphPositions . Length < ellipsizedLength ) {
@@ -349,7 +351,7 @@ public void layout(ParagraphConstraints constraints) {
349
351
350
352
// Pointer to the _glyphPositions array, to keep track of where the next glyph is stored
351
353
int pGlyphPositions = 0 ;
352
-
354
+
353
355
// Compute max(NumberOfWords(line) for line in lines), to determine the size of word buffers
354
356
int maxWordCount = this . _computeMaxWordCount ( ) ;
355
357
@@ -387,6 +389,7 @@ public void layout(ParagraphConstraints constraints) {
387
389
( lineNumber == lineLimit - 1 || this . _paragraphStyle . maxLines == null ) ) {
388
390
maxTextCount += ellipsis . Length ;
389
391
}
392
+
390
393
// Allocate the advances and positions to store the layout result
391
394
// TODO: find a way to compute the maxTextCount for the entire paragraph, so that this allocation
392
395
// happens only once
@@ -439,13 +442,14 @@ public void layout(ParagraphConstraints constraints) {
439
442
int truncateCount = Layout . computeTruncateCount ( runXOffset , text , textStart ,
440
443
textCount , style , this . _width - ellipsisWidth , this . _tabStops ) ;
441
444
442
- if ( ! ( this . _ellipsizedLength == textStart + textCount - truncateCount &&
443
- this . _ellipsizedText . Length == this . _ellipsizedLength + ellipsis . Length &&
444
- this . _ellipsizedText . EndsWith ( ellipsis ) ) ) {
445
+ if ( ! ( this . _ellipsizedLength == textStart + textCount - truncateCount &&
446
+ this . _ellipsizedText . Length == this . _ellipsizedLength + ellipsis . Length &&
447
+ this . _ellipsizedText . EndsWith ( ellipsis ) ) ) {
445
448
this . _ellipsizedText =
446
449
text . Substring ( 0 , textStart + textCount - truncateCount ) + ellipsis ;
447
450
this . _ellipsizedLength = this . _ellipsizedText . Length - ellipsis . Length ;
448
451
}
452
+
449
453
text = this . _ellipsizedText ;
450
454
textCount = text . Length - textStart ;
451
455
D . assert ( textCount != 0 ) ;
@@ -511,7 +515,7 @@ public void layout(ParagraphConstraints constraints) {
511
515
this . _codeUnitRuns [ this . _codeUnitRunsCount ++ ] = new CodeUnitRun (
512
516
new Range < int > ( start , end ) ,
513
517
new Range < float > ( this . _glyphPositions [ glyphPositionStyleRunStart ] . xPos . start ,
514
- this . _glyphPositions [ pGlyphPositions - 1 ] . xPos . end ) ,
518
+ this . _glyphPositions [ pGlyphPositions - 1 ] . xPos . end ) ,
515
519
lineNumber , TextDirection . ltr , glyphPositionStyleRunStart , textCount ) ;
516
520
517
521
lineStyleRunIndex ++ ;
@@ -562,7 +566,7 @@ void updateLineMetrics(FontMetrics metrics, float styleHeight) {
562
566
}
563
567
564
568
this . _lineHeights [ lineNumber ] = ( ( lineNumber == 0 ? 0 : this . _lineHeights [ lineNumber - 1 ] )
565
- + Mathf . Round ( maxLineSpacing + maxDescent ) ) ;
569
+ + Mathf . Round ( maxLineSpacing + maxDescent ) ) ;
566
570
// this._lineBaseLines[lineNumber] = this._lineHeights[lineNumber] - maxDescent;
567
571
yOffset += Mathf . Round ( maxLineSpacing + preMaxDescent ) ;
568
572
preMaxDescent = maxDescent ;
@@ -578,7 +582,7 @@ void updateLineMetrics(FontMetrics metrics, float styleHeight) {
578
582
int nextLineStart = lineNumber < this . _lineRangeCount - 1
579
583
? this . _lineRanges [ lineNumber + 1 ] . start
580
584
: this . _text . Length ;
581
- this . _glyphLines [ lineNumber ] =
585
+ this . _glyphLines [ lineNumber ] =
582
586
new GlyphLine ( glyphPositionLineStart , count , nextLineStart - lineStart ) ;
583
587
for ( int i = 0 ; i < lineStyleRunCount ; i ++ ) {
584
588
var paintRecord = this . _paintRecords [ this . _paintRecordsCount - 1 - i ] ;
@@ -751,6 +755,7 @@ internal PositionWithAffinity getGlyphPositionAtCoordinate(float dx, float dy) {
751
755
for ( int i = 0 ; i < yIndex ; i ++ ) {
752
756
lineStartIndex += this . _glyphLines [ i ] . totalCountUnits ;
753
757
}
758
+
754
759
return new PositionWithAffinity ( lineStartIndex , TextAffinity . downstream ) ;
755
760
}
756
761
@@ -843,18 +848,20 @@ int _computeLineBreak() {
843
848
if ( lineLimit != 0 && this . _lineRangeCount >= lineLimit ) {
844
849
break ;
845
850
}
851
+
846
852
var blockStart = newlineIndex > 0 ? newLinePositions [ newlineIndex - 1 ] + 1 : 0 ;
847
853
var blockEnd = newLinePositions [ newlineIndex ] ;
848
854
var blockSize = blockEnd - blockStart ;
849
855
if ( blockSize == 0 ) {
850
856
this . _addEmptyLine ( blockStart , blockEnd ) ;
851
857
continue ;
852
858
}
859
+
853
860
if ( lineLimit != 0 && this . _lineRangeCount >= lineLimit ) {
854
861
break ;
855
862
}
856
863
857
- this . _resetLineBreaker ( lineBreaker , blockStart , blockSize ,
864
+ this . _resetLineBreaker ( lineBreaker , blockStart , blockSize ,
858
865
lineLimit == 0 ? 0 : lineLimit - this . _lineRangeCount ) ;
859
866
countRuns += this . _addStyleRuns ( lineBreaker , ref runIndex , blockStart , blockEnd ) ;
860
867
0 commit comments