RFR: 8341670: [Text, TextFlow] Public API for Text Layout Info [v33]
Kevin Rushforth
kcr at openjdk.org
Wed Jun 11 18:39:47 UTC 2025
On Tue, 10 Jun 2025 18:49:20 GMT, Andy Goryachev <angorya at openjdk.org> wrote:
>> Please refer to
>>
>> https://github.com/andy-goryachev-oracle/Test/blob/main/doc/Text/LayoutInfo.md
>>
>> The RichTextArea control ([JDK-8301121](https://bugs.openjdk.org/browse/JDK-8301121)), or any custom control that needs non-trivial navigation within complex or wrapped text needs a public API to get information about text layout.
>>
>> This change fixes the missing functionality by adding a new public method to the `Text` and `TextFlow` classes.:
>>
>>
>> /**
>> * Obtains the snapshot of the current text layout information.
>> * @return the layout information
>> * @since 25
>> */
>> public final LayoutInfo getLayoutInfo()
>>
>>
>> The `LayoutInfo` provides a view into the text layout within `Text`/`TextFlow` nodes such as:
>>
>> - caret information
>> - text lines: offsets and bounds
>> - overall layout bounds
>> - text selection geometry
>> - strike-through geometry
>> - underline geometry
>>
>>
>>
>>
>> ## WARNINGS
>>
>> Presently, information obtained via certain Text/TextField methods is incorrect with non-zero padding and borders, see [JDK-8341438](https://bugs.openjdk.org/browse/JDK-8341438).
>>
>> This PR provides correct answers in the new API, leaving the behavior of the existing methods unchanged (there is a compatibility risk associated with trying to fix [JDK-8341438](https://bugs.openjdk.org/browse/JDK-8341438) ).
>>
>> Also, the RTL support is out of scope for this PR, due to multiple pre-existing conditions, see https://bugs.openjdk.org/browse/JDK-8343557
>>
>>
>> ## Testing
>>
>> The new APIs can be visually tested using the Monkey Tester on this branch:
>> https://github.com/andy-goryachev-oracle/MonkeyTest/tree/text.layout.api
>>
>> in the Text and TextFlow pages:
>> 
>>
>> Two very basic headful tests have been added.
>>
>>
>> ## See Also
>>
>> https://github.com/FXMisc/RichTextFX/pull/1246
>
> Andy Goryachev has updated the pull request incrementally with one additional commit since the last revision:
>
> text origin
The fix looks good. The tests look good, although I noted a few "assertEquals" in the test with expected and actual parameters reserved (meaning the error message would be confusing if they ever failed).
tests/system/src/test/java/test/robot/javafx/scene/TextFlow_TextLayout_Test.java line 81:
> 79:
> 80: // caret is one line
> 81: assertEquals(ci.getSegmentCount(), 1);
Expected and actual are reversed, here and a few others below (most are OK).
tests/system/src/test/java/test/robot/javafx/scene/TextFlow_TextLayout_Test.java line 136:
> 134: assertEquals(la.getTextLineCount(), 3);
> 135: List<TextLineInfo> ls = la.getTextLines(false);
> 136: assertNotNull(ls);
Minor: maybe check the following, too?
assertEquals(3, ls.size());
tests/system/src/test/java/test/robot/javafx/scene/Text_TextLayout_Test.java line 83:
> 81:
> 82: // caret is one line
> 83: assertEquals(ci.getSegmentCount(), 1);
Expected and actual are reversed, here and a few others below (most are OK).
-------------
PR Review: https://git.openjdk.org/jfx/pull/1596#pullrequestreview-2918282270
PR Review Comment: https://git.openjdk.org/jfx/pull/1596#discussion_r2140820285
PR Review Comment: https://git.openjdk.org/jfx/pull/1596#discussion_r2140823296
PR Review Comment: https://git.openjdk.org/jfx/pull/1596#discussion_r2140830505
More information about the openjfx-dev
mailing list