Skip to content

8358697: TextLayout/MyanmarTextTest.java passes if no Myanmar font is found #25879

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
45 changes: 19 additions & 26 deletions test/jdk/java/awt/font/TextLayout/MyanmarTextTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -27,12 +27,15 @@
* @key headful
* @summary Verifies that Myanmar script is rendered correctly:
* two characters combined into one glyph
* @library /test/lib
* @build jtreg.SkippedException
* @run main MyanmarTextTest
*/

import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.util.Arrays;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
Expand All @@ -45,12 +48,16 @@
import javax.swing.text.BadLocationException;
import javax.swing.text.Position;

import jtreg.SkippedException;

public class MyanmarTextTest {
private static final String TEXT = "\u1000\u103C";

private static final String FONT_WINDOWS = "Myanmar Text";
private static final String FONT_LINUX = "Padauk";
private static final String FONT_MACOS = "Myanmar MN";
private static final List<String> FONT_CANDIDATES =
List.of("Myanmar MN",
"Padauk",
"Myanmar Text",
"Noto Sans Myanmar");

private static final String FONT_NAME = selectFontName();

Expand All @@ -61,12 +68,8 @@ public class MyanmarTextTest {

public static void main(String[] args) throws Exception {
if (FONT_NAME == null) {
System.err.println("Unsupported OS: exiting");
return;
}
if (!fontExists()) {
System.err.println("Required font is not installed: " + FONT_NAME);
return;
throw new SkippedException("No suitable font found out of the list: "
+ String.join(", ", FONT_CANDIDATES));
}

try {
Expand Down Expand Up @@ -130,22 +133,12 @@ private void checkPositions() {
}

private static String selectFontName() {
String osName = System.getProperty("os.name").toLowerCase();
if (osName.contains("windows")) {
return FONT_WINDOWS;
} else if (osName.contains("linux")) {
return FONT_LINUX;
} else if (osName.contains("mac")) {
return FONT_MACOS;
} else {
return null;
}
return Arrays.stream(GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getAvailableFontFamilyNames())
.filter(FONT_CANDIDATES::contains)
.findFirst()
.orElse(null);
}

private static boolean fontExists() {
String[] fontFamilyNames = GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getAvailableFontFamilyNames();
return Arrays.asList(fontFamilyNames).contains(FONT_NAME);
}
}