JRE-430 added new regression test (Font fallback sometimes doesn't work in Swing text components)

(cherry picked from commit d04debc847)

with fix for JBR-5300 Change source code and test files to use GPL license

(cherry picked from commit 5a47f2a66c)
This commit is contained in:
Vitaly Provodin
2018-11-23 17:09:58 +07:00
committed by jbrbot
parent 2e377b04c2
commit 7ff048d0b7
2 changed files with 190 additions and 0 deletions

View File

@@ -0,0 +1,128 @@
/*
* Copyright 2000-2023 JetBrains s.r.o.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import javax.imageio.ImageIO;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
/*
* Description: The class is used by the test <code>font430.sh</code>.
*/
public class Font430 extends JFrame implements
WindowListener {
private static boolean CALL_GET_FONT_METRICS = false;
private static String FILE_NAME;
static Font430 frame = new Font430("Font430");
private static JEditorPane editorPane;
private Font430(String name) {
super(name);
}
public static void main(String[] args) {
if (args.length > 0)
FILE_NAME = args[0];
if (args.length > 1)
CALL_GET_FONT_METRICS = Boolean.valueOf(args[1]);
SwingUtilities.invokeLater(Font430::createAndShowGUI);
}
private static void createAndShowGUI() {
frame.setSize(200, 100);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.addComponentsToPane();
frame.pack();
frame.setVisible(true);
}
private void addComponentsToPane() {
editorPane = new JEditorPane("text/html",
"<html><head><style>body {font-family:'Segoe UI'; font-size:12pt;}</style></head><body>\u4e2d</body></html>");
if (CALL_GET_FONT_METRICS) {
editorPane.getFontMetrics(new Font("Segoe UI", Font.PLAIN, 12));
}
editorPane.setLocation(0, 0);
editorPane.setSize(200, 100);
frame.add(editorPane);
addWindowListener(this);
}
@Override
public void windowOpened(WindowEvent e) {
BufferedImage screenShoot;
Rectangle rect = editorPane.getBounds();
try {
screenShoot = new BufferedImage(rect.width, rect.height, BufferedImage.TYPE_INT_ARGB);
editorPane.paint(screenShoot.getGraphics());
ImageIO.write(screenShoot, "png", new File(FILE_NAME));
} catch (IOException ex) {
ex.printStackTrace();
}
frame.setVisible(false);
frame.dispose();
}
@Override
public void windowClosing(WindowEvent e) {
}
@Override
public void windowClosed(WindowEvent e) {
}
@Override
public void windowIconified(WindowEvent e) {
}
@Override
public void windowDeiconified(WindowEvent e) {
}
@Override
public void windowActivated(WindowEvent e) {
}
@Override
public void windowDeactivated(WindowEvent e) {
}
}

View File

@@ -0,0 +1,62 @@
#!/bin/bash
#
# Copyright 2000-2023 JetBrains s.r.o.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
# @test
# @summary font430.sh checks the 'physical' font object, created for 'Segoe UI' font and font-fallback-enabled one
# are not identical
# @run shell font430.sh
if [ -z "${TESTSRC}" ]; then
echo "TESTSRC undefined: set to ."
TESTSRC=.
fi
if [ -z "${TESTCLASSES}" ]; then
echo "TESTCLASSES undefined: set to ."
TESTCLASSES=.
fi
if [ -z "${TESTJAVA}" ]; then
echo "TESTJAVA undefined: testing cancelled"
exit 1
fi
cd ${TESTSRC}
${TESTJAVA}/bin/javac -d ${TESTCLASSES} Font430.java
${TESTJAVA}/bin/java -cp ${TESTCLASSES} Font430 t1.bmp true
${TESTJAVA}/bin/java -cp ${TESTCLASSES} Font430 t2.bmp true
cmp t1.bmp t2.bmp
exit_code=$?
case $exit_code in
0) echo "PASSED"
;;
*) echo "FAILED: $exit_code"
exit 1
;;
esac
exit 0