diff --git a/src/java.desktop/share/classes/sun/font/Type1GlyphMapper.java b/src/java.desktop/share/classes/sun/font/Type1GlyphMapper.java index 8715e300c7d..8325f7d0351 100644 --- a/src/java.desktop/share/classes/sun/font/Type1GlyphMapper.java +++ b/src/java.desktop/share/classes/sun/font/Type1GlyphMapper.java @@ -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. diff --git a/test/jdk/java/awt/Graphics2D/DrawString/IgnoredWhitespaceTest.java b/test/jdk/java/awt/Graphics2D/DrawString/IgnoredWhitespaceTest.java index e7c38f1c16e..973f89fc889 100644 --- a/test/jdk/java/awt/Graphics2D/DrawString/IgnoredWhitespaceTest.java +++ b/test/jdk/java/awt/Graphics2D/DrawString/IgnoredWhitespaceTest.java @@ -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); } }