7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
Reviewed-by: igor, jgodinez
This commit is contained in:
parent
e78547586a
commit
56980cf411
jdk
src
share/classes/sun
awt
font
java2d
windows/classes/sun/awt
test/sun/java2d/SunGraphicsEnvironment
@ -82,6 +82,10 @@ public abstract class FontConfiguration {
|
|||||||
* one to ensure proper static initialisation takes place.
|
* one to ensure proper static initialisation takes place.
|
||||||
*/
|
*/
|
||||||
public FontConfiguration(SunFontManager fm) {
|
public FontConfiguration(SunFontManager fm) {
|
||||||
|
if (FontUtilities.debugFonts()) {
|
||||||
|
FontUtilities.getLogger()
|
||||||
|
.info("Creating standard Font Configuration");
|
||||||
|
}
|
||||||
if (FontUtilities.debugFonts() && logger == null) {
|
if (FontUtilities.debugFonts() && logger == null) {
|
||||||
logger = PlatformLogger.getLogger("sun.awt.FontConfiguration");
|
logger = PlatformLogger.getLogger("sun.awt.FontConfiguration");
|
||||||
}
|
}
|
||||||
@ -111,6 +115,10 @@ public abstract class FontConfiguration {
|
|||||||
boolean preferLocaleFonts,
|
boolean preferLocaleFonts,
|
||||||
boolean preferPropFonts) {
|
boolean preferPropFonts) {
|
||||||
fontManager = fm;
|
fontManager = fm;
|
||||||
|
if (FontUtilities.debugFonts()) {
|
||||||
|
FontUtilities.getLogger()
|
||||||
|
.info("Creating alternate Font Configuration");
|
||||||
|
}
|
||||||
this.preferLocaleFonts = preferLocaleFonts;
|
this.preferLocaleFonts = preferLocaleFonts;
|
||||||
this.preferPropFonts = preferPropFonts;
|
this.preferPropFonts = preferPropFonts;
|
||||||
/* fontConfig should be initialised by default constructor, and
|
/* fontConfig should be initialised by default constructor, and
|
||||||
|
@ -54,4 +54,11 @@ public interface FontManagerForSGE extends FontManager {
|
|||||||
public Font[] getAllInstalledFonts();
|
public Font[] getAllInstalledFonts();
|
||||||
|
|
||||||
public String[] getInstalledFontFamilyNames(Locale requestedLocale);
|
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();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2874,7 +2874,10 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
|
|||||||
* on windows. Not needed on other platforms.
|
* on windows. Not needed on other platforms.
|
||||||
*/
|
*/
|
||||||
public synchronized void useAlternateFontforJALocales() {
|
public synchronized void useAlternateFontforJALocales() {
|
||||||
|
if (FontUtilities.isLogging()) {
|
||||||
|
FontUtilities.getLogger()
|
||||||
|
.info("Entered useAlternateFontforJALocales().");
|
||||||
|
}
|
||||||
if (!FontUtilities.isWindows) {
|
if (!FontUtilities.isWindows) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2897,7 +2900,9 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void preferLocaleFonts() {
|
public synchronized void preferLocaleFonts() {
|
||||||
|
if (FontUtilities.isLogging()) {
|
||||||
|
FontUtilities.getLogger().info("Entered preferLocaleFonts().");
|
||||||
|
}
|
||||||
/* Test if re-ordering will have any effect */
|
/* Test if re-ordering will have any effect */
|
||||||
if (!FontConfiguration.willReorderForStartupLocale()) {
|
if (!FontConfiguration.willReorderForStartupLocale()) {
|
||||||
return;
|
return;
|
||||||
@ -2928,7 +2933,10 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void preferProportionalFonts() {
|
public synchronized void preferProportionalFonts() {
|
||||||
|
if (FontUtilities.isLogging()) {
|
||||||
|
FontUtilities.getLogger()
|
||||||
|
.info("Entered preferProportionalFonts().");
|
||||||
|
}
|
||||||
/* If no proportional fonts are configured, there's no need
|
/* If no proportional fonts are configured, there's no need
|
||||||
* to take any action.
|
* to take any action.
|
||||||
*/
|
*/
|
||||||
@ -3456,6 +3464,11 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
|
|||||||
initCompositeFonts(FontConfiguration fontConfig,
|
initCompositeFonts(FontConfiguration fontConfig,
|
||||||
ConcurrentHashMap<String, Font2D> altNameCache) {
|
ConcurrentHashMap<String, Font2D> altNameCache) {
|
||||||
|
|
||||||
|
if (FontUtilities.isLogging()) {
|
||||||
|
FontUtilities.getLogger()
|
||||||
|
.info("Initialising composite fonts");
|
||||||
|
}
|
||||||
|
|
||||||
int numCoreFonts = fontConfig.getNumberCoreFonts();
|
int numCoreFonts = fontConfig.getNumberCoreFonts();
|
||||||
String[] fcFonts = fontConfig.getPlatformFontNames();
|
String[] fcFonts = fontConfig.getPlatformFontNames();
|
||||||
for (int f=0; f<fcFonts.length; f++) {
|
for (int f=0; f<fcFonts.length; f++) {
|
||||||
|
@ -185,6 +185,18 @@ public abstract class SunGraphicsEnvironment extends GraphicsEnvironment
|
|||||||
FontManager fm = FontManagerFactory.getInstance();
|
FontManager fm = FontManagerFactory.getInstance();
|
||||||
return (FontManagerForSGE) fm;
|
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.
|
* Returns all fonts available in this environment.
|
||||||
*/
|
*/
|
||||||
|
@ -39,12 +39,8 @@ import java.util.NoSuchElementException;
|
|||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
import sun.awt.DisplayChangedListener;
|
import sun.awt.DisplayChangedListener;
|
||||||
import sun.awt.SunDisplayChanger;
|
import sun.awt.SunDisplayChanger;
|
||||||
import sun.awt.windows.WFontConfiguration;
|
|
||||||
import sun.awt.windows.WPrinterJob;
|
import sun.awt.windows.WPrinterJob;
|
||||||
import sun.awt.windows.WToolkit;
|
import sun.awt.windows.WToolkit;
|
||||||
import sun.font.FontManager;
|
|
||||||
import sun.font.FontManagerFactory;
|
|
||||||
import sun.font.SunFontManager;
|
|
||||||
import sun.java2d.SunGraphicsEnvironment;
|
import sun.java2d.SunGraphicsEnvironment;
|
||||||
import sun.java2d.SurfaceManagerFactory;
|
import sun.java2d.SurfaceManagerFactory;
|
||||||
import sun.java2d.WindowsSurfaceManagerFactory;
|
import sun.java2d.WindowsSurfaceManagerFactory;
|
||||||
@ -231,20 +227,6 @@ public class Win32GraphicsEnvironment
|
|||||||
return device;
|
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() {
|
public boolean isDisplayLocal() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user