RFR: 8341670: [Text, TextFlow] Public API for Text Layout Info [v32]
Kevin Rushforth
kcr at openjdk.org
Tue Jun 10 18:20:43 UTC 2025
On Thu, 5 Jun 2025 21:42:46 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 with a new target base due to a merge or a rebase. The pull request now contains 63 commits:
>
> - review comments
> - Merge remote-tracking branch 'origin/master' into ag.text.layout.api
> - cleanup
> - Merge remote-tracking branch 'origin/master' into ag.text.layout.api
> - Merge remote-tracking branch 'origin/master' into ag.text.layout.api
> - cleanup
> - removed getStrikeThroughShape
> - caret geometry
> - review comments
> - Merge remote-tracking branch 'origin/master' into ag.text.layout.api
> - ... and 53 more: https://git.openjdk.org/jfx/compare/11f31146...d0f56fee
I ran the tests included with this fix on my macOS 14 system and see 3 failures:
$ gradle --continue --info -PTEST_ONLY=true -PFULL_TEST=true -PUSE_ROBOT=true :systemTests:test --tests TextFlow_TextLayout_Test --tests Text_TextLayout_Test
Text_TextLayout_Test > testSelection() FAILED
org.opentest4j.AssertionFailedError: expected: <0.0> but was: <-23.203125>
at app//org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
at app//org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
at app//org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
at app//org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:86)
at app//org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:81)
at app//org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1014)
at app//test.robot.javafx.scene.Text_TextLayout_Test.testSelection(Text_TextLayout_Test.java:205)
Text_TextLayout_Test > testTextLines() FAILED
org.opentest4j.AssertionFailedError: expected: <0.0> but was: <-23.203125>
at app//org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
at app//org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
at app//org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
at app//org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:86)
at app//org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:81)
at app//org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1014)
at app//test.robot.javafx.scene.Text_TextLayout_Test.testTextLines(Text_TextLayout_Test.java:155)
Text_TextLayout_Test > testCaretInfo() FAILED
org.opentest4j.AssertionFailedError: expected: <true> but was: <false>
at app//org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
at app//org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
at app//org.junit.jupiter.api.AssertTrue.failNotTrue(AssertTrue.java:63)
at app//org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:36)
at app//org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:31)
at app//org.junit.jupiter.api.Assertions.assertTrue(Assertions.java:183)
at app//test.robot.javafx.scene.Text_TextLayout_Test.testCaretInfo(Text_TextLayout_Test.java:87)
-------------
PR Comment: https://git.openjdk.org/jfx/pull/1596#issuecomment-2960211988
More information about the openjfx-dev
mailing list