Skip to content

Commit 027fdb2

Browse files
author
Laurent Bourgès
committed
8230728: Thin stroked shapes are not rendered if affine transform has flip bit
Use abs(at.getDeterminant()) in userSpaceLineWidth() to ensure positive value Reviewed-by: prr, jdv
1 parent 17c2843 commit 027fdb2

File tree

4 files changed

+109
-3
lines changed

4 files changed

+109
-3
lines changed

src/java.desktop/share/classes/sun/java2d/marlin/DMarlinRenderingEngine.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ private double userSpaceLineWidth(AffineTransform at, double lw) {
246246
widthScale = 1.0d;
247247
} else if ((at.getType() & (AffineTransform.TYPE_GENERAL_TRANSFORM |
248248
AffineTransform.TYPE_GENERAL_SCALE)) != 0) {
249-
widthScale = Math.sqrt(at.getDeterminant());
249+
// Determinant may be negative (flip), use its absolute value:
250+
widthScale = Math.sqrt(Math.abs(at.getDeterminant()));
250251
} else {
251252
// First calculate the "maximum scale" of this transform.
252253
double A = at.getScaleX(); // m00

src/java.desktop/share/classes/sun/java2d/marlin/MarlinRenderingEngine.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ private float userSpaceLineWidth(AffineTransform at, float lw) {
245245
widthScale = 1.0f;
246246
} else if ((at.getType() & (AffineTransform.TYPE_GENERAL_TRANSFORM |
247247
AffineTransform.TYPE_GENERAL_SCALE)) != 0) {
248-
widthScale = (float)Math.sqrt(at.getDeterminant());
248+
// Determinant may be negative (flip), use its absolute value:
249+
widthScale = (float)Math.sqrt(Math.abs(at.getDeterminant()));
249250
} else {
250251
// First calculate the "maximum scale" of this transform.
251252
double A = at.getScaleX(); // m00

src/java.desktop/share/classes/sun/java2d/marlin/Version.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
public final class Version {
2929

30-
private static final String VERSION = "marlin-0.9.1.2-Unsafe-OpenJDK";
30+
private static final String VERSION = "marlin-0.9.1.3-Unsafe-OpenJDK";
3131

3232
public static String getVersion() {
3333
return VERSION;
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
25+
import java.awt.BasicStroke;
26+
import java.awt.Color;
27+
import java.awt.Graphics2D;
28+
import java.awt.Rectangle;
29+
import java.awt.RenderingHints;
30+
import java.awt.geom.AffineTransform;
31+
import java.awt.geom.Ellipse2D;
32+
import java.awt.image.BufferedImage;
33+
import java.io.File;
34+
import java.io.IOException;
35+
import javax.imageio.ImageIO;
36+
37+
38+
/**
39+
* Tests calculating user space line with a negative determinant (flip).
40+
*
41+
* @test
42+
* @summary verify that flipped transformed lines are properly rasterized
43+
* @bug 8230728
44+
*/
45+
public class FlipBitTest {
46+
47+
static final boolean SAVE_IMAGE = false;
48+
49+
public static void main(final String[] args) {
50+
51+
final int size = 100;
52+
53+
// First display which renderer is tested:
54+
// JDK9 only:
55+
System.setProperty("sun.java2d.renderer.verbose", "true");
56+
57+
System.out.println("FlipBitTest: size = " + size);
58+
59+
final BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
60+
61+
final Graphics2D g2d = (Graphics2D) image.getGraphics();
62+
try {
63+
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
64+
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
65+
g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
66+
67+
final AffineTransform at = new AffineTransform();
68+
at.setToScale(1, -1.01);
69+
g2d.setTransform(at);
70+
71+
g2d.translate(0, -image.getHeight());
72+
g2d.setPaint(Color.WHITE);
73+
g2d.fill(new Rectangle(image.getWidth(), image.getHeight()));
74+
75+
g2d.setPaint(Color.BLACK);
76+
g2d.setStroke(new BasicStroke(0.1f));
77+
g2d.draw(new Ellipse2D.Double(25, 25, 50, 50));
78+
79+
if (SAVE_IMAGE) {
80+
try {
81+
final File file = new File("FlipBitTest.png");
82+
83+
System.out.println("Writing file: " + file.getAbsolutePath());
84+
ImageIO.write(image, "PNG", file);
85+
} catch (IOException ex) {
86+
ex.printStackTrace();
87+
}
88+
}
89+
90+
boolean nonWhitePixelFound = false;
91+
for (int x = 0; x < image.getWidth(); ++x) {
92+
if (image.getRGB(x, 50) != Color.WHITE.getRGB()) {
93+
nonWhitePixelFound = true;
94+
break;
95+
}
96+
}
97+
if (!nonWhitePixelFound) {
98+
throw new IllegalStateException("The ellipse was not drawn");
99+
}
100+
} finally {
101+
g2d.dispose();
102+
}
103+
}
104+
}

0 commit comments

Comments
 (0)