RFR: 8341670: [Text, TextFlow] Public API for Text Layout Info [v11]
Andy Goryachev
angorya at openjdk.org
Fri Nov 22 21:48:23 UTC 2024
On Fri, 22 Nov 2024 16:19:50 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 24
>> */
>> 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
>>
>>
>> This PR also adds the missing `strikeThroughShape()` method to complement the existing `underlineShape()` and `rangeShape()` for consistency sake:
>>
>>
>> /**
>> * Returns the shape for the strike-through in local coordinates.
>> *
>> * @param start the beginning character index for the range
>> * @param end the end character index (non-inclusive) for the range
>> * @return an array of {@code PathElement} which can be used to create a {@code Shape}
>> * @since 24
>> */
>> public final PathElement[] strikeThroughShape(int start, int end)
>>
>>
>> ## Discussion Points
>>
>> - it is unclear whether CaretInfo.getPartAt() should return a simple Rectangle2D or a more complex object similar to TextLineInfo, to be able to add more information, such as the nature of text, text direction, etc.
>>
>>
>> ## WARNING
>>
>> 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) ).
>>
>>
>>
>> ## 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:
>> ![Screenshot 2024-11-04 at 11 38 21](https://github.com/user-attachments/assets/2e17e55c...
>
> Andy Goryachev has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 34 additional commits since the last revision:
>
> - segments
> - Merge remote-tracking branch 'origin/master' into ag.text.layout.api
> - Merge remote-tracking branch 'origin/master' into ag.text.layout.api
> - coordinates
> - note
> - text layout test
> - text flow test
> - shorter array
> - line spacing
> - Merge remote-tracking branch 'origin/master' into ag.text.layout.api
> - ... and 24 more: https://git.openjdk.org/jfx/compare/8302d1b2...944bd0d3
@prrace please take a look
-------------
PR Comment: https://git.openjdk.org/jfx/pull/1596#issuecomment-2494915484
More information about the openjfx-dev
mailing list