author | katleman |
Thu, 17 Apr 2014 10:13:36 -0700 | |
changeset 23942 | 7b722b4cdd2d |
parent 8945 | 4718885476ee |
child 31660 | 1a4e2e5c15e1 |
permissions | -rw-r--r-- |
8945
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
1 |
/* |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
2 |
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
4 |
* |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
8 |
* |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
13 |
* accompanied this code). |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
14 |
* |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
18 |
* |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
21 |
* questions. |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
22 |
*/ |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
23 |
|
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
24 |
/** |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
25 |
* @test |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
26 |
* @bug 7032930 |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
27 |
* |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
28 |
* @summary verify the existence of the method |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
29 |
* SunGraphicsEnvironment.useAlternateFontforJALocales |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
30 |
* |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
31 |
* @run main/othervm TestSGEuseAlternateFontforJALocales |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
32 |
* @run main/othervm -Dfile.encoding=windows-31j -Duser.language=ja -Duser.country=JA TestSGEuseAlternateFontforJALocales |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
33 |
* |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
34 |
*/ |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
35 |
|
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
36 |
import java.lang.reflect.Method; |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
37 |
import java.nio.charset.Charset; |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
38 |
import java.util.Locale; |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
39 |
import java.awt.Font; |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
40 |
import java.awt.FontMetrics; |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
41 |
import java.awt.Graphics2D; |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
42 |
import java.awt.GraphicsEnvironment; |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
43 |
import java.awt.image.BufferedImage; |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
44 |
|
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
45 |
public class TestSGEuseAlternateFontforJALocales { |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
46 |
|
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
47 |
public static void main(String args[]) throws Exception { |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
48 |
System.out.println("Default Charset = " |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
49 |
+ Charset.defaultCharset().name()); |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
50 |
System.out.println("Locale = " + Locale.getDefault()); |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
51 |
String os = System.getProperty("os.name"); |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
52 |
String encoding = System.getProperty("file.encoding"); |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
53 |
/* Want to test the JA locale uses alternate font for DialogInput. */ |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
54 |
boolean jaTest = encoding.equalsIgnoreCase("windows-31j"); |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
55 |
if (!os.startsWith("Win") && jaTest) { |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
56 |
System.out.println("Skipping Windows only test"); |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
57 |
return; |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
58 |
} |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
59 |
|
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
60 |
String className = "sun.java2d.SunGraphicsEnvironment"; |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
61 |
String methodName = "useAlternateFontforJALocales"; |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
62 |
Class sge = Class.forName(className); |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
63 |
Method uafMethod = sge.getMethod(methodName, (Class[])null); |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
64 |
Object ret = uafMethod.invoke(null); |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
65 |
GraphicsEnvironment ge = |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
66 |
GraphicsEnvironment.getLocalGraphicsEnvironment(); |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
67 |
ge.preferLocaleFonts(); |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
68 |
ge.preferProportionalFonts(); |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
69 |
if (jaTest) { |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
70 |
Font msMincho = new Font("MS Mincho", Font.PLAIN, 12); |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
71 |
if (!msMincho.getFamily(Locale.ENGLISH).equals("MS Mincho")) { |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
72 |
System.out.println("MS Mincho not installed. Skipping test"); |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
73 |
return; |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
74 |
} |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
75 |
Font dialogInput = new Font("DialogInput", Font.PLAIN, 12); |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
76 |
Font courierNew = new Font("Courier New", Font.PLAIN, 12); |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
77 |
Font msGothic = new Font("MS Gothic", Font.PLAIN, 12); |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
78 |
BufferedImage bi = new BufferedImage(1,1,1); |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
79 |
Graphics2D g2d = bi.createGraphics(); |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
80 |
FontMetrics cnMetrics = g2d.getFontMetrics(courierNew); |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
81 |
FontMetrics diMetrics = g2d.getFontMetrics(dialogInput); |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
82 |
FontMetrics mmMetrics = g2d.getFontMetrics(msMincho); |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
83 |
FontMetrics mgMetrics = g2d.getFontMetrics(msGothic); |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
84 |
// This tests to make sure we at least have applied |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
85 |
// "preferLocaleFonts for Japanese |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
86 |
if (cnMetrics.charWidth('A') == diMetrics.charWidth('A')) { |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
87 |
throw new RuntimeException |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
88 |
("Courier New should not be used for DialogInput"); |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
89 |
} |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
90 |
// This is supposed to make sure we are using MS Mincho instead |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
91 |
// of MS Gothic. However they are metrics identical so its |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
92 |
// not definite proof. |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
93 |
if (diMetrics.charWidth('A') != mmMetrics.charWidth('A')) { |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
94 |
throw new RuntimeException |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
95 |
("MS Mincho should be used for DialogInput"); |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
96 |
} |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
97 |
} |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
98 |
} |
4718885476ee
7032930: A way to specify MS Mincho to be used in dialoginput on windows JA locale
prr
parents:
diff
changeset
|
99 |
} |