|
23 | 23 |
|
24 | 24 | /*
|
25 | 25 | * @test
|
26 |
| - * @bug 4269775 |
| 26 | + * @bug 4269775 8341535 |
27 | 27 | * @summary Check that different text rendering APIs agree
|
28 | 28 | */
|
29 | 29 |
|
|
46 | 46 | import java.awt.font.TextLayout;
|
47 | 47 | import java.awt.geom.AffineTransform;
|
48 | 48 | import java.awt.image.BufferedImage;
|
| 49 | +import javax.imageio.ImageIO; |
| 50 | +import java.io.File; |
49 | 51 | import java.util.HashMap;
|
50 | 52 |
|
51 | 53 | public class TestDevTransform {
|
@@ -105,17 +107,34 @@ static void init(Graphics2D g2d) {
|
105 | 107 | g2d.setFont(font);
|
106 | 108 | }
|
107 | 109 |
|
108 |
| - static void compare(BufferedImage bi1, BufferedImage bi2) { |
| 110 | + static void compare(BufferedImage bi1, String name1, BufferedImage bi2, String name2) throws Exception { |
| 111 | + int nonWhite1 = 0; |
| 112 | + int nonWhite2 = 0; |
| 113 | + int differences = 0; |
| 114 | + int whitePixel = Color.white.getRGB(); |
109 | 115 | for (int x = 0; x < bi1.getWidth(); x++) {
|
110 | 116 | for (int y = 0; y < bi1.getHeight(); y++) {
|
| 117 | + int pix1 = bi1.getRGB(x, y); |
| 118 | + int pix2 = bi2.getRGB(x, y); |
| 119 | + if (pix1 != whitePixel) { nonWhite1++; } |
| 120 | + if (pix2 != whitePixel) { nonWhite2++; } |
111 | 121 | if (bi1.getRGB(x, y) != bi2.getRGB(x, y)) {
|
112 |
| - throw new RuntimeException("Different rendering"); |
| 122 | + differences++; |
113 | 123 | }
|
114 | 124 | }
|
115 | 125 | }
|
| 126 | + int nonWhite = (nonWhite1 < nonWhite2) ? nonWhite1 : nonWhite2; |
| 127 | + if (differences > 0 && ((nonWhite / differences) < 20)) { |
| 128 | + ImageIO.write(bi1, "png", new File(name1 + ".png")); |
| 129 | + ImageIO.write(bi2, "png", new File(name2 + ".png")); |
| 130 | + System.err.println("nonWhite image 1 = " + nonWhite1); |
| 131 | + System.err.println("nonWhite image 2 = " + nonWhite2); |
| 132 | + System.err.println("Number of non-white differing pixels=" + differences); |
| 133 | + throw new RuntimeException("Different rendering: " + differences + " pixels differ."); |
| 134 | + } |
116 | 135 | }
|
117 | 136 |
|
118 |
| - public static void main(String args[]) { |
| 137 | + public static void main(String args[]) throws Exception { |
119 | 138 |
|
120 | 139 | BufferedImage tl_Image = new BufferedImage(W, H, BufferedImage.TYPE_INT_RGB);
|
121 | 140 | {
|
@@ -149,7 +168,7 @@ public static void main(String args[]) {
|
149 | 168 | draw(gv_g2d, gv, 10f, 36f, .33f);
|
150 | 169 | }
|
151 | 170 |
|
152 |
| - compare(tl_Image, st_Image); |
153 |
| - compare(gv_Image, st_Image); |
| 171 | + compare(tl_Image, "textlayout", st_Image, "string"); |
| 172 | + compare(gv_Image, "glyphvector", st_Image, "string"); |
154 | 173 | }
|
155 | 174 | }
|
0 commit comments