Skip to content

Commit

Permalink
8316206: Test StretchedFontTest.java fails for Baekmuk font
Browse files Browse the repository at this point in the history
Ignore broken fonts, i.e. the fonts for which
GlyphVector(TEXT).getVisualBounds().isEmpty() returns true

Backport-of: 00f585bd22f527eca0107a9b4ed366f25754f0be
  • Loading branch information
GoeLin committed Sep 27, 2023
1 parent 80c8ce7 commit b382b09
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions test/jdk/java/awt/font/FontScaling/StretchedFontTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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;
Expand Down Expand Up @@ -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)
Expand All @@ -82,6 +87,26 @@ public static void main(String[] args) {
}
}

/**
* 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.
*
Expand Down Expand Up @@ -145,7 +170,7 @@ private static String testFont(final Font font,
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);
Expand Down

1 comment on commit b382b09

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.