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