@@ -21,7 +21,7 @@ class TextFlowExt extends TextFlow {
21
21
/*
22
22
* Rename to getLayoutInfo() and delete once JavaFX
23
23
* [PR1596](https://github.com/openjdk/jfx/pull/1596)
24
- * is integrated and released. Also delete
24
+ * is integrated and released. Also delete
25
25
* TextFlowLayout and TextFlowSpan.
26
26
*/
27
27
private TextFlowLayout textLayout ()
@@ -37,17 +37,20 @@ int getLineCount() {
37
37
}
38
38
39
39
int getLineStartPosition (int charIdx ) {
40
- return textLayout ().getTextLineStart ( getLineOfCharacter (charIdx ) );
40
+ return textLayout ().getTextLine ( getLineOfCharacter (charIdx ) ). getStart ( );
41
41
}
42
42
43
43
int getLineEndPosition (int charIdx ) {
44
- return textLayout ().getTextLineEnd ( getLineOfCharacter (charIdx ) );
44
+ int line = getLineOfCharacter ( charIdx );
45
+ int end = textLayout ().getTextLine ( line ).getEnd ();
46
+ if ( line < (getLineCount () - 1 ) ) end --; // trailing space
47
+ return end ;
45
48
}
46
49
47
50
int getLineOfCharacter (int charIdx ) {
48
51
var layout = textLayout ();
49
52
return IntStream .range ( 0 , getLineCount () )
50
- .filter ( l -> charIdx <= layout .getTextLineEnd ( l ) )
53
+ .filter ( l -> charIdx < layout .getTextLine ( l ). getEnd ( ) )
51
54
.findFirst ().orElse ( Math .max (0 ,getLineCount ()-1 ) );
52
55
}
53
56
@@ -135,22 +138,22 @@ PathElement[] getUnderlineShape(int from, int to, double offset, double waveRadi
135
138
}
136
139
137
140
CharacterHit hitLine (double x , int lineIndex ) {
138
- Rectangle2D r = textLayout ().getLineBounds ( lineIndex );
141
+ Rectangle2D r = textLayout ().getTextLine ( lineIndex ). getBounds ( );
139
142
double y = r .getMinY () + r .getHeight () / 2.0 ;
140
143
return hit ( x , y , lineIndex );
141
144
}
142
145
143
146
CharacterHit hit (double x , double y ) {
144
147
var layout = textLayout ();
145
148
int line = IntStream .range ( 0 , getLineCount () )
146
- .filter ( l -> y < layout .getLineBounds ( l ).getMaxY () )
149
+ .filter ( l -> y < layout .getTextLine ( l ). getBounds ( ).getMaxY () )
147
150
.findFirst ().orElse ( Math .max (0 ,getLineCount ()-1 ) );
148
151
return hit ( x , y , line );
149
152
}
150
153
151
154
CharacterHit hit (double x , double y , int line ) {
152
155
153
- Rectangle2D lineBounds = textLayout ().getLineBounds ( line );
156
+ Rectangle2D lineBounds = textLayout ().getTextLine ( line ). getBounds ( );
154
157
HitInfo hit = hitTest (new Point2D (x , y ));
155
158
int charIdx = hit .getCharIndex ();
156
159
boolean leading = hit .isLeading ();
@@ -162,7 +165,7 @@ CharacterHit hit(double x, double y, int line) {
162
165
if ( ! leading && getLineCount () > 1 ) {
163
166
// If this is a wrapped paragraph and hit character is at end of hit line, make sure that the
164
167
// "character hit" stays at the end of the hit line (and not at the beginning of the next line).
165
- leading = (getLineOfCharacter (charIdx ) + 1 < getLineCount () && charIdx + 1 >= textLayout ().getTextLineEnd ( line ));
168
+ leading = (getLineOfCharacter (charIdx ) + 1 < getLineCount () && charIdx + 1 >= textLayout ().getTextLine ( line ). getEnd ( ));
166
169
}
167
170
168
171
if (x < lineBounds .getMinX () || x > lineBounds .getMaxX ()) {
0 commit comments