On Sat, 10 Feb 2024 17:24:17 GMT, John Hendrikx <jhendr...@openjdk.org> wrote:

>> There are a number of tickets open related to text rendering:
>> 
>> https://bugs.openjdk.org/browse/JDK-8314215
>> 
>> https://bugs.openjdk.org/browse/JDK-8145496
>> 
>> https://bugs.openjdk.org/browse/JDK-8129014
>> 
>> They have in common that wrapped text is taking the trailing spaces on each 
>> wrapped line into account when calculating where to wrap.  This looks okay 
>> for text that is left aligned (as the spaces will be trailing the lines and 
>> generally aren't a problem, but looks weird with CENTER and RIGHT 
>> alignments.  Even with LEFT alignment there are artifacts of this behavior, 
>> where a line like `AAA  BBB  CCC` (note the **double** spaces) gets split up 
>> into `AAA  `, `BBB  ` and `CCC`, but if space reduces further, it will wrap 
>> **too** early because the space is taken into account (ie. `AAA` may still 
>> have fit just fine, but `AAA  ` doesn't, so the engine wraps it to `AA` + `A 
>>  ` or something).
>> 
>> The fix for this is two fold; first the individual lines of text should not 
>> include any trailing spaces into their widths; second, the code that is 
>> taking the trailing space into account when wrapping should ignore all 
>> trailing spaces (currently it is ignoring all but one trailing space).  With 
>> these two fixes, the layout in LEFT/CENTER/RIGHT alignments all look great, 
>> and there is no more early wrapping due to a space being taking into account 
>> while the actual text still would have fit (this is annoying in tight 
>> layouts, where a line can be wrapped early even though it looks like it 
>> would have fit).
>> 
>> If it were that simple, we'd be done, but there may be another issue here 
>> that needs solving: wrapped aligned TextArea's.
>> 
>> TextArea don't directly support text alignment (via a setTextAlignment 
>> method like Label) but you can change it via CSS.
>> 
>> For Left alignment + wrapping, TextArea will ignore any spaces typed before 
>> a line that was wrapped.  In other words, you can type spaces as much as you 
>> want, and they won't show up and the cursor won't move.  The spaces are all 
>> getting appended to the previous line.  When you cursor through these 
>> spaces, the cursor can be rendered out of the control's bounds.  To 
>> illustrate, if you have the text `AAA                 BBB CCC`, and the text 
>> gets wrapped to `AAA`, `BBB`, `CCC`, typing spaces before `BBB` will not 
>> show up.  If you cursor back, the cursor may be outside the control bounds 
>> because so many spaces are trailing `AAA`.
>> 
>> The above behavior has NOT changed, is pretty standard for wrapped text 
>> controls,...
>
> John Hendrikx has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Change test to use the more common Arial font and add assumptions

I ran the tests in my Mac system with macOS 14.3 and found 2 tests are failing 
with following error:


TextLayoutTest > caseTest(Case) > 
test.com.sun.javafx.text.TextLayoutTest.caseTest(Case)[10] FAILED
    org.opentest4j.AssertionFailedError: left aligned rich text (spans): line 0 
for Parameters[text=The quick brown लोमड़ी jumps over the lazy कुत्ता, 
wrapWidth=160.0, lineWidths=[158.1914, 93.134766]] ==> expected: <RectBounds { 
minX:0.0, minY:-10.863281, maxX:158.1914, maxY:2.9355469} (w:158.1914, 
h:13.798828)> but was: <RectBounds { minX:0.0, minY:-10.863281, maxX:155.3047, 
maxY:2.9355469} (w:155.3047, h:13.798828)>
        at 
app//org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:55)
        at 
app//org.junit.jupiter.api.AssertionUtils.failNotEqual(AssertionUtils.java:62)
        at 
app//org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182)
        at 
app//org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1152)
        at 
app//test.com.sun.javafx.text.TextLayoutTest.caseTest(TextLayoutTest.java:501)

TextLayoutTest > caseTest(Case) > 
test.com.sun.javafx.text.TextLayoutTest.caseTest(Case)[11] FAILED
    org.opentest4j.AssertionFailedError: left aligned rich text (spans): line 0 
for Parameters[text=The quick brown लोमड़ी jumps           over the lazy 
कुत्ता, wrapWidth=160.0, lineWidths=[158.1914, 93.134766]] ==> expected: 
<RectBounds { minX:0.0, minY:-10.863281, maxX:158.1914, maxY:2.9355469} 
(w:158.1914, h:13.798828)> but was: <RectBounds { minX:0.0, minY:-10.863281, 
maxX:155.3047, maxY:2.9355469} (w:155.3047, h:13.798828)>
        at 
app//org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:55)
        at 
app//org.junit.jupiter.api.AssertionUtils.failNotEqual(AssertionUtils.java:62)
        at 
app//org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182)
        at 
app//org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1152)
        at 
app//test.com.sun.javafx.text.TextLayoutTest.caseTest(TextLayoutTest.java:501)

TextLayoutTest > fixedComplexTestsToEnsureNoFurtherRegressions() SKIPPED

TextLayoutTest > complexTestsThatAreBrokenSince2013() SKIPPED


The failing tests are SOFT_WRAP_WITH_COMPLEX_TEXT and 
SOFT_WRAP_WITH_COMPLEX_TEXT_AND_EXTRA_SPACE.

Added a minor comment inline as well.

modules/javafx.graphics/src/main/java/com/sun/javafx/text/PrismTextLayout.java 
line 1228:

> 1226:      *
> 1227:      * Text effects have no effect on the alignment, and so with 
> underlining on
> 1228:      * the right right aligned text would look like:

Minor: "right" is repeated

-------------

PR Review: https://git.openjdk.org/jfx/pull/1236#pullrequestreview-1874624074
PR Review Comment: https://git.openjdk.org/jfx/pull/1236#discussion_r1485798441

Reply via email to