RFR: 8341670: [Text, TextFlow] Public API for Text Layout Info [v5]
Andy Goryachev
angorya at openjdk.org
Thu Oct 10 19:26:22 UTC 2024
On Wed, 9 Oct 2024 22:41:29 GMT, Andy Goryachev <angorya at openjdk.org> wrote:
>> 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 immutable `LayoutInfo` structure contains information about:
>>
>> - text lines: offsets and bounds
>> - overall layout bounds
>>
>> TBD:
>>
>> the platform can also report additional information such as:
>>
>> - individual text lines' left and right side bearings (what are those?)
>> - text runs within each line
>
> Andy Goryachev has updated the pull request incrementally with one additional commit since the last revision:
>
> convert to wrapper
One additional thought/question:
There is a need to extract a few more data points from the text layout in addition to the text lines, specifically:
- bounds of the (selection) range, as rectangles
- strikethrough range shape (as `PathElement[]` and/or rectangles)
- underline range shape (as `PathElement[]` and/or rectangles)
We currently have `Text/TextFlow.underlineShape(int,int)`, `.rangeShape(int,int)` which return `PathElement[]` in an undocumented way.
There is no corresponding `.strikeThroughShape()` method, or a way to retrieve the geometric bounds as lines/rectangles.
Granted, one can attempt to analyze the `PathElement[]` and convert it to geometry, but it seems we should avoid asking the clients to do that.
So the question are:
- should we add these data points to LayoutInfo
- if so, in what form? i.e. as individual methods or as an array of Line/Rectangle objects,
- should we add the `.strikeThroughShape()` to Text/TextFlow, or simply adding it here should be sufficient?
-------------
PR Comment: https://git.openjdk.org/jfx/pull/1596#issuecomment-2405873364
More information about the openjfx-dev
mailing list