Skip to content

Commit 593c27e

Browse files
committedOct 9, 2024
8341535: sun/awt/font/TestDevTransform.java fails with RuntimeException: Different rendering
Reviewed-by: mbaesken
1 parent 3180aaa commit 593c27e

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed
 

‎test/jdk/sun/awt/font/TestDevTransform.java

+25-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/*
2525
* @test
26-
* @bug 4269775
26+
* @bug 4269775 8341535
2727
* @summary Check that different text rendering APIs agree
2828
*/
2929

@@ -46,6 +46,8 @@
4646
import java.awt.font.TextLayout;
4747
import java.awt.geom.AffineTransform;
4848
import java.awt.image.BufferedImage;
49+
import javax.imageio.ImageIO;
50+
import java.io.File;
4951
import java.util.HashMap;
5052

5153
public class TestDevTransform {
@@ -105,17 +107,34 @@ static void init(Graphics2D g2d) {
105107
g2d.setFont(font);
106108
}
107109

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();
109115
for (int x = 0; x < bi1.getWidth(); x++) {
110116
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++; }
111121
if (bi1.getRGB(x, y) != bi2.getRGB(x, y)) {
112-
throw new RuntimeException("Different rendering");
122+
differences++;
113123
}
114124
}
115125
}
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+
}
116135
}
117136

118-
public static void main(String args[]) {
137+
public static void main(String args[]) throws Exception {
119138

120139
BufferedImage tl_Image = new BufferedImage(W, H, BufferedImage.TYPE_INT_RGB);
121140
{
@@ -149,7 +168,7 @@ public static void main(String args[]) {
149168
draw(gv_g2d, gv, 10f, 36f, .33f);
150169
}
151170

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");
154173
}
155174
}

0 commit comments

Comments
 (0)
Please sign in to comment.