8356966: java/awt/Graphics2D/DrawString/IgnoredWhitespaceTest.java fails on Linux after JDK-8350203

Reviewed-by: honkar, aivanov
This commit is contained in:
Daniel Gredler 2025-05-19 11:28:54 +00:00 committed by Alexey Ivanov
parent 26cb016b75
commit 3acfa9e4e7
2 changed files with 17 additions and 9 deletions

View File

@ -78,7 +78,7 @@ public final class Type1GlyphMapper extends CharToGlyphMapper {
}
public int charToGlyph(char ch) {
if (FontUtilities.isDefaultIgnorable(ch)) {
if (FontUtilities.isDefaultIgnorable(ch) || isIgnorableWhitespace(ch)) {
return INVISIBLE_GLYPH_ID;
}
try {
@ -93,7 +93,7 @@ public final class Type1GlyphMapper extends CharToGlyphMapper {
if (ch < 0 || ch > 0xffff) {
return missingGlyph;
} else {
if (FontUtilities.isDefaultIgnorable(ch)) {
if (FontUtilities.isDefaultIgnorable(ch) || isIgnorableWhitespace(ch)) {
return INVISIBLE_GLYPH_ID;
}
try {
@ -105,6 +105,13 @@ public final class Type1GlyphMapper extends CharToGlyphMapper {
}
}
// Matches behavior in e.g. CMap.getControlCodeGlyph(int, boolean)
// and RasterPrinterJob.removeControlChars(String)
// and CCharToGlyphMapper.isIgnorableWhitespace(int)
private static boolean isIgnorableWhitespace(int code) {
return code == 0x0009 || code == 0x000a || code == 0x000d;
}
public void charsToGlyphs(int count, char[] unicodes, int[] glyphs) {
/* The conversion into surrogates is misleading.
* The Type1 glyph mapper only accepts 16 bit unsigned shorts.

View File

@ -23,7 +23,7 @@
/*
* @test
* @bug 8350203
* @bug 8350203 8356966
* @summary Confirm that a few special whitespace characters are ignored.
*/
@ -93,36 +93,37 @@ public class IgnoredWhitespaceTest {
g2d.setColor(Color.BLACK);
g2d.drawString(text, x, y);
Rectangle actual = findTextBoundingBox(image);
assertEqual(expected, actual, text);
assertEqual(expected, actual, text, font);
g2d.setColor(Color.WHITE);
g2d.fillRect(0, 0, w, h);
g2d.setColor(Color.BLACK);
g2d.drawString(new AttributedString(text, Map.of(TextAttribute.FONT, font)).getIterator(), x, y);
actual = findTextBoundingBox(image);
assertEqual(expected, actual, text);
assertEqual(expected, actual, text, font);
g2d.setColor(Color.WHITE);
g2d.fillRect(0, 0, w, h);
g2d.setColor(Color.BLACK);
g2d.drawChars(text.toCharArray(), 0, text.length(), x, y);
actual = findTextBoundingBox(image);
assertEqual(expected, actual, text);
assertEqual(expected, actual, text, font);
g2d.setColor(Color.WHITE);
g2d.fillRect(0, 0, w, h);
g2d.setColor(Color.BLACK);
g2d.drawGlyphVector(font.createGlyphVector(frc, text), x, y);
actual = findTextBoundingBox(image);
assertEqual(expected, actual, text);
assertEqual(expected, actual, text, font);
}
private static void assertEqual(Rectangle r1, Rectangle r2, String text) {
private static void assertEqual(Rectangle r1, Rectangle r2, String text, Font font) {
if (!r1.equals(r2)) {
String escaped = text.replace("\r", "\\r")
.replace("\n", "\\n")
.replace("\t", "\\t");
String msg = String.format("for text '%s': %s != %s", escaped, r1.toString(), r2.toString());
String msg = String.format("for text '%s' with font %s: %s != %s",
escaped, font.toString(), r1.toString(), r2.toString());
throw new RuntimeException(msg);
}
}