RFR: 8339974: Graphics2D.drawString doesn't always work with Font derived from AffineTransform [v2]

Phil Race prr at openjdk.org
Fri Oct 4 21:14:35 UTC 2024


On Fri, 13 Sep 2024 14:41:48 GMT, Daniel Gredler <duke at openjdk.org> wrote:

>> There is a bug in `TextLayout.getOutline(AffineTransform)`, where the transformation is applied too early (before the layout path applies its mapping). The most obvious error caused by this bug is that `Graphics2D.drawString(...)` fails to draw the string when using a rotated + scaled `AffineTransform` (see minimal test case in the bug report).
>> 
>> There are two uses of `TextLayout.getOutline(AffineTransform)`: the first one, triggered via a simple `Graphics2D.drawString(...)` was the one I ran into; the second one requires the use of a transformed font with a `PSPrinterJob`. Both are broken. This PR includes two test classes verifying that both scenarios were broken before the fix and are working after the fix.
>> 
>> Two points which might require some discussion:
>> 1. I've changed the signature of method `TextLine.getOutline(AffineTransform)`, to just `TextLine.getOutline()`; I'm assuming this is OK since `TextLine` is a package-private class.
>> 2. I've added a fast path in `TextLayout.getOutline(AffineTransform)` to transform the shape in place if it is a `GeneralPath` (it should usually be, and avoids an extra `Shape` copy vs. the current code, which makes no copy). A bit more complex, but efficient.
>
> Daniel Gredler has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Add bug ID and summary to test classes

I've run it through all our automated testing and it looks OK - by which I mean the existing tests all pass.
I would still like to do some manual testing because as you can tell from the gyrations you had to do
in order to write these tests, visual verification is more certain with many transform related bugs.

Of the 3 times I ran it I had one failure on one platform - Windows Server 2016
java.lang.RuntimeException: No x-edge at center: scale=1, quadrants=2
	at RotatedScaledFontTest.test(RotatedScaledFontTest.java:74)
	at RotatedScaledFontTest.main(RotatedScaledFontTest.java:39)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
	at java.base/java.lang.reflect.Method.invoke(Method.java:573)
	at com.sun.javatest.regtest.agent.MainWrapper$MainTask.run(MainWrapper.java:138)
	at java.base/java.lang.Thread.run(Thread.java:1576)

I would have expected complete consistency but perhaps that older system uses an older version of
the Arial font and it just tripped over your "roughlyEqual" threshold ?
I'm not sure I believe that though .. so a bit of an odd one.

Perhaps you can add some extra tolerance and print out the values that caused the failure

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

PR Comment: https://git.openjdk.org/jdk/pull/20993#issuecomment-2394653911


More information about the client-libs-dev mailing list