@@ -193,11 +193,15 @@ private void checkOrientation() {
193193
194194 /**
195195 * Maps local point to {@link HitInfo} in the content.
196+ * <p>
197+ * NOTE: this method does not take border or padding into account.
196198 *
197199 * @param point the specified point to be tested
198200 * @return a {@code HitInfo} representing the character index found
199201 * @since 9
202+ * @deprecated replaced by {@link #getHitInfo(javafx.geometry.Point2D)}
200203 */
204+ @ Deprecated (since ="25" )
201205 public final HitInfo hitTest (javafx .geometry .Point2D point ) {
202206 if (point != null ) {
203207 TextLayout layout = getTextLayout ();
@@ -210,42 +214,132 @@ public final HitInfo hitTest(javafx.geometry.Point2D point) {
210214 }
211215 }
212216
217+ /**
218+ * Maps local point to {@link HitInfo} in the content.
219+ *
220+ * @param point the specified point to be tested
221+ * @return a {@code HitInfo} representing the character index found
222+ * @since 25
223+ */
224+ public final HitInfo getHitInfo (javafx .geometry .Point2D point ) {
225+ if (point != null ) {
226+ TextLayout layout = getTextLayout ();
227+ double x = point .getX () - snappedLeftInset ();
228+ double y = point .getY () - snappedTopInset ();
229+ TextLayout .Hit h = layout .getHitInfo ((float )x , (float )y );
230+ return new HitInfo (h .getCharIndex (), h .getInsertionIndex (), h .isLeading ());
231+ } else {
232+ return null ;
233+ }
234+ }
235+
213236 /**
214237 * Returns shape of caret in local coordinates.
238+ * <p>
239+ * NOTE: this method does not take border or padding into account.
215240 *
216241 * @param charIndex the character index for the caret
217242 * @param leading whether the caret is biased on the leading edge of the character
218243 * @return an array of {@code PathElement} which can be used to create a {@code Shape}
219244 * @since 9
245+ * @deprecated replaced by {@link #getCaretShape(int, boolean)}
220246 */
247+ @ Deprecated (since ="25" )
221248 public PathElement [] caretShape (int charIndex , boolean leading ) {
222249 TextLayout .CaretGeometry g = getTextLayout ().getCaretGeometry (charIndex , leading );
223- // TODO padding JDK-8341438?
224250 return TextUtils .getCaretPathElements (g , 0.0 , 0.0 );
225251 }
226252
253+ /**
254+ * Returns shape of caret in local coordinates.
255+ *
256+ * @param charIndex the character index for the caret
257+ * @param leading whether the caret is biased on the leading edge of the character
258+ * @return an array of {@code PathElement} which can be used to create a {@code Shape}
259+ * @since 25
260+ */
261+ public PathElement [] getCaretShape (int charIndex , boolean leading ) {
262+ TextLayout .CaretGeometry g = getTextLayout ().getCaretGeometry (charIndex , leading );
263+ double dx = snappedLeftInset ();
264+ double dy = snappedTopInset ();
265+ return TextUtils .getCaretPathElements (g , dx , dy );
266+ }
267+
227268 /**
228269 * Returns shape for the range of the text in local coordinates.
270+ * <p>
271+ * NOTES:
272+ * <ul>
273+ * <li>this method does not take border or padding into account
274+ * <li>the shapes returned do not include line spacing
275+ * </ul>
229276 *
230277 * @param start the beginning character index for the range
231278 * @param end the end character index (non-inclusive) for the range
232279 * @return an array of {@code PathElement} which can be used to create a {@code Shape}
233280 * @since 9
281+ * @deprecated replaced by {@link #getRangeShape(int, int, boolean)}
234282 */
283+ @ Deprecated (since ="25" )
235284 public final PathElement [] rangeShape (int start , int end ) {
236- return getRange (start , end , TextLayout .TYPE_TEXT );
285+ return getRange (start , end , TextLayout .TYPE_TEXT , false , 0.0 );
286+ }
287+
288+ /**
289+ * Returns shape for the range of the text in local coordinates.
290+ *
291+ * @param start the beginning character index for the range
292+ * @param end the end character index (non-inclusive) for the range
293+ * @param includeLineSpacing determines whether the result includes the line spacing
294+ * @return an array of {@code PathElement} which can be used to create a {@code Shape}
295+ * @since 25
296+ * @see LayoutInfo#getSelectionGeometry(int, int, boolean)
297+ */
298+ public final PathElement [] getRangeShape (int start , int end , boolean includeLineSpacing ) {
299+ double lineSpacing = includeLineSpacing ? getLineSpacing () : 0.0 ;
300+ return getRange (start , end , TextLayout .TYPE_TEXT , true , lineSpacing );
237301 }
238302
239303 /**
240304 * Returns the shape for the underline in local coordinates.
305+ * <p>
306+ * NOTE: this method does not take border or padding into account.
241307 *
242308 * @param start the beginning character index for the range
243309 * @param end the end character index (non-inclusive) for the range
244310 * @return an array of {@code PathElement} which can be used to create a {@code Shape}
245311 * @since 21
312+ * @deprecated replaced by {@link #getUnderlineShape(int, int)}
246313 */
314+ @ Deprecated (since ="25" )
247315 public final PathElement [] underlineShape (int start , int end ) {
248- return getRange (start , end , TextLayout .TYPE_UNDERLINE );
316+ return getRange (start , end , TextLayout .TYPE_UNDERLINE , false , 0.0 );
317+ }
318+
319+ /**
320+ * Returns the shape for the underline in local coordinates.
321+ *
322+ * @param start the beginning character index for the range
323+ * @param end the end character index (non-inclusive) for the range
324+ * @return an array of {@code PathElement} which can be used to create a {@code Shape}
325+ * @since 25
326+ * @see LayoutInfo#getUnderlineGeometry(int, int)
327+ */
328+ public final PathElement [] getUnderlineShape (int start , int end ) {
329+ return getRange (start , end , TextLayout .TYPE_UNDERLINE , true , 0.0 );
330+ }
331+
332+ /**
333+ * Returns the shape for the strike-through in local coordinates.
334+ *
335+ * @param start the beginning character index for the range
336+ * @param end the end character index (non-inclusive) for the range
337+ * @return an array of {@code PathElement} which can be used to create a {@code Shape}
338+ * @since 25
339+ * @see LayoutInfo#getStrikeThroughGeometry(int, int)
340+ */
341+ public final PathElement [] getStrikeThroughShape (int start , int end ) {
342+ return getRange (start , end , TextLayout .TYPE_STRIKETHROUGH , true , 0.0 );
249343 }
250344
251345 @ Override
@@ -368,9 +462,18 @@ public boolean usesMirroring() {
368462 inLayout = false ;
369463 }
370464
371- private PathElement [] getRange (int start , int end , int type ) {
465+ private PathElement [] getRange (int start , int end , int type , boolean accountForInsets , double lineSpacing ) {
466+ double dx ;
467+ double dy ;
468+ if (accountForInsets ) {
469+ dx = snappedLeftInset ();
470+ dy = snappedTopInset ();
471+ } else {
472+ dx = 0.0 ;
473+ dy = 0.0 ;
474+ }
372475 TextLayout layout = getTextLayout ();
373- return TextUtils .getRange (layout , start , end , type , 0 , 0 );
476+ return TextUtils .getRange (layout , start , end , type , dx , dy , lineSpacing );
374477 }
375478
376479 private static class EmbeddedSpan implements TextSpan {
0 commit comments