7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
Reviewed-by: igor, jgodinez
--- a/jdk/src/share/classes/sun/awt/FontConfiguration.java Fri Apr 01 12:45:45 2011 -0700
+++ b/jdk/src/share/classes/sun/awt/FontConfiguration.java Fri Apr 01 20:21:14 2011 -0700
@@ -82,6 +82,10 @@
* one to ensure proper static initialisation takes place.
*/
public FontConfiguration(SunFontManager fm) {
+ if (FontUtilities.debugFonts()) {
+ FontUtilities.getLogger()
+ .info("Creating standard Font Configuration");
+ }
if (FontUtilities.debugFonts() && logger == null) {
logger = PlatformLogger.getLogger("sun.awt.FontConfiguration");
}
@@ -111,6 +115,10 @@
boolean preferLocaleFonts,
boolean preferPropFonts) {
fontManager = fm;
+ if (FontUtilities.debugFonts()) {
+ FontUtilities.getLogger()
+ .info("Creating alternate Font Configuration");
+ }
this.preferLocaleFonts = preferLocaleFonts;
this.preferPropFonts = preferPropFonts;
/* fontConfig should be initialised by default constructor, and
--- a/jdk/src/share/classes/sun/font/FontManagerForSGE.java Fri Apr 01 12:45:45 2011 -0700
+++ b/jdk/src/share/classes/sun/font/FontManagerForSGE.java Fri Apr 01 20:21:14 2011 -0700
@@ -54,4 +54,11 @@
public Font[] getAllInstalledFonts();
public String[] getInstalledFontFamilyNames(Locale requestedLocale);
+
+ /* Modifies the behaviour of a subsequent call to preferLocaleFonts()
+ * to use Mincho instead of Gothic for dialoginput in JA locales
+ * on windows. Not needed on other platforms.
+ */
+ public void useAlternateFontforJALocales();
+
}
--- a/jdk/src/share/classes/sun/font/SunFontManager.java Fri Apr 01 12:45:45 2011 -0700
+++ b/jdk/src/share/classes/sun/font/SunFontManager.java Fri Apr 01 20:21:14 2011 -0700
@@ -2874,7 +2874,10 @@
* on windows. Not needed on other platforms.
*/
public synchronized void useAlternateFontforJALocales() {
-
+ if (FontUtilities.isLogging()) {
+ FontUtilities.getLogger()
+ .info("Entered useAlternateFontforJALocales().");
+ }
if (!FontUtilities.isWindows) {
return;
}
@@ -2897,7 +2900,9 @@
}
public synchronized void preferLocaleFonts() {
-
+ if (FontUtilities.isLogging()) {
+ FontUtilities.getLogger().info("Entered preferLocaleFonts().");
+ }
/* Test if re-ordering will have any effect */
if (!FontConfiguration.willReorderForStartupLocale()) {
return;
@@ -2928,7 +2933,10 @@
}
public synchronized void preferProportionalFonts() {
-
+ if (FontUtilities.isLogging()) {
+ FontUtilities.getLogger()
+ .info("Entered preferProportionalFonts().");
+ }
/* If no proportional fonts are configured, there's no need
* to take any action.
*/
@@ -3456,6 +3464,11 @@
initCompositeFonts(FontConfiguration fontConfig,
ConcurrentHashMap<String, Font2D> altNameCache) {
+ if (FontUtilities.isLogging()) {
+ FontUtilities.getLogger()
+ .info("Initialising composite fonts");
+ }
+
int numCoreFonts = fontConfig.getNumberCoreFonts();
String[] fcFonts = fontConfig.getPlatformFontNames();
for (int f=0; f<fcFonts.length; f++) {
--- a/jdk/src/share/classes/sun/java2d/SunGraphicsEnvironment.java Fri Apr 01 12:45:45 2011 -0700
+++ b/jdk/src/share/classes/sun/java2d/SunGraphicsEnvironment.java Fri Apr 01 20:21:14 2011 -0700
@@ -185,6 +185,18 @@
FontManager fm = FontManagerFactory.getInstance();
return (FontManagerForSGE) fm;
}
+
+ /* Modifies the behaviour of a subsequent call to preferLocaleFonts()
+ * to use Mincho instead of Gothic for dialoginput in JA locales
+ * on windows. Not needed on other platforms.
+ *
+ * DO NOT MOVE OR RENAME OR OTHERWISE ALTER THIS METHOD.
+ * ITS USED BY SOME NON-JRE INTERNAL CODE.
+ */
+ public static void useAlternateFontforJALocales() {
+ getFontManagerForSGE().useAlternateFontforJALocales();
+ }
+
/**
* Returns all fonts available in this environment.
*/
--- a/jdk/src/windows/classes/sun/awt/Win32GraphicsEnvironment.java Fri Apr 01 12:45:45 2011 -0700
+++ b/jdk/src/windows/classes/sun/awt/Win32GraphicsEnvironment.java Fri Apr 01 20:21:14 2011 -0700
@@ -39,12 +39,8 @@
import java.util.StringTokenizer;
import sun.awt.DisplayChangedListener;
import sun.awt.SunDisplayChanger;
-import sun.awt.windows.WFontConfiguration;
import sun.awt.windows.WPrinterJob;
import sun.awt.windows.WToolkit;
-import sun.font.FontManager;
-import sun.font.FontManagerFactory;
-import sun.font.SunFontManager;
import sun.java2d.SunGraphicsEnvironment;
import sun.java2d.SurfaceManagerFactory;
import sun.java2d.WindowsSurfaceManagerFactory;
@@ -231,20 +227,6 @@
return device;
}
- // Implements SunGraphicsEnvironment.createFontConfiguration.
- protected FontConfiguration createFontConfiguration() {
- FontConfiguration fc = new WFontConfiguration(SunFontManager.getInstance());
- fc.init();
- return fc;
- }
-
- public FontConfiguration createFontConfiguration(boolean preferLocaleFonts,
- boolean preferPropFonts) {
-
- return new WFontConfiguration(SunFontManager.getInstance(),
- preferLocaleFonts,preferPropFonts);
- }
-
public boolean isDisplayLocal() {
return true;
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/sun/java2d/SunGraphicsEnvironment/TestSGEuseAlternateFontforJALocales.java Fri Apr 01 20:21:14 2011 -0700
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2011, 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
+ * 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
+ * @bug 7032930
+ *
+ * @summary verify the existence of the method
+ * SunGraphicsEnvironment.useAlternateFontforJALocales
+ *
+ * @run main/othervm TestSGEuseAlternateFontforJALocales
+ * @run main/othervm -Dfile.encoding=windows-31j -Duser.language=ja -Duser.country=JA TestSGEuseAlternateFontforJALocales
+ *
+ */
+
+import java.lang.reflect.Method;
+import java.nio.charset.Charset;
+import java.util.Locale;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Graphics2D;
+import java.awt.GraphicsEnvironment;
+import java.awt.image.BufferedImage;
+
+public class TestSGEuseAlternateFontforJALocales {
+
+ public static void main(String args[]) throws Exception {
+ System.out.println("Default Charset = "
+ + Charset.defaultCharset().name());
+ System.out.println("Locale = " + Locale.getDefault());
+ String os = System.getProperty("os.name");
+ String encoding = System.getProperty("file.encoding");
+ /* Want to test the JA locale uses alternate font for DialogInput. */
+ boolean jaTest = encoding.equalsIgnoreCase("windows-31j");
+ if (!os.startsWith("Win") && jaTest) {
+ System.out.println("Skipping Windows only test");
+ return;
+ }
+
+ String className = "sun.java2d.SunGraphicsEnvironment";
+ String methodName = "useAlternateFontforJALocales";
+ Class sge = Class.forName(className);
+ Method uafMethod = sge.getMethod(methodName, (Class[])null);
+ Object ret = uafMethod.invoke(null);
+ GraphicsEnvironment ge =
+ GraphicsEnvironment.getLocalGraphicsEnvironment();
+ ge.preferLocaleFonts();
+ ge.preferProportionalFonts();
+ if (jaTest) {
+ Font msMincho = new Font("MS Mincho", Font.PLAIN, 12);
+ if (!msMincho.getFamily(Locale.ENGLISH).equals("MS Mincho")) {
+ System.out.println("MS Mincho not installed. Skipping test");
+ return;
+ }
+ Font dialogInput = new Font("DialogInput", Font.PLAIN, 12);
+ Font courierNew = new Font("Courier New", Font.PLAIN, 12);
+ Font msGothic = new Font("MS Gothic", Font.PLAIN, 12);
+ BufferedImage bi = new BufferedImage(1,1,1);
+ Graphics2D g2d = bi.createGraphics();
+ FontMetrics cnMetrics = g2d.getFontMetrics(courierNew);
+ FontMetrics diMetrics = g2d.getFontMetrics(dialogInput);
+ FontMetrics mmMetrics = g2d.getFontMetrics(msMincho);
+ FontMetrics mgMetrics = g2d.getFontMetrics(msGothic);
+ // This tests to make sure we at least have applied
+ // "preferLocaleFonts for Japanese
+ if (cnMetrics.charWidth('A') == diMetrics.charWidth('A')) {
+ throw new RuntimeException
+ ("Courier New should not be used for DialogInput");
+ }
+ // This is supposed to make sure we are using MS Mincho instead
+ // of MS Gothic. However they are metrics identical so its
+ // not definite proof.
+ if (diMetrics.charWidth('A') != mmMetrics.charWidth('A')) {
+ throw new RuntimeException
+ ("MS Mincho should be used for DialogInput");
+ }
+ }
+ }
+}