3819N/A/*
3819N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3819N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3819N/A *
3819N/A * This code is free software; you can redistribute it and/or modify it
3819N/A * under the terms of the GNU General Public License version 2 only, as
3819N/A * published by the Free Software Foundation.
3819N/A *
3819N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3819N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3819N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3819N/A * version 2 for more details (a copy is included in the LICENSE file that
3819N/A * accompanied this code).
3819N/A *
3819N/A * You should have received a copy of the GNU General Public License version
3819N/A * 2 along with this work; if not, write to the Free Software Foundation,
3819N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3819N/A *
3819N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3819N/A * or visit www.oracle.com if you need additional information or have any
3819N/A * questions.
3819N/A */
3819N/A
3819N/A/**
3819N/A * @test
3819N/A * @bug 7032930
3819N/A *
3819N/A * @summary verify the existence of the method
3819N/A * SunGraphicsEnvironment.useAlternateFontforJALocales
3819N/A *
3819N/A * @run main/othervm TestSGEuseAlternateFontforJALocales
3819N/A * @run main/othervm -Dfile.encoding=windows-31j -Duser.language=ja -Duser.country=JA TestSGEuseAlternateFontforJALocales
3819N/A *
3819N/A */
3819N/A
3819N/Aimport java.lang.reflect.Method;
3819N/Aimport java.nio.charset.Charset;
3819N/Aimport java.util.Locale;
3819N/Aimport java.awt.Font;
3819N/Aimport java.awt.FontMetrics;
3819N/Aimport java.awt.Graphics2D;
3819N/Aimport java.awt.GraphicsEnvironment;
3819N/Aimport java.awt.image.BufferedImage;
3819N/A
3819N/Apublic class TestSGEuseAlternateFontforJALocales {
3819N/A
3819N/A public static void main(String args[]) throws Exception {
3819N/A System.out.println("Default Charset = "
3819N/A + Charset.defaultCharset().name());
3819N/A System.out.println("Locale = " + Locale.getDefault());
3819N/A String os = System.getProperty("os.name");
3819N/A String encoding = System.getProperty("file.encoding");
3819N/A /* Want to test the JA locale uses alternate font for DialogInput. */
3819N/A boolean jaTest = encoding.equalsIgnoreCase("windows-31j");
3819N/A if (!os.startsWith("Win") && jaTest) {
3819N/A System.out.println("Skipping Windows only test");
3819N/A return;
3819N/A }
3819N/A
3819N/A String className = "sun.java2d.SunGraphicsEnvironment";
3819N/A String methodName = "useAlternateFontforJALocales";
3819N/A Class sge = Class.forName(className);
3819N/A Method uafMethod = sge.getMethod(methodName, (Class[])null);
3819N/A Object ret = uafMethod.invoke(null);
3819N/A GraphicsEnvironment ge =
3819N/A GraphicsEnvironment.getLocalGraphicsEnvironment();
3819N/A ge.preferLocaleFonts();
3819N/A ge.preferProportionalFonts();
3819N/A if (jaTest) {
3819N/A Font msMincho = new Font("MS Mincho", Font.PLAIN, 12);
3819N/A if (!msMincho.getFamily(Locale.ENGLISH).equals("MS Mincho")) {
3819N/A System.out.println("MS Mincho not installed. Skipping test");
3819N/A return;
3819N/A }
3819N/A Font dialogInput = new Font("DialogInput", Font.PLAIN, 12);
3819N/A Font courierNew = new Font("Courier New", Font.PLAIN, 12);
3819N/A Font msGothic = new Font("MS Gothic", Font.PLAIN, 12);
3819N/A BufferedImage bi = new BufferedImage(1,1,1);
3819N/A Graphics2D g2d = bi.createGraphics();
3819N/A FontMetrics cnMetrics = g2d.getFontMetrics(courierNew);
3819N/A FontMetrics diMetrics = g2d.getFontMetrics(dialogInput);
3819N/A FontMetrics mmMetrics = g2d.getFontMetrics(msMincho);
3819N/A FontMetrics mgMetrics = g2d.getFontMetrics(msGothic);
3819N/A // This tests to make sure we at least have applied
3819N/A // "preferLocaleFonts for Japanese
3819N/A if (cnMetrics.charWidth('A') == diMetrics.charWidth('A')) {
3819N/A throw new RuntimeException
3819N/A ("Courier New should not be used for DialogInput");
3819N/A }
3819N/A // This is supposed to make sure we are using MS Mincho instead
3819N/A // of MS Gothic. However they are metrics identical so its
3819N/A // not definite proof.
3819N/A if (diMetrics.charWidth('A') != mmMetrics.charWidth('A')) {
3819N/A throw new RuntimeException
3819N/A ("MS Mincho should be used for DialogInput");
3819N/A }
3819N/A }
3819N/A }
3819N/A}