@@ -21,7 +21,7 @@ class TextFlowExt extends TextFlow {
2121 /*
2222 * Rename to getLayoutInfo() and delete once JavaFX
2323 * [PR1596](https://github.com/openjdk/jfx/pull/1596)
24- * is integrated and released. Also delete
24+ * is integrated and released. Also delete
2525 * TextFlowLayout and TextFlowSpan.
2626 */
2727 private TextFlowLayout textLayout ()
@@ -37,17 +37,20 @@ int getLineCount() {
3737 }
3838
3939 int getLineStartPosition (int charIdx ) {
40- return textLayout ().getTextLineStart ( getLineOfCharacter (charIdx ) );
40+ return textLayout ().getTextLine ( getLineOfCharacter (charIdx ) ). getStart ( );
4141 }
4242
4343 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 ;
4548 }
4649
4750 int getLineOfCharacter (int charIdx ) {
4851 var layout = textLayout ();
4952 return IntStream .range ( 0 , getLineCount () )
50- .filter ( l -> charIdx <= layout .getTextLineEnd ( l ) )
53+ .filter ( l -> charIdx < layout .getTextLine ( l ). getEnd ( ) )
5154 .findFirst ().orElse ( Math .max (0 ,getLineCount ()-1 ) );
5255 }
5356
@@ -151,22 +154,22 @@ PathElement[] getUnderlineShape(int from, int to, double offset, double waveRadi
151154 }
152155
153156 CharacterHit hitLine (double x , int lineIndex ) {
154- Rectangle2D r = textLayout ().getLineBounds ( lineIndex );
157+ Rectangle2D r = textLayout ().getTextLine ( lineIndex ). getBounds ( );
155158 double y = r .getMinY () + r .getHeight () / 2.0 ;
156159 return hit ( x , y , lineIndex );
157160 }
158161
159162 CharacterHit hit (double x , double y ) {
160163 var layout = textLayout ();
161164 int line = IntStream .range ( 0 , getLineCount () )
162- .filter ( l -> y < layout .getLineBounds ( l ).getMaxY () )
165+ .filter ( l -> y < layout .getTextLine ( l ). getBounds ( ).getMaxY () )
163166 .findFirst ().orElse ( Math .max (0 ,getLineCount ()-1 ) );
164167 return hit ( x , y , line );
165168 }
166169
167170 CharacterHit hit (double x , double y , int line ) {
168171
169- Rectangle2D lineBounds = textLayout ().getLineBounds ( line );
172+ Rectangle2D lineBounds = textLayout ().getTextLine ( line ). getBounds ( );
170173 HitInfo hit = hitTest (new Point2D (x , y ));
171174 int charIdx = hit .getCharIndex ();
172175 boolean leading = hit .isLeading ();
@@ -178,7 +181,7 @@ CharacterHit hit(double x, double y, int line) {
178181 if ( ! leading && getLineCount () > 1 ) {
179182 // If this is a wrapped paragraph and hit character is at end of hit line, make sure that the
180183 // "character hit" stays at the end of the hit line (and not at the beginning of the next line).
181- leading = (getLineOfCharacter (charIdx ) + 1 < getLineCount () && charIdx + 1 >= textLayout ().getTextLineEnd ( line ));
184+ leading = (getLineOfCharacter (charIdx ) + 1 < getLineCount () && charIdx + 1 >= textLayout ().getTextLine ( line ). getEnd ( ));
182185 }
183186
184187 if (x < lineBounds .getMinX () || x > lineBounds .getMaxX ()) {
0 commit comments