8316206: Test StretchedFontTest.java fails for Baekmuk font

Ignore broken fonts, i.e. the fonts for which
GlyphVector(TEXT).getVisualBounds().isEmpty() returns true

Reviewed-by: azvegint, prr, goetz
This commit is contained in:
Alexey Ivanov 2023-09-22 12:47:01 +00:00
parent c24c66db97
commit 00f585bd22

View File

@ -26,6 +26,7 @@ import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.font.FontRenderContext;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.File;
@ -61,15 +62,19 @@ public final class StretchedFontTest {
new Color(0x7F000000, true)
};
/** Locale for getting font names. */
private static final Locale ENGLISH_LOCALE = Locale.ENGLISH;
private static final AffineTransform STRETCH_TRANSFORM =
AffineTransform.getScaleInstance(2.0, 1.0);
public static void main(String[] args) {
List<String> errors =
Arrays.stream(getLocalGraphicsEnvironment()
.getAvailableFontFamilyNames(Locale.ENGLISH))
.getAvailableFontFamilyNames(ENGLISH_LOCALE))
.map(family -> new Font(family, Font.PLAIN, FONT_SIZE))
.filter(font -> font.canDisplay(TEXT.codePointAt(0)))
.filter(font -> !isBrokenFont(font))
.map(font -> font.deriveFont(STRETCH_TRANSFORM))
.flatMap(StretchedFontTest::testFont)
.filter(Objects::nonNull)
@ -82,6 +87,26 @@ public final class StretchedFontTest {
}
}
/**
* Checks whether the font renders the glyph in {@code TEXT} and
* returns {@code true} if the glyph isn't rendered.
*
* @param font the font to test
* @return {@code true} if the visual bounds of {@code TEXT} are empty, and
* {@code false} otherwise
*/
private static boolean isBrokenFont(final Font font) {
final boolean empty =
font.createGlyphVector(new FontRenderContext(null, false, false),
TEXT)
.getVisualBounds()
.isEmpty();
if (empty) {
System.err.println("Broken font: " + font.getFontName(ENGLISH_LOCALE));
}
return empty;
}
/**
* Tests the font with a set of text antialiasing hints.
*
@ -145,7 +170,7 @@ public final class StretchedFontTest {
if (verifyImage(image)) {
return null;
}
String fontName = font.getFontName(Locale.ENGLISH);
String fontName = font.getFontName(ENGLISH_LOCALE);
String hintValue = getHintString(hint);
String hexColor = String.format("0x%08x", foreground.getRGB());
saveImage(image, fontName + "-" + hintValue + "-" + hexColor);