Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8316206: Test StretchedFontTest.java fails for Baekmuk font #15818

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions test/jdk/java/awt/font/FontScaling/StretchedFontTest.java
Original file line number Diff line number Diff line change
@@ -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;
@@ -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 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.
*
@@ -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);