1 /* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * 4 * This code is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU General Public License version 2 only, as 6 * published by the Free Software Foundation. 7 * 8 * This code is distributed in the hope that it will be useful, but WITHOUT 9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 * version 2 for more details (a copy is included in the LICENSE file that 12 * accompanied this code). 13 * 14 * You should have received a copy of the GNU General Public License version 15 * 2 along with this work; if not, write to the Free Software Foundation, 16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17 * 18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 19 * or visit www.oracle.com if you need additional information or have any 20 * questions. 21 * 22 */ 23 24 /* @test 25 * @summary Verify Variation Selector matches an expected image 26 * @bug 8187100 27 * @ignore Requires a special font installed. 28 */ 29 30 import javax.swing.SwingUtilities; 31 import javax.swing.border.LineBorder; 32 import javax.swing.JLabel; 33 import javax.swing.JPanel; 34 import javax.swing.JFrame; 35 import javax.swing.JTextArea; 36 import javax.swing.ImageIcon; 37 import java.awt.Font; 38 import java.awt.Color; 39 40 public class TestVS { 41 public static void main(String[] args) { 42 SwingUtilities.invokeLater(new Runnable() { 43 public void run() { 44 new TestVS().run(); 45 } 46 }); 47 } 48 49 private void run() { 50 Font ourFont = null; 51 final String fontName = "ipaexm.ttf"; 52 // download from https://ipafont.ipa.go.jp/node26#en 53 // and place in {user.home}/fonts/ 54 try { 55 ourFont = Font.createFont(Font.TRUETYPE_FONT, 56 new java.io.File(new java.io.File( 57 System.getProperty("user.home"), 58 "fonts"), fontName)); 59 ourFont = ourFont.deriveFont((float)48.0); 60 final String actualFontName = ourFont.getFontName(); 61 if (!actualFontName.equals("IPAexMincho")) { 62 System.err.println("*** Warning: missing font IPAexMincho."); 63 System.err.println("*** Using font: " + actualFontName); 64 } 65 } catch(Throwable t) { 66 t.printStackTrace(); 67 System.err.println("Fail: " + t); 68 return; 69 } 70 JFrame frame = new JFrame(System.getProperty("java.version")); 71 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 72 JPanel panel = new JPanel(); 73 final JTextArea label = new JTextArea("empty"); 74 label.setSize(400, 300); 75 label.setBorder(new LineBorder(Color.black)); 76 label.setFont(ourFont); 77 78 final String str = "\u845b\udb40\udd00\u845b\udb40\udd01\n"; 79 80 label.setText(str); 81 82 panel.add(label); 83 panel.add(new JLabel(ourFont.getFamily())); 84 85 // Show the expected result. 86 panel.add(new JLabel(new ImageIcon("TestVS-expect.png"))); 87 88 frame.getContentPane().add(panel); 89 frame.pack(); 90 frame.setVisible(true); 91 } 92 }