@@ -14,22 +14,19 @@ struct CodeUnitRun {
14
14
public readonly int start ;
15
15
public readonly int count ;
16
16
17
- readonly GlyphPosition [ ] _positions ;
18
-
19
- public CodeUnitRun ( GlyphPosition [ ] positions , Range < int > cu , Range < float > xPos , int line ,
17
+ public CodeUnitRun ( Range < int > cu , Range < float > xPos , int line ,
20
18
TextDirection direction , int start , int count ) {
21
19
this . lineNumber = line ;
22
20
this . codeUnits = cu ;
23
21
this . xPos = xPos ;
24
- this . _positions = positions ;
25
22
this . direction = direction ;
26
23
this . start = start ;
27
24
this . count = count ;
28
25
}
29
26
30
- public GlyphPosition get ( int i ) {
27
+ public GlyphPosition get ( int i , GlyphPosition [ ] glyphPositions ) {
31
28
D . assert ( i < this . count ) ;
32
- return this . _positions [ this . start + i ] ;
29
+ return glyphPositions [ this . start + i ] ;
33
30
}
34
31
}
35
32
@@ -89,11 +86,11 @@ public PositionWithAffinity(int p, TextAffinity a) {
89
86
90
87
struct GlyphPosition {
91
88
public Range < float > xPos ;
92
- public readonly Range < int > codeUnits ;
89
+ public readonly int codeUnit ;
93
90
94
- public GlyphPosition ( float start , float advance , Range < int > codeUnits ) {
91
+ public GlyphPosition ( float start , float advance , int codeUnit ) {
95
92
this . xPos = new Range < float > ( start , start + advance ) ;
96
- this . codeUnits = codeUnits ;
93
+ this . codeUnit = codeUnit ;
97
94
}
98
95
99
96
public void shiftSelf ( float shift ) {
@@ -190,7 +187,7 @@ public LineRange(int start, int end, int endExcludingWhitespace, int endIncludin
190
187
List < float > _lineWidths = new List < float > ( ) ;
191
188
// float[] _lineBaseLines;
192
189
GlyphLine [ ] _glyphLines ;
193
- GlyphPosition [ ] glyphPositions ;
190
+ GlyphPosition [ ] _glyphPositions ;
194
191
PaintRecord [ ] _paintRecords ;
195
192
CodeUnitRun [ ] _codeUnitRuns ;
196
193
float [ ] _lineHeights ;
@@ -326,11 +323,11 @@ public void layout(ParagraphConstraints constraints) {
326
323
}
327
324
builder . setPositions ( this . _textBlobPositions ) ;
328
325
// this._glyphLines and this._codeUnitRuns will refer to this array for glyph positions
329
- if ( this . glyphPositions == null || this . glyphPositions . Length < ellipsizedLength ) {
330
- this . glyphPositions = new GlyphPosition [ ellipsizedLength ] ;
326
+ if ( this . _glyphPositions == null || this . _glyphPositions . Length < ellipsizedLength ) {
327
+ this . _glyphPositions = new GlyphPosition [ ellipsizedLength ] ;
331
328
}
332
329
333
- // Pointer to the glyphPositions array, to keep track of where the next glyph is stored
330
+ // Pointer to the _glyphPositions array, to keep track of where the next glyph is stored
334
331
int pGlyphPositions = 0 ;
335
332
336
333
// Compute max(NumberOfWords(line) for line in lines), to determine the size of word buffers
@@ -381,7 +378,7 @@ public void layout(ParagraphConstraints constraints) {
381
378
_positionsBuffer = new float [ maxTextCount ] ;
382
379
}
383
380
384
- // Keep of the position in glyphPositions before evaluating this line
381
+ // Keep of the position in _glyphPositions before evaluating this line
385
382
int glyphPositionLineStart = pGlyphPositions ;
386
383
387
384
if ( lineStyleRunCount != 0 ) {
@@ -407,7 +404,7 @@ public void layout(ParagraphConstraints constraints) {
407
404
int textStart = start ;
408
405
int textEnd = end ;
409
406
int textCount = textEnd - textStart ;
410
- // Keep track of the pointer to glyphPositions in the start of this run
407
+ // Keep track of the pointer to _glyphPositions in the start of this run
411
408
int glyphPositionStyleRunStart = pGlyphPositions ;
412
409
413
410
// Ellipsize the text if ellipsis string is set, and this is the last lineStyleRun of
@@ -446,8 +443,8 @@ public void layout(ParagraphConstraints constraints) {
446
443
float glyphXOffset = _positionsBuffer [ glyphIndex ] + justifyXOffset ;
447
444
float glyphAdvance = _advancesBuffer [ glyphIndex ] ;
448
445
builder . setPosition ( glyphIndex , glyphXOffset ) ;
449
- this . glyphPositions [ pGlyphPositions ++ ] = new GlyphPosition ( runXOffset + glyphXOffset ,
450
- glyphAdvance , new Range < int > ( textStart + glyphIndex , textStart + glyphIndex + 1 ) ) ;
446
+ this . _glyphPositions [ pGlyphPositions ++ ] = new GlyphPosition ( runXOffset + glyphXOffset ,
447
+ glyphAdvance , textStart + glyphIndex ) ;
451
448
if ( wordIndex < wordCount ) {
452
449
Range < int > word = _wordsBuffer [ wordIndex ] ;
453
450
// Run into the start of current word, record the start position of this word
@@ -467,7 +464,7 @@ public void layout(ParagraphConstraints constraints) {
467
464
// width of this word, and update the entire word
468
465
if ( ! float . IsNaN ( wordStartPosition ) ) {
469
466
maxWordWidth = Mathf . Max ( maxWordWidth ,
470
- this . glyphPositions [ pGlyphPositions - 1 ] . xPos . end - wordStartPosition ) ;
467
+ this . _glyphPositions [ pGlyphPositions - 1 ] . xPos . end - wordStartPosition ) ;
471
468
wordStartPosition = float . NaN ;
472
469
}
473
470
}
@@ -485,9 +482,8 @@ public void layout(ParagraphConstraints constraints) {
485
482
486
483
// Create code unit run
487
484
this . _codeUnitRuns [ this . _codeUnitRunsCount ++ ] = new CodeUnitRun (
488
- this . glyphPositions ,
489
485
new Range < int > ( start , end ) ,
490
- new Range < float > ( this . glyphPositions [ 0 ] . xPos . start , this . glyphPositions . last ( ) . xPos . end ) ,
486
+ new Range < float > ( this . _glyphPositions [ 0 ] . xPos . start , this . _glyphPositions . last ( ) . xPos . end ) ,
491
487
lineNumber , TextDirection . ltr , glyphPositionStyleRunStart , textCount ) ;
492
488
493
489
lineStyleRunIndex ++ ;
@@ -544,9 +540,9 @@ void updateLineMetrics(FontMetrics metrics, float styleHeight) {
544
540
preMaxDescent = maxDescent ;
545
541
float lineXOffset = this . getLineXOffset ( runXOffset ) ;
546
542
int count = pGlyphPositions - glyphPositionLineStart ;
547
- if ( lineXOffset != 0 && this . glyphPositions != null ) {
543
+ if ( lineXOffset != 0 && this . _glyphPositions != null ) {
548
544
for ( int i = 0 ; i < count ; ++ i ) {
549
- this . glyphPositions [ this . glyphPositions . Length - i - 1 ] . shiftSelf ( lineXOffset ) ;
545
+ this . _glyphPositions [ this . _glyphPositions . Length - i - 1 ] . shiftSelf ( lineXOffset ) ;
550
546
}
551
547
}
552
548
@@ -555,7 +551,7 @@ void updateLineMetrics(FontMetrics metrics, float styleHeight) {
555
551
? this . _lineRanges [ lineNumber + 1 ] . start
556
552
: this . _text . Length ;
557
553
this . _glyphLines [ lineNumber ] =
558
- new GlyphLine ( this . glyphPositions , glyphPositionLineStart , count , nextLineStart - lineStart ) ;
554
+ new GlyphLine ( this . _glyphPositions , glyphPositionLineStart , count , nextLineStart - lineStart ) ;
559
555
for ( int i = 0 ; i < lineStyleRunCount ; i ++ ) {
560
556
var paintRecord = this . _paintRecords [ this . _paintRecordsCount - 1 - i ] ;
561
557
paintRecord . shift ( lineXOffset , yOffset ) ;
@@ -646,8 +642,8 @@ public List<TextBox> getRectsForRange(int start, int end) {
646
642
left = float . MaxValue ;
647
643
right = float . MinValue ;
648
644
for ( int i = 0 ; i < run . count ; i ++ ) {
649
- var gp = run . get ( i ) ;
650
- if ( gp . codeUnits . start >= start && gp . codeUnits . end <= end ) {
645
+ var gp = run . get ( i , this . _glyphPositions ) ;
646
+ if ( gp . codeUnit >= start && gp . codeUnit + 1 <= end ) {
651
647
left = Mathf . Min ( left , gp . xPos . start ) ;
652
648
right = Mathf . Max ( right , gp . xPos . end ) ;
653
649
}
@@ -746,12 +742,12 @@ internal PositionWithAffinity getGlyphPositionAtCoordinate(float dx, float dy) {
746
742
747
743
if ( ! gpSet ) {
748
744
GlyphPosition lastGlyph = glyphLine . last ( ) ;
749
- return new PositionWithAffinity ( lastGlyph . codeUnits . end , TextAffinity . upstream ) ;
745
+ return new PositionWithAffinity ( lastGlyph . codeUnit + 1 , TextAffinity . upstream ) ;
750
746
}
751
747
752
748
TextDirection direction = TextDirection . ltr ;
753
749
foreach ( var run in this . _codeUnitRuns ) {
754
- if ( gp . codeUnits . start >= run . codeUnits . start && gp . codeUnits . end <= run . codeUnits . end ) {
750
+ if ( gp . codeUnit >= run . codeUnits . start && gp . codeUnit + 1 <= run . codeUnits . end ) {
755
751
direction = run . direction ;
756
752
break ;
757
753
}
@@ -760,10 +756,10 @@ internal PositionWithAffinity getGlyphPositionAtCoordinate(float dx, float dy) {
760
756
float glyphCenter = ( gp . xPos . start + gp . xPos . end ) / 2 ;
761
757
if ( ( direction == TextDirection . ltr && dx < glyphCenter ) ||
762
758
( direction == TextDirection . rtl && dx >= glyphCenter ) ) {
763
- return new PositionWithAffinity ( gp . codeUnits . start , TextAffinity . downstream ) ;
759
+ return new PositionWithAffinity ( gp . codeUnit , TextAffinity . downstream ) ;
764
760
}
765
761
766
- return new PositionWithAffinity ( gp . codeUnits . end , TextAffinity . upstream ) ;
762
+ return new PositionWithAffinity ( gp . codeUnit + 1 , TextAffinity . upstream ) ;
767
763
}
768
764
769
765
public int getLine ( TextPosition position ) {
0 commit comments