Skip to content

Commit

Permalink
8199529: javax/swing/text/Utilities/8142966/SwingFontMetricsTest.java…
Browse files Browse the repository at this point in the history
… fails on windows

Reviewed-by: phh
Backport-of: 1ce6ec6
  • Loading branch information
RealCLanger committed Oct 29, 2021
1 parent 4a99728 commit ff65591
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 0 additions & 1 deletion test/jdk/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,6 @@ javax/swing/text/html/parser/Parser/8078268/bug8078268.java 8199092 generic-all
javax/swing/PopupFactory/8048506/bug8048506.java 8202660 windows-all
javax/swing/JTextArea/TextViewOOM/TextViewOOM.java 8167355 generic-all
javax/swing/JEditorPane/8195095/ImageViewTest.java 8202656 windows-all
javax/swing/text/Utilities/8142966/SwingFontMetricsTest.java 8199529 windows-all
javax/swing/JPopupMenu/8075063/ContextMenuScrollTest.java 202880 linux-all
javax/swing/dnd/8139050/NativeErrorsInTableDnD.java 8202765 macosx-all,linux-all
javax/swing/Popup/TaskbarPositionTest.java 8065097 macosx-all,linux-all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
*/
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import static java.awt.RenderingHints.*;
import java.awt.Toolkit;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import javax.swing.JFrame;
Expand All @@ -31,7 +36,7 @@
/**
* @test
* @key headful
* @bug 8142966
* @bug 8142966 8199529
* @summary Wrong cursor position in text components on HiDPI display
* @run main/othervm -Dsun.java2d.uiScale=2 SwingFontMetricsTest
*/
Expand All @@ -42,8 +47,15 @@ public class SwingFontMetricsTest {
private static final String TEXT = LOWER_CASE_TEXT + UPPER_CASE_TEXT;
private static boolean passed = false;
private static CountDownLatch latch = new CountDownLatch(1);
private static Object aaHint = null;

public static void main(String[] args) throws Exception {
Map map = (Map)Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints");
aaHint = map.get(RenderingHints.KEY_TEXT_ANTIALIASING);
if (aaHint == null) {
aaHint = VALUE_TEXT_ANTIALIAS_DEFAULT;
}

SwingUtilities.invokeAndWait(SwingFontMetricsTest::createAndShowGUI);
latch.await(5, TimeUnit.SECONDS);

Expand All @@ -61,7 +73,10 @@ private static void createAndShowGUI() {
public void paint(Graphics g) {
super.paint(g);
Font font = getFont();
Graphics2D g2d = (Graphics2D)g;
int width1 = getFontMetrics(font).stringWidth(TEXT);
// Set the same AA hint that the built-in Swing L&Fs set.
g2d.setRenderingHint(KEY_TEXT_ANTIALIASING, aaHint);
int width2 = g.getFontMetrics(font).stringWidth(TEXT);
passed = (width1 == width2);
latch.countDown();
Expand Down

1 comment on commit ff65591

@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.