RFR: 8339974: Graphics2D.drawString doesn't always work with Font derived from AffineTransform [v4]
Andy Goryachev
angorya at openjdk.org
Mon Oct 7 21:43:56 UTC 2024
On Mon, 7 Oct 2024 21:29:55 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:
>
> Save image to disk if test fails
test/jdk/java/awt/font/FontScaling/RotatedScaledFontTest.java line 141:
> 139: }
> 140:
> 141: private static String saveImage(String name, BufferedImage image) {
is this a good idea to write files?
e.g. the CI system may not make the files accessible, the local FS might overflow, etc.
there is an idea to output base-64 encoded image to the stdout, see https://bugs.openjdk.org/browse/JDK-8328716
this way
- the images will be available as long as the log file is available
- zero dependency on local file system or its limitations
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/20993#discussion_r1790905684
More information about the client-libs-dev
mailing list