Skip to content

Commit 3acfa9e

Browse files
Daniel Gredleraivanov-jdk
authored andcommitted
8356966: java/awt/Graphics2D/DrawString/IgnoredWhitespaceTest.java fails on Linux after JDK-8350203
Reviewed-by: honkar, aivanov
1 parent 26cb016 commit 3acfa9e

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/java.desktop/share/classes/sun/font/Type1GlyphMapper.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public boolean canDisplay(char ch) {
7878
}
7979

8080
public int charToGlyph(char ch) {
81-
if (FontUtilities.isDefaultIgnorable(ch)) {
81+
if (FontUtilities.isDefaultIgnorable(ch) || isIgnorableWhitespace(ch)) {
8282
return INVISIBLE_GLYPH_ID;
8383
}
8484
try {
@@ -93,7 +93,7 @@ public int charToGlyph(int ch) {
9393
if (ch < 0 || ch > 0xffff) {
9494
return missingGlyph;
9595
} else {
96-
if (FontUtilities.isDefaultIgnorable(ch)) {
96+
if (FontUtilities.isDefaultIgnorable(ch) || isIgnorableWhitespace(ch)) {
9797
return INVISIBLE_GLYPH_ID;
9898
}
9999
try {
@@ -105,6 +105,13 @@ public int charToGlyph(int ch) {
105105
}
106106
}
107107

108+
// Matches behavior in e.g. CMap.getControlCodeGlyph(int, boolean)
109+
// and RasterPrinterJob.removeControlChars(String)
110+
// and CCharToGlyphMapper.isIgnorableWhitespace(int)
111+
private static boolean isIgnorableWhitespace(int code) {
112+
return code == 0x0009 || code == 0x000a || code == 0x000d;
113+
}
114+
108115
public void charsToGlyphs(int count, char[] unicodes, int[] glyphs) {
109116
/* The conversion into surrogates is misleading.
110117
* The Type1 glyph mapper only accepts 16 bit unsigned shorts.

test/jdk/java/awt/Graphics2D/DrawString/IgnoredWhitespaceTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/*
2525
* @test
26-
* @bug 8350203
26+
* @bug 8350203 8356966
2727
* @summary Confirm that a few special whitespace characters are ignored.
2828
*/
2929

@@ -93,36 +93,37 @@ private static void test(BufferedImage image, Graphics2D g2d, Font font, String
9393
g2d.setColor(Color.BLACK);
9494
g2d.drawString(text, x, y);
9595
Rectangle actual = findTextBoundingBox(image);
96-
assertEqual(expected, actual, text);
96+
assertEqual(expected, actual, text, font);
9797

9898
g2d.setColor(Color.WHITE);
9999
g2d.fillRect(0, 0, w, h);
100100
g2d.setColor(Color.BLACK);
101101
g2d.drawString(new AttributedString(text, Map.of(TextAttribute.FONT, font)).getIterator(), x, y);
102102
actual = findTextBoundingBox(image);
103-
assertEqual(expected, actual, text);
103+
assertEqual(expected, actual, text, font);
104104

105105
g2d.setColor(Color.WHITE);
106106
g2d.fillRect(0, 0, w, h);
107107
g2d.setColor(Color.BLACK);
108108
g2d.drawChars(text.toCharArray(), 0, text.length(), x, y);
109109
actual = findTextBoundingBox(image);
110-
assertEqual(expected, actual, text);
110+
assertEqual(expected, actual, text, font);
111111

112112
g2d.setColor(Color.WHITE);
113113
g2d.fillRect(0, 0, w, h);
114114
g2d.setColor(Color.BLACK);
115115
g2d.drawGlyphVector(font.createGlyphVector(frc, text), x, y);
116116
actual = findTextBoundingBox(image);
117-
assertEqual(expected, actual, text);
117+
assertEqual(expected, actual, text, font);
118118
}
119119

120-
private static void assertEqual(Rectangle r1, Rectangle r2, String text) {
120+
private static void assertEqual(Rectangle r1, Rectangle r2, String text, Font font) {
121121
if (!r1.equals(r2)) {
122122
String escaped = text.replace("\r", "\\r")
123123
.replace("\n", "\\n")
124124
.replace("\t", "\\t");
125-
String msg = String.format("for text '%s': %s != %s", escaped, r1.toString(), r2.toString());
125+
String msg = String.format("for text '%s' with font %s: %s != %s",
126+
escaped, font.toString(), r1.toString(), r2.toString());
126127
throw new RuntimeException(msg);
127128
}
128129
}

0 commit comments

Comments
 (0)